RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
226 stars 28 forks source link

Mac: Bad video state when doing two fast consecutive media loads #637

Closed TheloTheGreat closed 3 years ago

TheloTheGreat commented 3 years ago

On Mac, when I call MediaPlayer.OpenMedia twice in fast succession, the second OpenMedia call may leave the MediaPlayer in a state where the audio plays normally, but the video image never updates.

To reproduce, start by loading AVPro 2.0.7 on Mac Unity (2020.2.1), then open the built-in Demo_MediaPlayer demo scene, then edit the code for MediaPlayerUI.Update, adding this near the top:

if (Input.GetKeyDown(KeyCode.Q)) {
    _mediaPlayer.CloseMedia(); // does not matter
    _mediaPlayer.OpenMedia(MediaPathType.RelativeToProjectFolder, "Assets/StreamingAssets/AVProVideoSamples/RenderHeads-1080p30-H264.mp4");
}
if (Input.GetKeyDown(KeyCode.W)) {
    _mediaPlayer.CloseMedia(); // does not matter
    _mediaPlayer.OpenMedia(MediaPathType.RelativeToProjectFolder, "Assets/StreamingAssets/AVProVideoSamples/BigBuckBunny-360p30-H264.mp4");
}

Launch the project and press Q then W in quick succession, about 0.1s to 0.2s apart. The expected result is that the second video plays normally, but the actual result is often (but not always) that you enter a bad state where the second video's sound plays just fine, it appears to be correctly loaded, but its image stays frozen forever. From that bad state, no amount of video seeking, or pausing then resuming, will fix the image.

You don't need to "mash" the Q and W keys, just quickly pressing each key once is enough to trigger the bad state. You can also delete the CloseMedia calls, they have no effect on the problem.

Additionally, when the bad state happens, the FirstFrameReady, ResolutionChanged, and Started events happen exactly like normal, so I don't think I can even detect the bad state from code.

(Note: I'm using AVPro to build a video-intensive UI, where the user really can trigger video loads quite fast, so it's important to me to be able to make quick video changes work right.)

MorrisRH commented 3 years ago

I've managed to reproduce this. Will try and get a fix into the next release.

OpenMedia isn't a cheap call though, you might be better off with two media players that you swap between so you can have the second video preloaded and ready to go.

TheloTheGreat commented 3 years ago

Thanks.

Do you have a rough idea of when to expect the 2.0.8 release that would have that fix in it? Like a couple weeks, a couple months? Just to know if I should bother doing some temp workarounds or not.

MorrisRH commented 3 years ago

End of the week at the latest.

MorrisRH commented 3 years ago

2.0.8 is now available