Windows 8 app - MediaElement not playing ".wmv" files

2

I have an issue with MediaElement in my Win8 app - when I try to play some ".wmv" files from local library it very often (not always) throws MediaFailed and I get the error

MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED : HRESULT - 0xC00D36C4

which means

Either the video codec or the audio codec is unsupported, or one of the streams in a video file is corrupted. This content may not be supported.

The problem is not that files are corrupted (I can play them with Windows Media Player). Here's the code I use to set MediaElement:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    var picker = new FileOpenPicker();
    picker.FileTypeFilter.Add(".wmv");
    picker.FileTypeFilter.Add(".mp4");
    picker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
    StorageFile file = await picker.PickSingleFileAsync();
    if (file != null)
    {
        using (IRandomAccessStream ras = await file.OpenAsync(FileAccessMode.Read))
        {
            me.SetSource(ras, file.ContentType);
        }
    }
}

Does anybody know what's wrong here? Thanks in advance.

c#
windows-8
windows-runtime
asked on Stack Overflow Oct 5, 2013 by w.b • edited Oct 7, 2013 by chue x

1 Answer

5

The problem is likely that you are closing the stream prior to playing it. Therefore this code:

if (file != null)
{
    using (IRandomAccessStream ras = await file.OpenAsync(FileAccessMode.Read))
    {
        me.SetSource(ras, file.ContentType);
    }
    // The stream is now closed! How can it be played!?
}

should be changed to not have the using block:

if (file != null)
{
    IRandomAccessStream ras = await file.OpenAsync(FileAccessMode.Read);
    me.SetSource(ras, file.ContentType);
}

I did try the second block of code above on some channel 9 videos (both mid and high quality wmv files) and my app played them successfully.

answered on Stack Overflow Oct 6, 2013 by chue x

User contributions licensed under CC BY-SA 3.0