コード例 #1
0
        private IEnumerator UpdateVideoTexture()
        {
            while (true)
            {
                if (FramesCounter != _framesCounter)
                {
                    _framesCounter = FramesCounter;
                    UpdateFpsCounter();

                    if (!_isTextureExist)
                    {
                        if (_videoTexture != null)
                        {
                            UnityEngine.Object.Destroy(_videoTexture);
                            _videoTexture = null;
                        }

                        if (_options.FixedVideoSize == Vector2.zero)
                        {
                            int width  = VideoWidth;
                            int height = VideoHeight;

                            if (_videoBuffer == null ||
                                (_videoBuffer != null &&
                                 _videoBuffer.Width != width || _videoBuffer.Height != height))
                            {
                                if (_videoBuffer != null)
                                {
                                    _videoBuffer.ClearFramePixels();
                                }

                                _videoBuffer = new PlayerBufferVideo(width, height);
                                _wrapper.NativeSetPixelsBuffer(_videoBuffer.FramePixelsAddr, _videoBuffer.Width, _videoBuffer.Height);
                            }
                        }

                        _videoTexture = MediaPlayerHelper.GenPluginTexture(_videoBuffer.Width, _videoBuffer.Height);
                        MediaPlayerHelper.ApplyTextureToRenderingObjects(_videoTexture, _videoOutputObjects);
                        _wrapper.NativeSetTexture(_videoTexture.GetNativeTexturePtr());

                        _isTextureExist = true;
                    }

                    _wrapper.PlayerUpdateSurfaceTexture();
                    GL.IssuePluginEvent(_wrapper.NativeGetUnityRenderCallback(), _wrapper.NativeIndex);
                }

                if (_wrapper.PlayerIsReady() && !_isReady)
                {
                    _isReady = true;

                    if (_isLoad)
                    {
                        _eventManager.ReplaceEvent(PlayerState.Paused, PlayerState.Prepared, _videoTexture);
                        Pause();
                    }
                    else
                    {
                        _eventManager.SetEvent(PlayerState.Prepared, _videoTexture);
                        _eventManager.SetEvent(PlayerState.Playing);
                    }
                }

                yield return(null);
            }
        }
コード例 #2
0
        private IEnumerator UpdateVideoTexture()
        {
            MediaTrackInfoExpanded[] tracks = null;
            var hasVideo = false;

            while (true)
            {
                if (_playerObj != IntPtr.Zero && _wrapper.PlayerIsPlaying(_playerObj))
                {
                    if (tracks == null)
                    {
                        tracks = TracksInfo;

                        if (tracks != null)
                        {
                            foreach (var track in tracks)
                            {
                                if (track is MediaTrackInfoVideo)
                                {
                                    hasVideo = true;
                                }
                            }
                        }
                        else
                        {
                            yield return(null);

                            continue;
                        }
                    }

                    if (FramesCounter != _framesCounter)
                    {
                        _framesCounter = FramesCounter;
                        UpdateFpsCounter(_framesCounter);

                        if (_videoBuffer == null)
                        {
                            int width  = _wrapper.NativeGetPixelsBufferWidth();
                            int height = _wrapper.NativeGetPixelsBufferHeight();

                            _videoBuffer = new PlayerBufferVideo(width, height);
                            _wrapper.NativeSetPixelsBuffer(_videoBuffer.FramePixelsAddr, _videoBuffer.Width, _videoBuffer.Height);
                        }

                        if (!_isTextureExist)
                        {
                            if (_videoTexture != null)
                            {
                                UnityEngine.Object.Destroy(_videoTexture);
                                _videoTexture = null;
                            }

                            _videoTexture = MediaPlayerHelper.GenPluginTexture(_videoBuffer.Width, _videoBuffer.Height);
                            MediaPlayerHelper.ApplyTextureToRenderingObjects(_videoTexture, _videoOutputObjects);
                            _wrapper.NativeSetTexture(_videoTexture.GetNativeTexturePtr());

                            _isTextureExist = true;
                        }

                        GL.IssuePluginEvent(_wrapper.NativeGetUnityRenderCallback(), _wrapper.NativeIndex);
                    }

                    if (!_isReady && (hasVideo ? (_videoTexture != null && _videoBuffer != null) : tracks != null))
                    {
                        _isReady = true;

                        if (_isLoad)
                        {
                            _eventManager.ReplaceEvent(PlayerState.Paused, PlayerState.Prepared, _videoTexture);
                            Pause();
                        }
                        else
                        {
                            _eventManager.SetEvent(PlayerState.Prepared, _videoTexture);
                            _eventManager.SetEvent(PlayerState.Playing);
                        }
                    }
                }

                yield return(null);
            }
        }