Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...