Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...