Ejemplo n.º 1
0
        private static void MediaPlayback_Changed(IntPtr thisObjectPtr, Plugin.PLAYBACK_STATE args)
        {
            if (thisObjectPtr == IntPtr.Zero)
            {
                Debug.LogError("MediaPlayback_Changed: requires thisObjectPtr.");
                return;
            }

            var      handle     = GCHandle.FromIntPtr(thisObjectPtr);
            Playback thisObject = handle.Target as Playback;

            if (thisObject == null)
            {
                Debug.LogError("MediaPlayback_Changed: thisObjectPtr is not null, but seems invalid.");
                return;
            }

#if UNITY_WSA_10_0
            if (!UnityEngine.WSA.Application.RunningOnAppThread())
            {
                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    thisObject.OnStateChanged(args);
                }, false);
            }
            else
            {
                thisObject.OnStateChanged(args);
            }
#else
            thisObject.OnStateChanged(args);
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Callback for media playback change event (media state change)
        /// </summary>
        /// <param name="args"></param>
        private void MediaPlayback_Changed(Plugin.PLAYBACK_STATE args)
        {
#if UNITY_UWP
            UnityEngine.WSA.Application.InvokeOnAppThread(() =>
            {
                OnStateChanged(args);
            }, false);
#else
            OnStateChanged(args);
#endif
        }
Ejemplo n.º 3
0
        private void OnStateChanged(Plugin.PLAYBACK_STATE args)
        {
            var state = (PlaybackState)args.type;

            switch (state)
            {
            case PlaybackState.Buffering:
                break;

            case PlaybackState.Ended:
                break;

            case PlaybackState.None:
                break;

            case PlaybackState.Paused:
                break;

            case PlaybackState.Playing:
                break;
            }

            var stateType = (Plugin.StateType)Enum.ToObject(typeof(Plugin.StateType), args.type);

            switch (stateType)
            {
            case Plugin.StateType.StateType_StateChanged:
                this.State = (PlaybackState)Enum.ToObject(typeof(PlaybackState), args.state);
                //Debug.Log("State Type: " + stateType.ToString() + " - " + this.State.ToString());
                break;

            case Plugin.StateType.StateType_Opened:
                // Only output this information on initial play
                if (currentPosition == 0)
                {
                    Plugin.MEDIA_DESCRIPTION description = args.description;
                    //Debug.Log("Opening Media:");
                    //Debug.Log(" Width = " + description.width.ToString());
                    //Debug.Log(" Height = " + description.height.ToString());
                    //Debug.Log(" Duration = " + description.duration.ToString());
                    //Debug.Log(" Seekable = " + description.isSeekable.ToString());
                }
                break;

            case Plugin.StateType.StateType_Failed:
                CheckHR(args.hresult);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 4
0
        private void OnStateChanged(Plugin.PLAYBACK_STATE args)
        {
            var stateType = (Plugin.StateType)Enum.ToObject(typeof(Plugin.StateType), args.type);

            switch (stateType)
            {
            case Plugin.StateType.StateType_None:
                var newState0 = (PlaybackState)Enum.ToObject(typeof(PlaybackState), args.state);
                if (newState0 == PlaybackState.Ended || newState0 == PlaybackState.None)
                {
                    currentMediaDescription = new Plugin.MEDIA_DESCRIPTION();
                }
                loaded = false;
                break;

            case Plugin.StateType.StateType_StateChanged:
                var newState = (PlaybackState)Enum.ToObject(typeof(PlaybackState), args.state);
                if (newState == PlaybackState.None)
                {
                    if (State == PlaybackState.Playing || State == PlaybackState.Paused)
                    {
                        Debug.Log("Video ended");
                        newState = PlaybackState.Ended;
                    }
                    currentMediaDescription = new Plugin.MEDIA_DESCRIPTION();
                    loaded = false;
                }
                else if (newState == PlaybackState.Ended)
                {
                    currentMediaDescription = new Plugin.MEDIA_DESCRIPTION();
                    loaded = false;
                }
                else if (newState != PlaybackState.Buffering && args.description.width != 0 && args.description.height != 0)
                {
                    currentMediaDescription.duration   = args.description.duration;
                    currentMediaDescription.width      = args.description.width;
                    currentMediaDescription.height     = args.description.height;
                    currentMediaDescription.isSeekable = args.description.isSeekable;

                    hasNewSize = true;
                }
                this.State = newState;
                Debug.Log("Playback State: " + stateType.ToString() + " - " + this.State.ToString());
                break;

            case Plugin.StateType.StateType_Opened:
                currentMediaDescription.duration   = args.description.duration;
                currentMediaDescription.width      = args.description.width;
                currentMediaDescription.height     = args.description.height;
                currentMediaDescription.isSeekable = args.description.isSeekable;
                Debug.Log("Media Opened: " + args.description.ToString());
                break;

            case Plugin.StateType.StateType_Failed:
                loaded = false;
                CheckHR(args.hresult);
                if (this.PlaybackFailed != null)
                {
                    PlaybackFailed(this, args.hresult);
                }
                this.State = PlaybackState.None;
                loaded     = false;
                break;

            case Plugin.StateType.StateType_DeviceLost:
                Debug.LogWarning("Graphics device was lost!");
                break;

            case Plugin.StateType.StateType_DeviceRestored:
                Debug.LogWarning("Graphics device was restored! Recreating the playback texture!");
                UpdateTexture();
                break;

            default:
                break;
            }
        }