Windows 8 app - MediaElement not playing quot;.wmvquot; files(Windows 8 应用程序 - MediaElement 不播放“.wmv文件)
问题描述
我的 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"文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Windows 8 应用程序 - MediaElement 不播放“.wmv"文件
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01