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.
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:
UPDATE:
Nowadays better use libvlcsharp
User contributions licensed under CC BY-SA 3.0