public override void Dispose() { //Debug.LogError("DISPOSE"); if (m_Video != null) { m_Video.Call("SetDeinitialiseFlagged"); m_Video.Dispose(); m_Video = null; } if (s_Interface != null) { s_Interface.Call("DestroyPlayer", m_iPlayerIndex); } if (m_Texture != null) { Texture2D.Destroy(m_Texture); m_Texture = null; } // Deinitialise player (replaces call directly as GL textures are involved) AndroidMediaPlayer.IssuePluginEvent(Native.AVPPluginEvent.PlayerDestroy, m_iPlayerIndex); }
public AndroidMediaPlayer(bool useFastOesPath, bool showPosterFrame, Android.VideoApi api, bool enable360Audio, Audio360ChannelMode channelMode, bool preferSoftware) { m_API = api; // Create a java-size video class up front m_Video = s_Interface.Call <AndroidJavaObject>("CreatePlayer", (int)m_API, useFastOesPath, enable360Audio, (int)channelMode, preferSoftware); if (m_Video != null) { m_Method_SetHeadRotation = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "SetHeadRotation", "(FFFF)V", false); m_Method_SetFocusProps = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "SetFocusProps", "(FF)V", false); m_Method_SetFocusEnabled = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "SetFocusEnabled", "(Z)V", false); m_Method_SetFocusRotation = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "SetFocusRotation", "(FFFF)V", false); m_Method_GetCurrentTimeMs = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "GetCurrentTimeMs", "()J", false); m_Method_GetSourceVideoFrameRate = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "GetSourceVideoFrameRate", "()F", false); m_Method_IsPlaying = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "IsPlaying", "()Z", false); m_Method_IsPaused = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "IsPaused", "()Z", false); m_Method_IsFinished = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "IsFinished", "()Z", false); m_Method_IsSeeking = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "IsSeeking", "()Z", false); m_Method_IsBuffering = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "IsBuffering", "()Z", false); m_Method_IsLooping = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "IsLooping", "()Z", false); m_Method_HasVideo = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "HasVideo", "()Z", false); m_Method_HasAudio = AndroidJNIHelper.GetMethodID(m_Video.GetRawClass(), "HasAudio", "()Z", false); m_iPlayerIndex = m_Video.Call <int>("GetPlayerIndex"); Helper.LogInfo("Creating player " + m_iPlayerIndex); //Debug.Log( "AVPro: useFastOesPath: " + useFastOesPath ); SetOptions(useFastOesPath, showPosterFrame); // Initialise renderer, on the render thread AndroidMediaPlayer.IssuePluginEvent(Native.AVPPluginEvent.PlayerSetup, m_iPlayerIndex); } }
public override void Render() { if (m_Video != null) { //GL.InvalidateState(); AndroidMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerUpdate, m_iPlayerIndex); //GL.InvalidateState(); // Check if we can create the texture // Scan for a change in resolution if (m_Texture != null) { int newWidth = m_Video.Call <int>("GetWidth"); int newHeight = m_Video.Call <int>("GetHeight"); if (newWidth != m_Width || newHeight != m_Height) { m_Texture = null; m_TextureHandle = 0; } } int textureHandle = m_Video.Call <int>("GetTextureHandle"); if (textureHandle > 0 && textureHandle != m_TextureHandle) { int newWidth = m_Video.Call <int>("GetWidth"); int newHeight = m_Video.Call <int>("GetHeight"); if (Mathf.Max(newWidth, newHeight) > SystemInfo.maxTextureSize) { m_Width = newWidth; m_Height = newHeight; m_TextureHandle = textureHandle; Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize"); } else if (newWidth > 0 && newHeight > 0) { m_Width = newWidth; m_Height = newHeight; m_TextureHandle = textureHandle; _playerDescription = "MediaPlayer"; Helper.LogInfo("Using playback path: " + _playerDescription + " (" + m_Width + "x" + m_Height + "@" + GetVideoFrameRate().ToString("F2") + ")"); m_Texture = Texture2D.CreateExternalTexture(m_Width, m_Height, TextureFormat.RGBA32, false, false, new System.IntPtr(textureHandle)); if (m_Texture != null) { ApplyTextureProperties(m_Texture); } Helper.LogInfo("Texture ID: " + textureHandle); } } if (m_DurationMs == 0.0f) { m_DurationMs = (float)(m_Video.Call <long>("GetDurationMs")); // if( m_DurationMs > 0.0f ) { Helper.LogInfo("Duration: " + m_DurationMs); } } } }
public override void Render() { if (m_Video != null) { GL.InvalidateState(); AndroidMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerUpdate, m_iPlayerIndex); GL.InvalidateState(); // Check if we can create the texture // Scan for a change in resolution if (m_Texture != null) { int newWidth = m_Video.Call <int>("GetWidth"); int newHeight = m_Video.Call <int>("GetHeight"); if (newWidth != m_Width || newHeight != m_Height) { m_Texture = null; m_TextureHandle = 0; } } int textureHandle = m_Video.Call <int>("GetTextureHandle"); if (textureHandle > 0 && textureHandle != m_TextureHandle) { int newWidth = m_Video.Call <int>("GetWidth"); int newHeight = m_Video.Call <int>("GetHeight"); if (Mathf.Max(newWidth, newHeight) > SystemInfo.maxTextureSize) { m_Width = newWidth; m_Height = newHeight; m_TextureHandle = textureHandle; Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize"); } else if (newWidth > 0 && newHeight > 0) { m_Width = newWidth; m_Height = newHeight; m_TextureHandle = textureHandle; // Debug.Log("Video Dimensions: " + m_Width + " x " + m_Height); m_Texture = Texture2D.CreateExternalTexture(m_Width, m_Height, TextureFormat.RGBA32, false, false, new System.IntPtr(textureHandle)); m_Texture.wrapMode = TextureWrapMode.Clamp; Debug.Log("Texture ID: " + textureHandle); } } if (m_DurationMs == 0.0f) { m_DurationMs = (float)(m_Video.Call <long>("GetDurationMs")); // if( m_DurationMs > 0.0f ) { Debug.Log("Duration: " + m_DurationMs); } } } }
public AndroidMediaPlayer() { // Create a java-size video class up front m_Video = new AndroidJavaObject("com.RenderHeads.AVProVideo.AVProMobileVideo"); if (m_Video != null) { // Initialise m_Video.Call("Initialise", s_ActivityContext); m_iPlayerIndex = m_Video.Call <int>("GetPlayerIndex"); // Initialise render, on the render thread AndroidMediaPlayer.IssuePluginEvent(AVPPluginEvent.PlayerSetup, m_iPlayerIndex); } }
public AndroidMediaPlayer(bool useFastOesPath, bool showPosterFrame, Android.VideoApi api, bool enable360Audio, Audio360ChannelMode channelMode) { m_API = api; // Create a java-size video class up front m_Video = s_Interface.Call <AndroidJavaObject>("CreatePlayer", (int)m_API, enable360Audio, (int)channelMode); if (m_Video != null) { m_iPlayerIndex = m_Video.Call <int>("GetPlayerIndex"); Debug.Log("AVProVideo creating player " + m_iPlayerIndex); //Debug.Log( "AVPro: useFastOesPath: " + useFastOesPath ); SetOptions(useFastOesPath, showPosterFrame); // Initialise renderer, on the render thread AndroidMediaPlayer.IssuePluginEvent(Native.AVPPluginEvent.PlayerSetup, m_iPlayerIndex); } }
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; }
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); }
public AndroidMediaPlayer(bool useFastOesPath, bool showPosterFrame) { // Create a java-size video class up front m_Video = new AndroidJavaObject("com.RenderHeads.AVProVideo.AVProMobileVideo"); if (m_Video != null) { // Initialise m_Video.Call("Initialise", s_ActivityContext); m_iPlayerIndex = m_Video.Call <int>("GetPlayerIndex"); //Debug.Log( "AVPro: useFastOesPath: " + useFastOesPath ); SetOptions(useFastOesPath, showPosterFrame); // Initialise renderer, on the render thread AndroidMediaPlayer.IssuePluginEvent(Native.AVPPluginEvent.PlayerSetup, m_iPlayerIndex); } }
public AndroidMediaPlayer(bool useFastOesPath, bool showPosterFrame, Android.VideoApi api, bool enable360Audio, Audio360ChannelMode channelMode, bool preferSoftware) { #if UNITY_5 || UNITY_5_4_OR_NEWER Debug.Assert(s_Interface != null); Debug.Assert(s_bInitialised); #endif m_API = api; // Create a java-size video class up front m_Video = s_Interface.Call <AndroidJavaObject>("CreatePlayer", (int)m_API, useFastOesPath, enable360Audio, (int)channelMode, preferSoftware); if (m_Video != null) { m_Method_Update = GetMethod("Update", "()V"); m_Method_SetHeadRotation = GetMethod("SetHeadRotation", "(FFFF)V"); m_Method_SetFocusProps = GetMethod("SetFocusProps", "(FF)V"); m_Method_SetFocusEnabled = GetMethod("SetFocusEnabled", "(Z)V"); m_Method_SetFocusRotation = GetMethod("SetFocusRotation", "(FFFF)V"); m_Method_GetCurrentTimeMs = GetMethod("GetCurrentTimeMs", "()J"); m_Method_GetSourceVideoFrameRate = GetMethod("GetSourceVideoFrameRate", "()F"); m_Method_IsPlaying = GetMethod("IsPlaying", "()Z"); m_Method_IsPaused = GetMethod("IsPaused", "()Z"); m_Method_IsFinished = GetMethod("IsFinished", "()Z"); m_Method_IsSeeking = GetMethod("IsSeeking", "()Z"); m_Method_IsBuffering = GetMethod("IsBuffering", "()Z"); m_Method_IsLooping = GetMethod("IsLooping", "()Z"); m_Method_HasVideo = GetMethod("HasVideo", "()Z"); m_Method_HasAudio = GetMethod("HasAudio", "()Z"); m_iPlayerIndex = m_Video.Call <int>("GetPlayerIndex"); Helper.LogInfo("Creating player " + m_iPlayerIndex); Debug.Log("AVPro: useFastOesPath: " + useFastOesPath); SetOptions(useFastOesPath, showPosterFrame); // Initialise renderer, on the render thread AndroidMediaPlayer.IssuePluginEvent(Native.AVPPluginEvent.PlayerSetup, m_iPlayerIndex); } else { Debug.LogError("[AVProVideo] Failed to create player instance"); } }
public override void Render() { if (m_Video != null) { if (m_UseFastOesPath) { // This is needed for at least Unity 5.5.0, otherwise it just renders black in OES mode GL.InvalidateState(); } AndroidMediaPlayer.IssuePluginEvent(Native.AVPPluginEvent.PlayerUpdate, m_iPlayerIndex); if (m_UseFastOesPath) { GL.InvalidateState(); } // Check if we can create the texture // Scan for a change in resolution int newWidth = -1; int newHeight = -1; if (m_Texture != null) { #if DLL_METHODS newWidth = Native._GetWidth(m_iPlayerIndex); newHeight = Native._GetHeight(m_iPlayerIndex); #else newWidth = m_Video.Call <int>("GetWidth"); newHeight = m_Video.Call <int>("GetHeight"); #endif if (newWidth != m_Width || newHeight != m_Height) { m_Texture = null; m_TextureHandle = 0; } } #if DLL_METHODS int textureHandle = Native._GetTextureHandle(m_iPlayerIndex); #else int textureHandle = m_Video.Call <int>("GetTextureHandle"); #endif if (textureHandle != 0 && textureHandle != m_TextureHandle) { // Already got? (from above) if (newWidth == -1 || newHeight == -1) { #if DLL_METHODS newWidth = Native._GetWidth(m_iPlayerIndex); newHeight = Native._GetHeight(m_iPlayerIndex); #else newWidth = m_Video.Call <int>("GetWidth"); newHeight = m_Video.Call <int>("GetHeight"); #endif } if (Mathf.Max(newWidth, newHeight) > SystemInfo.maxTextureSize) { m_Width = newWidth; m_Height = newHeight; m_TextureHandle = textureHandle; Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize"); } else if (newWidth > 0 && newHeight > 0) { m_Width = newWidth; m_Height = newHeight; m_TextureHandle = textureHandle; switch (m_API) { case Android.VideoApi.MediaPlayer: _playerDescription = "MediaPlayer"; break; case Android.VideoApi.ExoPlayer: _playerDescription = "ExoPlayer"; break; default: _playerDescription = "UnknownPlayer"; break; } Helper.LogInfo("Using playback path: " + _playerDescription + " (" + m_Width + "x" + m_Height + "@" + GetVideoFrameRate().ToString("F2") + ")"); // NOTE: From Unity 5.4.x when using OES textures, an error "OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_OPERATION: Operation illegal in current state" will be logged. // We assume this is because we're passing in TextureFormat.RGBA32 which isn't the true texture format. This error should be safe to ignore. m_Texture = Texture2D.CreateExternalTexture(m_Width, m_Height, TextureFormat.RGBA32, false, false, new System.IntPtr(textureHandle)); if (m_Texture != null) { ApplyTextureProperties(m_Texture); } Helper.LogInfo("Texture ID: " + textureHandle); } } #if AVPROVIDEO_FIXREGRESSION_TEXTUREQUALITY_UNITY542 // In Unity 5.4.2 and above the video texture turns black when changing the TextureQuality in the Quality Settings // The code below gets around this issue. A bug report has been sent to Unity. So far we have tested and replicated the // "bug" in Windows only, but a user has reported it in Android too. // Texture.GetNativeTexturePtr() must sync with the rendering thread, so this is a large performance hit! if (_textureQuality != QualitySettings.masterTextureLimit) { if (m_Texture != null && textureHandle > 0 && m_Texture.GetNativeTexturePtr() == System.IntPtr.Zero) { //Debug.Log("RECREATING"); m_Texture.UpdateExternalTexture(new System.IntPtr(textureHandle)); } _textureQuality = QualitySettings.masterTextureLimit; } #endif } }
public override void Render() { if (m_Video != null) { //GL.InvalidateState(); AndroidMediaPlayer.IssuePluginEvent(Native.AVPPluginEvent.PlayerUpdate, m_iPlayerIndex); //GL.InvalidateState(); // Check if we can create the texture // Scan for a change in resolution int newWidth = -1; int newHeight = -1; if (m_Texture != null) { #if DLL_METHODS newWidth = Native._GetWidth(m_iPlayerIndex); newHeight = Native._GetHeight(m_iPlayerIndex); #else newWidth = m_Video.Call <int>("GetWidth"); newHeight = m_Video.Call <int>("GetHeight"); #endif if (newWidth != m_Width || newHeight != m_Height) { m_Texture = null; m_TextureHandle = 0; } } #if DLL_METHODS int textureHandle = Native._GetTextureHandle(m_iPlayerIndex); #else int textureHandle = m_Video.Call <int>("GetTextureHandle"); #endif if (textureHandle > 0 && textureHandle != m_TextureHandle) { // Already got? (from above) if (newWidth == -1 || newHeight == -1) { #if DLL_METHODS newWidth = Native._GetWidth(m_iPlayerIndex); newHeight = Native._GetHeight(m_iPlayerIndex); #else newWidth = m_Video.Call <int>("GetWidth"); newHeight = m_Video.Call <int>("GetHeight"); #endif } if (Mathf.Max(newWidth, newHeight) > SystemInfo.maxTextureSize) { m_Width = newWidth; m_Height = newHeight; m_TextureHandle = textureHandle; Debug.LogError("[AVProVideo] Video dimensions larger than maxTextureSize"); } else if (newWidth > 0 && newHeight > 0) { m_Width = newWidth; m_Height = newHeight; m_TextureHandle = textureHandle; _playerDescription = "MediaPlayer"; Helper.LogInfo("Using playback path: " + _playerDescription + " (" + m_Width + "x" + m_Height + "@" + GetVideoFrameRate().ToString("F2") + ")"); // NOTE: From Unity 5.4.x when using OES textures, an error "OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_OPERATION: Operation illegal in current state" will be logged. // We assume this is because we're passing in TextureFormat.RGBA32 which isn't the true texture format. This error should be safe to ignore. m_Texture = Texture2D.CreateExternalTexture(m_Width, m_Height, TextureFormat.RGBA32, false, false, new System.IntPtr(textureHandle)); if (m_Texture != null) { ApplyTextureProperties(m_Texture); } Helper.LogInfo("Texture ID: " + textureHandle); } } #if UNITY_5_4_OR_NEWER // In Unity 5.4.2 and above the vidoe texture turns black when changing the TextureQuality in the Quality Settings // The code below gets around this issue. A bug report has been sent to Unity. So far we have tested and replicated the // "bug" in Windows only, but a user has reported it in Android too if (m_Texture != null && textureHandle > 0 && m_Texture.GetNativeTexturePtr() == System.IntPtr.Zero) { //Debug.Log("RECREATING"); m_Texture.UpdateExternalTexture(new System.IntPtr(textureHandle)); } #endif if (m_DurationMs == 0.0f) { #if DLL_METHODS m_DurationMs = (float)(Native._GetDuration(m_iPlayerIndex)); #else m_DurationMs = (float)(m_Video.Call <long>("GetDurationMs")); #endif // if( m_DurationMs > 0.0f ) { Helper.LogInfo("Duration: " + m_DurationMs); } } } }