问题描述
我的 Win8 应用程序中的 MediaElement
存在问题 - 当我尝试从本地库播放一些.wmv"文件时,它经常(并非总是)抛出 MediaFailed
我得到了错误
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
MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED : HRESULT - 0xC00D36C4
意思是
视频编解码器或音频编解码器不受支持,或者其中之一视频文件中的流已损坏.此内容可能不是支持.
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.
问题是不是文件已损坏(我可以使用 Windows Media Player 播放它们).这是我用来设置 MediaElement
的代码:
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.
推荐答案
问题可能是您在播放之前关闭了流.因此这段代码:
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!?
}
应该改为没有 using
块:
if (file != null)
{
IRandomAccessStream ras = await file.OpenAsync(FileAccessMode.Read);
me.SetSource(ras, file.ContentType);
}
我确实在一些 9 频道视频(中质量和高质量 wmv 文件)上尝试了上面的第二个代码块,并且我的应用成功地播放了它们.
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.
这篇关于Windows 8 应用程序 - MediaElement 不播放“.wmv"文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!