Playing a Second Video Freezes Unity (new in 0.1.4)
Summary
Playing a video with a video already playing freezes Unity -- if I had to guess, it is in an infinite loop. This is new in 0.1.4, in 0.1.3 this did not happen. While building a repro scene for this I also stumbled into some other weird behaviors. I could split those into a second issue.
Minimal project and steps to reproduce
-
Clone this repo: https://gitlab.com/brisingre/vlc-unity-bugs
-
Import VLC Unity 0.1.4
-
Open the "122 Double Play Freeze" scene
-
Press play in Unity
-
Press the "New Media, New Player, Play" button in the top left. ("New Media, Play", and "Just Play" work too.) Let Big Buck Bunny start.
-
With a video playing, press one of the buttons on the left. Any of the red ones will freeze (usually or crash (rarely) Unity.
-
If Unity freezes, the only way I know of to fix it is to kill the process and relaunch Unity. Occasionally depending how it is stuck it might work to connect Visual Studio's debugger. Some people do that for infinite loop freezes in Unity, I know. But it never works for me.
Other things to try: Without a video playing, try pressing "Stop, Play" or Pause, Play". (Big Buck Bunny doesn't start when you do this, it seems like it should.)
With a video playing, try pressing "Pause, Play". (Probably nothing happens.) Then press "Pause, Play" a few times quickly. (If you try a few times you'll be able to get it to pause and eventually resume.)
Open and run 115 Buffer Size Gets Stuck. It freezes in the same way, demonstrating:
- This is a new bug in 0.1.4, that demo worked in 0.1.3
- It doesn't matter if you play a different video or the same video
What is the current bug behavior?
Several of these buttons have unusual or undesireable behaviors, particularly when a video is playing.
Most problematic, calling Play on a MediaPlayer that's already played something causes a freeze. Calling Stop first does not prevent this, but recreating the Media Player or calling Pause first does. I'm pretty sure this is new to 0.1.4 and didn't happen in 0.1.3, but that might need more testing to say conclusively.
Slightly unusual, calling Stop or Pause right before Play, on the same frame, seems to make Play not work. That seems like a bug to me but could be that's how it's supposed to work for some reason.
Also unusual, calling Pause and Play on the same frame sometimes pauses and sometimes does not. It seems to be pretty random whether it happens or not, maybe it's a race, and usually Pause finishes first and Play resumes immediately without spending even one frame actually Paused, but occasionally Play finishes first and then Pause finishes and actually pauses playback. I don't have any great reason to call Pause and Play on the same frame, but this does seem like a minor bug to me.
What is the expected correct behavior?
Well, it definitely shouldn't freeze or crash when you play a video. That's the most important thing.
Probably if you call Stop or Pause before calling Play on a video player that isn't playing anything, it should just ignore the Stop or Pause (since there's nothing to stop or pause) and then Play should start playback.
Calling Pause and Play on the same frame should produce consistent behavior.
The most intuitive way would be that if you call Pause before Play, you end up playing (since Play happened more recently) and if you call Play before Pause you end up paused (since Pause happened more recently.) Always ending up Playing or always ending up Paused would be less intuitive, but probably still preferable to what we have now, where you wind up Playing (common) or Paused (less common) unpredictably.
Does it work on other plaforms? Does it work with the official VLC apps?
Right now VLC for Unity only supports one platform. I haven't tried to reproduce all of these in VLC (hard to pause and play on the same frame, for example.) VLC doesn't freeze or crash when you play something it's already playing.
Environment
- OS: Windows
- Version 7
- Device: PC
- LibVLC version and architecture 4.0.0 x64
- LibVLCSharp version Not quite sure how to check this, sorry.
- VLC Unity plugin version 0.1.4 (And this is important! 0.1.3 did not have this freeze as far as I know.)
- Scripting backend used Mono
Possible fixes
Destroying and recreating the Media Player before playing any new media seems to be a decent workaround for the main freeze issue. This is a workaround I've used before. (#115 (closed))
Stop/Pause, then Play not causing media to play can probably be worked around by just not doing that, there's no reason you really have to. Calling Pause and Play on the same frame causing unpredictable behavior likewise, there's even less reason to do it, so don't.