[iOS] Coroutine couldn't be started because the the game object 'MediaPlayer' is inactive!
Unity version
6000.0.41f1
Unity editor platform
macOS
AVPro Video edition
Core
AVPro Video version
3.2.4
Device hardware
iPhone XR
Which iOS version are you using?
17
Texture format
BGRA
Audio output
System Direct
Any other Media Player component configuration required to reproduce the issue.
Using media player with Display uGUI to display video in Canvas
Which output component(s) are you using?
Display uGUI
Any other component configuration required to reproduce the issue.
No response
The issue
Hello, I am currently loading and playing a local video on a UI Canvas in Unity using:
bool isOpening = mediaPlayer.OpenMedia(new MediaPath(contentUrl, MediaPathType.AbsolutePathOrURL), autoPlay: true);
However, if the parent gameObject is disabled quickly before the video is loaded and played in the canvas, I get the following below error :
Coroutine couldn't be started because the the game object 'MediaPlayer' is inactive! UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator) RenderHeads.Media.AVProVideo.MediaPlayer:StartRenderCoroutine () (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:1023) RenderHeads.Media.AVProVideo.MediaPlayer:InternalOpenMedia () (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:638) RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:535) RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (RenderHeads.Media.AVProVideo.MediaPathType,string,bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:514) RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (RenderHeads.Media.AVProVideo.MediaPath,bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:505)
This in turn makes my game crash.
The issue occurs on iOS & Android builds, as well as in the editor while in Play mode.
I have tried wrapping the mediaPlayer.OpenMedia inside a try-catch method, but the error still occurs.
Is there anything that I can do to avoid this error? Ideally, if the gameObject is not active, then I'd simply let the video load without autoplay
Media information
No response
Log output
Coroutine couldn't be started because the the game object 'MediaPlayer' is inactive!
UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator)
RenderHeads.Media.AVProVideo.MediaPlayer:StartRenderCoroutine () (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:1023)
RenderHeads.Media.AVProVideo.MediaPlayer:InternalOpenMedia () (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:638)
RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:535)
RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (RenderHeads.Media.AVProVideo.MediaPathType,string,bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:514)
RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (RenderHeads.Media.AVProVideo.MediaPath,bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:505)
What is your reason for disabling the parent gameObject? Are you able to provide your crash logs please?
Sure, so there are several reasons:
-
User is presented a pop-up in the UI with the video. The user then closes the pop-up or skips the video before it loads, resulting in the error.
-
User is presented with a scrollview of tutorial videos. When the user scrolls, the video at the top starts to autoplay. The scrollview uses object pooling for performance issues. So, if the users swipes quickly to reach the bottom videos, the top gameObjects are recycled. In this case, the parent gameObject is disabled and re-enabled for pooling before the video finishes loading.
Can you provide a full, unfiltered logcat please
So we have currently discontinued Android builds for other reasons. We have iOS and the issue also occurs in the editor. Is there anything else I can share from the editor for example?
Can you provide a full, unfiltered logcat please
Is the logcat only available from Android? If so, I cannot provide a full logcat right now as Android has been discontinued. Is there an equivalent for iOS or editor?
This issue has been fixed. We now check for the game object being active before starting the render coroutine in the OpenMedia call.
This fix will make it into the next release.
AVPro Video version 3.2.5 has been released. Please let us know if it has not fixed your issue.
Hello, thank you very much for this and apologies for the late reply. Due to several factors we were not able to upgrade the AVPro Video version until now. We updated to the current latest release (v3.2.6) and the issue still persists.
Running this in the Editor with v3.2.6-trial build we get the following:
Coroutine couldn't be started because the the game object 'MediaPlayer' is inactive! UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator) RenderHeads.Media.AVProVideo.MediaPlayer:StartRenderCoroutine () (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:1028) RenderHeads.Media.AVProVideo.MediaPlayer:InternalOpenMedia () (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:638) RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:535) RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (RenderHeads.Media.AVProVideo.MediaPathType,string,bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:514) RenderHeads.Media.AVProVideo.MediaPlayer:OpenMedia (RenderHeads.Media.AVProVideo.MediaPath,bool) (at Assets/AVProVideo/Runtime/Scripts/Components/MediaPlayer.cs:505)
This should be fixed in the next release, version 3.2.7.
AVPro Video version 3.2.7 has been released. Please let us know if this has not fixed the issue for you.