C# Media Element - No Video

1

I have created a media player designed for the Windows Store and for music and audio files it's working perfect, but it doesn't play video files.

This is the code for the Media Element in the XAML page :

<ContentControl x:Name="MediaContainer"
                HorizontalContentAlignment="Right"
                VerticalContentAlignment="Center"
                Height="405" Width="720" HorizontalAlignment="Right"
                KeyUp="MediaContainer_KeyUp"
                Grid.Column="0" >

<MediaElement Name="CoreMediaElement"
              AudioCategory="BackgroundCapableMedia"
              MediaOpened="CoreElement_MediaOpened"
              MediaEnded="CoreMediaElement_MediaEnded"
              MediaFailed="CoreMediaElement_MediaFailed"
              CurrentStateChanged="CoreMediaElement_CurrentStateChanged"
              AutoPlay="True"/>

</ContentControl>

This is how I set the source of the file:

var file = MediaList[IndexOfMediaFileToBeLoaded].FileData;
try
{
    var stream = await file.OpenAsync(FileAccessMode.Read);
    CoreMediaElement.SetSource(stream, file.ContentType);
}
catch
{
}

where FileData is a StorageFile() object and MediaList is a List() with all the files in the playlist.

After I run a step by step debug, I observed that when I load a video, the MediaElement.MediaFailed event is being triggered and it giver the next error : "MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED : HRESULT - 0xC00D36C4".

OBSERVATION: While writing this post I decided to try to load different types of files, hoping this will resolve the problem. But after I loaded almost 10 videos that didn't work, I looked at the extention : ". MKV". I took my video converter, I converted them to ".MP4" and they worked. So what the problem actually ? I have all the codecs installed. I use K-Lite Codec Pack.

EDIT: ".AVI" files also working.

c#
wpf
video
wpf-controls
media-player
asked on Stack Overflow Dec 15, 2013 by TheQuestioner • edited Jun 11, 2019 by georges619

1 Answer

2

The MediaElement is a control that's able to play only some file types. It's based on media player of windows but only on its core encoders - it will not use additional codecs/plugins. So if a bare-bones media player can't play your file, neither will MediaElelment.

The solution, usually, is to use a different control for playback.

One of them is was VideoLan DotNet that is based on VLC. It's fast, robust and allows playback of virtually any media file. But:

  1. IIRC, it will require your users to install VLC on their machines (might be integrated into install process).
  2. It uses "weird" xaml - you create the control (nothing is shown) and then you create an image that takes its source from the control above. See here (read the first comment for an alternate implementation).

UPDATE:
Nowadays better use libvlcsharp

answered on Stack Overflow Dec 15, 2013 by XAMeLi • edited Jun 18, 2020 by oo_dev

User contributions licensed under CC BY-SA 3.0