"Cannot start video" intermittent crash

I have a background video running on my menu screens. The screen/video player gets instanced every time the user goes to a new menu screen. Sometimes the video player crashes with a message “cannot start video”. Any idea why?

video = content.Load<Video>("MainMenu/TauCetiMainMenu");
              
player = new VideoPlayer();

player.Play(video); // sometimes throws "cannot start video"

I had the same code in XNA and it never crashed…

I found this source on Google, probably out of date:

// XNA doesn't return until the video is playing
+            const int timeOutMs = 500;
+            var timer = new Stopwatch();
+            timer.Start();
+            while (State != MediaState.Playing )
+            {
+                if (timer.ElapsedMilliseconds > timeOutMs)
+                {
+                    //We timed out - attempt to stop to fix any bad state
+                    Stop();
+                    throw new InvalidOperationException("cannot start video"); 
+                }
+            }

It looks like an exception that gets thrown when the player times out. The player seems to be more shaky than it was in XNA.
I should probably catch the exception and retry at a later point…

Try with latest source from GitHub or one of development builds from the Downloads page at MonoGame.net.

I will try the development build then, I’m not mentally ready to start building the source yet.

The error still occurs in v. 3.6

Are you able to share the project? Privately is ok. I’d like to get this issue solved for you. slygamer@gmail.com if you can, or even a small sample project that exhibits the issue.

1 Like

Thanks, I’ll work on a repro right away.

Repro project sent.:gift:

I knew I had fixed video issues like this before. The changes had been submitted a while ago but I didn’t realise they hadn’t been merged yet. It fixes the playback, the intermittent start crash and the resource usage (the increased lag the longer it plays). Your test case did show up one issue though, where you manually loop the video. I have now fixed that, but setting IsLooped = true on the VideoPlayer does give a much smoother loop because the player does not have to release and then re-create resources at the loop point.

Hopefully the PR (#5084) will pass the build tests soon and we will try to get it merged into the development branch as soon as possible.

Your test case also exposed another bug in our handling of multisample quality for which I have also submitted a fix (#5083).

Hello,
I am also working in looping videos in monogame and I’ve also found the same problem, sometimes the video player crashes with the “cannot start video” exception.

I have to loop the video manually, because when you try to set the IsLooped property to true, it sents the following exception: “The method or operation is not implemented”.

I am using the 3.6v.

Any ideas?

This “can not start video” issue still seems to exist

I have tried reusing one videoplayer and video object, static versions and having multi copy’s of the objects

Sometimes the video plays 2 or 3 times, but that i get the “can not start video error”

Any ideas how to get around this, or a fix ?

thanks