WPF MediaElement radomly crashing in background without error

1

I'm attempting to stream video using WPF MediaElement, but i've become stuck on a rather peculiar problem.

The issue is that randomly, perhaps 1 time out of 10 on average, the MediaElement just freezes after the first frame. There is no error in MediaFailed event, and when it happens, the application uses 100% of the CPU core until closed.

The files i'm streaming is mp4 video from GfyCat, for example http://zippy.gfycat.com/AjarHealthyAfricancivet.mp4. I've tried downloading them and playing from disk, same issue. I can also reproduce with a new blank project only containing a MediaElement.

I also tried playing them using the WPF MediaPlayer, same issue. Software rendering the window does not help. The problem seem to occur much more often when running the exe outside of visual studio, but it still sometimes happens while debugging. It also seem to happen more often on monitors other then the primary.

Every time i set a source url, i get a "System.IO.FileNotFoundException: Cannot find the media file. ---> System.Runtime.InteropServices.COMException (0xC00D1197): Exception from HRESULT: 0xC00D1197". I can work around this by simply setting the url again, so i'm not sure if it's a part of the problem or not.

Does anyone know a solution to this problem, or is MediaElement just not the right tool for reliable looping video ?

c#
wpf
video
mp4
mediaelement
asked on Stack Overflow Sep 26, 2014 by sskodje

1 Answer

1

I am have the same problem with looping the video. Sometimes it just don't play, and after that it can't play anymore.

But I had this COMException too, and in my case, the video really was not being copied to output, then it raised the exception, in my case was just a file name mistake or file not existent that was rising this exception.

There's a memory leak on this MediaElement too, for me, this solved it:

    private void CleanUpVideos()
    {
        videoElement.Close();
        videoElement.Clock = null;
        videoElement.Source = null;
        videoElement = null;

        GC.Collect();
        GC.WaitForPendingFinalizers();
    }

User contributions licensed under CC BY-SA 3.0