Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if WPF MediaElement is actually playing a video?

I'm developing a WPF based application that must play some videos during its execution. To do this I was using the MediaElement class, however just after I made the first tests with my application, I discovered that some of the videos that I am trying to play are not supported by the Media Element class because I am missing the right codec. After the missing codecs were installed everything worked fine.

The problem is that my customer's machines can also be missing codecs, in that case I would like to display some kind of message saying that a codec is missing so that this problem can be solved quickly, however when I was looking at the MediaElement class I didn't find any property which states why a given video is not playing. Actually from what I've seen the MediaElement doesn't even throw an exception when the video that it's trying to play is not on the right format, nor does it has a state variable saying that it is or is not playing a video.

Therefore I would like to know if there is any way to discover programmatically at runtime if a given video can or cannot be played by the MediaElement.

like image 864
Felipe Avatar asked Nov 24 '11 18:11

Felipe


1 Answers

You can always subscribe to the MediaFailed and MediaOpened events. These two will execute on fails and on success respectively.

In case of a codec error MediaElement.MediaFailed will be raised.

Checkout MSDN for more info on MediaFailed.

like image 185
mcabral Avatar answered Nov 09 '22 12:11

mcabral