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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With