Beispiel #1
0
    void OnRenderObject()
    {
        if (mAppPaused)
        {
            return;
        }

        CheckIconPlaneVisibility();

        if (!mIsInited)
        {
            if (!mInitInProgess)
            {
                mInitInProgess = true;
                StartCoroutine(InitVideoPlayer());
            }

            return;
        }

        if (isPlayableOnTexture)
        {
            // Update the video texture with the latest video frame
            VideoPlayerHelper.MediaState state = mVideoPlayer.UpdateVideoData();
            if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
            {
#if UNITY_WSA_10_0 && !UNITY_EDITOR
                // For Direct3D video texture update, we need to be on the rendering thread
                GL.IssuePluginEvent(VideoPlayerHelper.GetNativeRenderEventFunc(), 0);
#else
                GL.InvalidateState();
#endif
            }

            // Check for playback state change
            if (state != mCurrentState)
            {
                HandleStateChange(state);
                mCurrentState = state;
            }
        }
        else
        {
            // Get the current status
            VideoPlayerHelper.MediaState state = mVideoPlayer.GetStatus();
            if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
            {
                GL.InvalidateState();
            }

            // Check for playback state change
            if (state != mCurrentState)
            {
                HandleStateChange(state);
                mCurrentState = state;
            }
        }
    }
    private void OnRenderObject()
    {
        if (mAppPaused)
        {
            return;
        }
        if (!mIsInited)
        {
            return;
        }
        if (!mIsPrepared)
        {
            pushMsg("!mIsPrepared....");

            VideoPlayerHelper.MediaState state = mVideoPlayer.GetStatus();

            if (state == VideoPlayerHelper.MediaState.ERROR)
            {
                pushMsg("Could not load video ");
                HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
                this.enabled = false;
            }

            else if (state < VideoPlayerHelper.MediaState.NOT_READY)
            {
                // Video player is ready
                int videoWidth  = mVideoPlayer.GetVideoWidth();
                int videoHeight = mVideoPlayer.GetVideoHeight();

                if (videoWidth > 0 && videoHeight > 0)
                {
                    // Scale the video plane to match the video aspect ratio
                    float aspect = videoHeight / (float)videoWidth;

                    // Flip the plane as the video texture is mirrored on the horizontal
                    transform.localScale = new Vector3(-0.1f, 0.1f, 0.1f * aspect);
                }
                // Video is prepared, ready for playback
                mIsPrepared = true;
                pushMsg("Video is prepared, ready for playback");
            }
        }
        else
        {
            VideoPlayerHelper.MediaState state = mVideoPlayer.UpdateVideoData();

            if (state == VideoPlayerHelper.MediaState.PLAYING)
            {
                GL.InvalidateState();
                // Update Video Info
                UpdateVideoInfo();
            }

            if (state != mCurrentState)
            {
                HandleStateChange(state);
                mCurrentState = state;
            }
        }
    }
Beispiel #3
0
    void OnRenderObject()
    {
        if (mAppPaused)
        {
            return;
        }

        if (!mIsInited)
        {
            Debug.Log("Initialising the video");
            // Initialize the video player
            if (mVideoPlayer.Init() == false)
            {
                Debug.Log("Could not initialize video player");
                HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
                this.enabled = false;
                return;
            }

            // Initialize the video texture
            InitVideoTexture();

            // Load the video
            if (!isCloudReco && mVideoPlayer.Load(m_path, mMediaType, false, 0) == false)
            {
                Debug.Log("Could not load video '" + m_path + "' for media type " + mMediaType);
                HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
                this.enabled = false;
                return;
            }

            // Successfully initialized
            mIsInited = true;
        }
        else if (!mIsPrepared)
        {
            // Get the video player status
            VideoPlayerHelper.MediaState state = mVideoPlayer.GetStatus();
            if (state == VideoPlayerHelper.MediaState.ERROR)
            {
                Debug.Log("Could not load video '" + m_path + "' for media type " + mMediaType);
                HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
                this.enabled = false;
            }
            else if (state < VideoPlayerHelper.MediaState.NOT_READY)
            {
                // Video player is ready

                // Can we play this video on a texture?
                isPlayableOnTexture = mVideoPlayer.IsPlayableOnTexture();

                if (isPlayableOnTexture)
                {
                    //Set texture and aspect ratio
                    SetVideoTextureAndAspectRatio();

                    // Seek ahead if necessary
                    if (mSeekPosition > 0)
                    {
                        mVideoPlayer.SeekTo(mSeekPosition);
                    }
                }
                else
                {
                    // Handle the state change
                    state = mVideoPlayer.GetStatus();
                    HandleStateChange(state);
                    mCurrentState = state;
                }

                // Scale the icon
                ScaleIcon();

                // Video is prepared, ready for playback
                mIsPrepared = true;
            }
        }
        else
        {
            if (isPlayableOnTexture)
            {
                // Update the video texture with the latest video frame
                VideoPlayerHelper.MediaState state = mVideoPlayer.UpdateVideoData();
                if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                    (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
                {
                    GL.InvalidateState();
                }


                // Check for playback state change
                if (state != mCurrentState)
                {
                    HandleStateChange(state);
                    mCurrentState = state;
                }
            }
            else
            {
                // Get the current status
                VideoPlayerHelper.MediaState state = mVideoPlayer.GetStatus();
                if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                    (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
                {
                    GL.InvalidateState();
                }

                // Check for playback state change
                if (state != mCurrentState)
                {
                    HandleStateChange(state);
                    mCurrentState = state;
                }
            }
        }

        CheckIconPlaneVisibility();
    }
Beispiel #4
0
    void OnRenderObject()
    {
        if (mAppPaused)
        {
            return;
        }

        if (!mIsInited)
        {
            // Initialize the video player
            if (mVideoPlayer.Init() == false)
            {
                Debug.Log("Could not initialize video player");
                HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
                this.enabled = false;
                return;
            }

            // Initialize the video texture
            InitVideoTexture();

            // Load the video
            if (mVideoPlayer.Load(m_path, mMediaType, false, 0) == false)
            {
                Debug.Log("Could not load video '" + m_path + "' for media type " + mMediaType);
                HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
                this.enabled = false;
                return;
            }

            // Successfully initialized
            mIsInited = true;
        }
        else if (!mIsPrepared)
        {
            // Get the video player status
            VideoPlayerHelper.MediaState state = mVideoPlayer.GetStatus();

            if (state == VideoPlayerHelper.MediaState.ERROR)
            {
                Debug.Log("Could not load video '" + m_path + "' for media type " + mMediaType);
                HandleStateChange(VideoPlayerHelper.MediaState.ERROR);
                this.enabled = false;
            }
            else if (state < VideoPlayerHelper.MediaState.NOT_READY)
            {
                // Video player is ready

                // Can we play this video on a texture?
                isPlayableOnTexture = mVideoPlayer.IsPlayableOnTexture();

                if (isPlayableOnTexture)
                {
                    // Pass the video texture id to the video player
                    int nativeTextureID = mVideoTexture.GetNativeTextureID();
                    mVideoPlayer.SetVideoTextureID(nativeTextureID);

                    // Get the video width and height
                    int videoWidth  = mVideoPlayer.GetVideoWidth();
                    int videoHeight = mVideoPlayer.GetVideoHeight();

                    if (videoWidth > 0 && videoHeight > 0)
                    {
                        // Scale the video plane to match the video aspect ratio
                        float aspect = videoHeight / (float)videoWidth;

                        // Flip the plane as the video texture is mirrored on the horizontal
                        transform.localScale = new Vector3(-0.1f, 0.1f, 0.1f * aspect);
                    }

                    // Seek ahead if necessary
                    if (mSeekPosition > 0)
                    {
                        mVideoPlayer.SeekTo(mSeekPosition);
                    }
                }
                else
                {
                    // Handle the state change
                    state = mVideoPlayer.GetStatus();
                    HandleStateChange(state);
                    mCurrentState = state;
                }

                // Scale the icon
                ScaleIcon();

                // Video is prepared, ready for playback
                mIsPrepared = true;
            }
        }
        else
        {
            if (isPlayableOnTexture)
            {
                // Update the video texture with the latest video frame
                VideoPlayerHelper.MediaState state = mVideoPlayer.UpdateVideoData();
                if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                    (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
                {
                    GL.InvalidateState();
                }


                // Check for playback state change
                if (state != mCurrentState)
                {
                    HandleStateChange(state);
                    mCurrentState = state;
                }
            }
            else
            {
                // Get the current status
                VideoPlayerHelper.MediaState state = mVideoPlayer.GetStatus();
                if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                    (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
                {
                    GL.InvalidateState();
                }

                // Check for playback state change
                if (state != mCurrentState)
                {
                    HandleStateChange(state);
                    mCurrentState = state;
                }
            }
        }

        CheckIconPlaneVisibility();
    }