How do I know if WPF MediaElement really plays video?

I am developing a WPF-based application that needs to play several videos during its execution. For this, I used the MediaElement class, however, immediately after I did the first tests with my application, I found 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 installing the missing codecs, everything works fine.

The problem is that my client computers may also be missing codecs, in this case I would like to show some message that the codec is missing so that this problem can be solved quickly, however, when I looked at the MediaElement class I didn’t Found no property that indicates why this video is not playing. In fact, from what I saw, MediaElement does not even throw an exception when the video it is trying to play is not in the correct format and does not have a state variable saying that it does not play the video.

Therefore, I would like to know if there is a way to detect programmatically at runtime if a given video may or cannot be played by MediaElement .

+4
source share
1 answer

You can always subscribe to MediaFailed and MediaOpened . These two will fail with success.

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

Checkout MSDN for more information on MediaFailed .

+6
source

Source: https://habr.com/ru/post/1382942/


All Articles