/// <summary> /// Create instance of MediaPlayerIPhone 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 MediaPlayerIPhone(MonoBehaviour monoObject, GameObject[] videoOutputObjects, PlayerOptionsIPhone options) { _monoObject = monoObject; _videoOutputObjects = videoOutputObjects; _options = options; _wrapper = new WrapperInternal(_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) { _optionsLine = _options.GetOptions('\n'); if (_options.FixedVideoSize != Vector2.zero) { _videoBuffer = new PlayerBufferVideo((int)_options.FixedVideoSize.x, (int)_options.FixedVideoSize.y); _wrapper.NativeSetPixelsBuffer(_videoBuffer.FramePixelsAddr, _videoBuffer.Width, _videoBuffer.Height); } } _wrapper.NativeInitPlayer(_optionsLine); _eventManager = new PlayerManagerEvents(_monoObject, this); _eventManager.PlayerPlayingListener += OnPlayerPlaying; _eventManager.PlayerPausedListener += OnPlayerPaused; }
private IEnumerator UpdateVideoTexture() { while (true) { if (FramesCounter != _framesCounter) { _framesCounter = FramesCounter; UpdateFpsCounter(); _shareTexture = _wrapper.NativeGetTexture(); 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 = Texture2D.CreateExternalTexture(_videoBuffer.Width, _videoBuffer.Height, TextureFormat.BGRA32, false, false, _shareTexture); MediaPlayerHelper.ApplyTextureToRenderingObjects(_videoTexture, _videoOutputObjects); //_wrapper.NativeHelperSetTexture(_pluginObj, _videoTexture.GetNativeTexturePtr()); _isTextureExist = true; } _videoTexture.UpdateExternalTexture(_shareTexture); } 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); } }