/// <summary>
        ///  Create instance of MediaPlayerStandalone object with additional arguments
        /// </summary>
        /// <param name="monoObject">MonoBehaviour instanse</param>
        /// <param name="videoOutputObjects">Objects that will be rendering video output</param>
        /// <param name="options">Additional player options</param>
        public MediaPlayerStandalone(MonoBehaviour monoObject, GameObject[] videoOutputObjects, PlayerOptionsStandalone options)
        {
            _monoObject         = monoObject;
            _videoOutputObjects = videoOutputObjects;
            _options            = options;

            _wrapper = new WrapperStandalone(_options);

            if (_wrapper.NativeIndex < 0)
            {
                Debug.LogError("Don't support video playback on current platform or you use incorrect UMP libraries!");
                throw new Exception();
            }

            if (_options != null)
            {
                if (!string.IsNullOrEmpty(_options.DirectAudioDevice))
                {
                    _options.DirectAudioDevice = GetAudioDevice(_options.DirectAudioDevice);
                }

                _wrapper.NativeSetPixelsVerticalFlip(_options.FlipVertically);

                if (_options.FixedVideoSize != Vector2.zero)
                {
                    _videoBuffer = new PlayerBufferVideo((int)_options.FixedVideoSize.x, (int)_options.FixedVideoSize.y);
                    _wrapper.NativeSetPixelsBuffer(_videoBuffer.FramePixelsAddr, _videoBuffer.Width, _videoBuffer.Height);
                }

                if (_options.AudioOutputs != null && _options.AudioOutputs.Length > 0)
                {
                    _audioManager = new PlayerManagerAudios(_options.AudioOutputs);
                    _audioManager.AddListener(OnAudioFilterRead);
                }

                _arguments   = _options.GetOptions('\n').Split('\n');
                _logDetail   = _options.LogDetail;
                _logListener = _options.LogListener;
            }

            MediaPlayerInit();
        }
Beispiel #2
0
        private void InitBufferSize(int width, int height)
        {
            _wrapper.NativePixelsBufferRelease();

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

            if (_videoBuffer == null)
            {
                _videoBuffer = new PlayerBufferVideo(width, height);
                _wrapper.NativeSetPixelsBuffer(_videoBuffer.FramePixelsAddr, _videoBuffer.Width, _videoBuffer.Height);
                _isTextureExist = false;
            }
        }
        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);
            }
        }