Пример #1
0
        private static void ValueAtKeyPathDidChangeThunk(IntPtr self, string keyPath)
        {
            GCHandle       handle = GCHandle.FromIntPtr(self);
            OSXMediaPlayer player = (OSXMediaPlayer)handle.Target;

            player.ValueAtKeyPathDidChange(keyPath);
        }
        public override void Update()
        {
            // Only call this once per frame!
            OSXMediaPlayer.IssuePluginEvent(AVPPluginEventType.PlayerUpdate, AVPPlayerGetHandle(_player));

            int width  = 0;
            int height = 0;

            AVPPlayerGetTextureSize(_player, out width, out height);
            IntPtr native = AVPPlayerGetTextureHandle(_player);

            if (_texture != null && (_width != width || _height != height))
            {
                // Have to update with zero to release Metal textures!
                _texture.UpdateExternalTexture(IntPtr.Zero);
                Texture2D.Destroy(_texture);
                _texture = null;
            }

            if (_texture == null && native != IntPtr.Zero)
            {
                TextureFormat format = TextureFormat.BGRA32;
                bool          mipmap = false;
                bool          linear = false;
                _texture = Texture2D.CreateExternalTexture(width, height, format, mipmap, linear, native);
                _width   = width;
                _height  = height;
                _native  = native;
                ApplyTextureProperties(_texture);
            }
            else if (_texture != null && native != _native)
            {
                _texture.UpdateExternalTexture(native);
                _native = native;
            }

            // Check for meta data to become available
            if (!_isMetaDataReady)
            {
                if (AVPPlayerHasMetaData(_player) || CanPlay())
                {
                    if (HasVideo())
                    {
                        if (width > 0 && height > 0)
                        {
                            if (Mathf.Max(width, height) > SystemInfo.maxTextureSize)
                            {
                                Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize");
                            }
                            _isMetaDataReady = true;
                        }
                    }
                    else if (HasAudio())
                    {
                        _isMetaDataReady = true;
                    }
                }
            }
        }
Пример #3
0
		public virtual BaseMediaPlayer CreatePlatformMediaPlayer()
		{
			BaseMediaPlayer mediaPlayer = null;

#if !AVPROVIDEO_FORCE_NULL_MEDIAPLAYER

			// Setup for running in the editor (Either OSX, Windows or Linux)
#if UNITY_EDITOR
#if (UNITY_EDITOR_OSX)
#if UNITY_EDITOR_64
			mediaPlayer = new OSXMediaPlayer();
#else
			Debug.LogError("[AVProVideo] 32-bit OS X Unity editor not supported.  64-bit required.");
#endif
#elif UNITY_EDITOR_WIN
			WindowsMediaPlayer.InitialisePlatform();
			mediaPlayer = new WindowsMediaPlayer(_optionsWindows.forceDirectShowApi, _optionsWindows.forceAudioOutputDeviceName);
#endif
#else
			// Setup for running builds
#if (UNITY_STANDALONE_WIN || UNITY_WSA_10_0 || UNITY_WINRT_8_1)
			WindowsMediaPlayer.InitialisePlatform();
			mediaPlayer = new WindowsMediaPlayer(_optionsWindows.forceDirectShowApi, _optionsWindows.forceAudioOutputDeviceName);
#elif (UNITY_STANDALONE_OSX || UNITY_IPHONE || UNITY_IOS || UNITY_TVOS)
			mediaPlayer = new OSXMediaPlayer();
#elif (UNITY_ANDROID)
			// Initialise platform (also unpacks videos from StreamingAsset folder (inside a jar), to the persistent data path)
			AndroidMediaPlayer.InitialisePlatform();
			mediaPlayer = new AndroidMediaPlayer();
#elif (UNITY_WEBGL)
            WebGLMediaPlayer.InitialisePlatform();
            mediaPlayer = new WebGLMediaPlayer();
#endif
#endif

#endif

			// Fallback
			if (mediaPlayer == null)
			{
				Debug.LogWarning("[AVProVideo] Not supported on this platform.  Using placeholder player!");
				mediaPlayer = new NullMediaPlayer();
			}

			return mediaPlayer;
		}
        public override void Dispose()
        {
            if (_texture != null)
            {
                // Have to update with zero to release Metal textures!
                _texture.UpdateExternalTexture(IntPtr.Zero);
                Texture2D.Destroy(_texture);
                _texture = null;
            }

            if (_player != IntPtr.Zero)
            {
                OSXMediaPlayer.IssuePluginEvent(AVPPluginEventType.FreeTextureResources, AVPPlayerGetHandle(_player));
                AVPPlayerRelease(_player);
                _player = IntPtr.Zero;
            }
        }
Пример #5
0
        private BaseMediaPlayer CreatePlatformMediaPlayer()
        {
            BaseMediaPlayer mediaPlayer = null;

            // Setup for running in the editor (Either OSX, Windows or Linux)
#if UNITY_EDITOR
        #if (UNITY_EDITOR_OSX)
                #if UNITY_EDITOR_64
            mediaPlayer = new OSXMediaPlayer();
                #else
            Debug.LogWarning("[AVProVideo] 32-bit OS X Unity editor not supported.  64-bit required.");
                #endif
        #elif UNITY_EDITOR_WIN
            WindowsMediaPlayer.InitialisePlatform();
            mediaPlayer = new WindowsMediaPlayer();
        #endif
#else
            // Setup for running builds
#if (UNITY_STANDALONE_WIN)
            WindowsMediaPlayer.InitialisePlatform();
            mediaPlayer = new WindowsMediaPlayer();
            //Windows_VLC_MediaPlayer.InitialisePlatform();
            //mediaPlayer = new Windows_VLC_MediaPlayer();
#elif (UNITY_STANDALONE_OSX || UNITY_IPHONE || UNITY_IOS || UNITY_TVOS)
            mediaPlayer = new OSXMediaPlayer();
#elif (UNITY_ANDROID)
            // Initialise platform (also unpacks videos from StreamingAsset folder (inside a jar), to the persistent data path)
            AndroidMediaPlayer.InitialisePlatform();
            mediaPlayer = new AndroidMediaPlayer();
#elif (UNITY_WP8)
            // TODO: add Windows Phone 8 suppport
#elif (UNITY_WP81)
            // TODO: add Windows Phone 8.1 suppport
#endif
#endif

            // Fallback
            if (mediaPlayer == null)
            {
                Debug.LogWarning("[AVProVideo] Not supported on this platform.  Using placeholder video!");
                mediaPlayer = new NullMediaPlayer();
            }

            return(mediaPlayer);
        }
Пример #6
0
 // Convenience method for calling OSXMediaPlayer.IssuePluginEvent.
 //
 private void IssuePluginEvent(AVPPluginEventType type)
 {
     OSXMediaPlayer.IssuePluginEvent(type, _handle);
 }
Пример #7
0
 public override void Dispose()
 {
     OSXMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerShutdown, AVPPlayerGetHandle(_player));
     AVPPlayerRelease(_player);
     _player = IntPtr.Zero;
 }
Пример #8
0
        public override void Update()
        {
            // Called before Render.

            // Check for meta data to become available
            if (!_isMetaDataReady)
            {
                if (AVPPlayerHasMetaData(_player) || CanPlay())
                {
                    if (HasVideo())
                    {
                        int width = 0, height = 0;
                        AVPPlayerGetTextureSize(_player, out width, out height);

                        if (width > 0 && height > 0)
                        {
                            if (Mathf.Max(width, height) > SystemInfo.maxTextureSize)
                            {
                                Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize");
                            }
                            else
                            {
                                _width  = width;
                                _height = height;
                            }
                            _isMetaDataReady = true;
                        }
                    }
                    else if (HasAudio())
                    {
                        _isMetaDataReady = true;
                    }
                }
            }

            // Free texture
            if (_texture != null)
            {
                IntPtr native = AVPPlayerGetTextureHandle(_player);
                if (native == IntPtr.Zero)
                {
                    if (_texture != null)
                    {
                        Texture2D.Destroy(_texture);
                        _texture = null;
                    }
                    _width         = _height = 0;
                    _nativeTexture = IntPtr.Zero;
                }
            }

            if (HasVideo() && _width > 0 && _height > 0)
            {
                IntPtr native = AVPPlayerGetTextureHandle(_player);

                int width = 0, height = 0;
                AVPPlayerGetTextureSize(_player, out width, out height);

                if (_texture != null)
                {
                    // Point to a new texture
                    if (native != _nativeTexture)
                    {
                        _texture.UpdateExternalTexture(native);
                        _nativeTexture = native;

                        _width  = width;
                        _height = height;
                    }
                }
                if (_texture == null || width != _width || height != _height)
                {
                    TextureFormat format = TextureFormat.BGRA32;
                    bool          mipmap = false;
                    bool          linear = false;

                    // Free existing texture if any
                    if (_texture != null)
                    {
                        Texture2D.Destroy(_texture);
                        _texture = null;
                    }
                    _width         = _height = 0;
                    _nativeTexture = IntPtr.Zero;

                    _texture       = Texture2D.CreateExternalTexture(width, height, format, mipmap, linear, native);
                    _nativeTexture = native;
                    _width         = width;
                    _height        = height;

                    OSXMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerUpdate, AVPPlayerGetHandle(_player));
                }
            }
        }
Пример #9
0
 public override void Render()
 {
     OSXMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerUpdate, AVPPlayerGetHandle(_player));
 }
Пример #10
0
 public OSXMediaPlayer()
 {
     OSXMediaPlayer.Initialise();
     _player = AVPPlayerNew();
 }