没有扩展名的MediaPlayer无法播放文件名 [英] MediaPlayer cannot play file names without an extension

查看:474
本文介绍了没有扩展名的MediaPlayer无法播放文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试播放的本地文件有没有文件扩展名 System.Windows.Controls.MediaElement 组件失败,并出现FileNotFoundException说< STRONG>媒体文件下载失败。:空。内部异常是 System.Runtime.InteropServices.COMException 与HResult的0xC00D0FEA。

When I try to play a local file having no file extension the component System.Windows.Controls.MediaElement fails with a FileNotFoundException saying "Media file download failed.":null. The inner exception is a System.Runtime.InteropServices.COMException with HResult 0xC00D0FEA.

我想我分配到 MediaPlayer.Source WebClient.DownloadData的URI(URI)并没有问题既不的URI也不返回的数据。

I tried the Uri I assigned to MediaPlayer.Source with WebClient.DownloadData(Uri) and there were no problems with neither the uri nor the returned data.

更新: 当我第一次集中在为什么新的URI(@C:\ TEMP \文件名。)刚刚成为文件:/// C:/ TEMP /文件名后,终于重命名文件filename.data仍是同样的异常被抛出(吞咽尾随点)。我认为WPF - 这是使用媒体基金会,这是最新的技术 - 使用的,而不是只是解析文件中的数据文件扩展名。 facepalm

Update: While I first concentrated on why new Uri(@"c:\temp\filename.") just becomes file:///c:/temp/filename (swallowing the trailing dot) after finally renaming the file to "filename.data" still the very same exception is thrown. I assume that WPF -- which is using Media Foundation, which is newest technology -- uses file name extensions instead of just parsing file data. facepalm

推荐答案

要解决这个问题是很容易
1 - 获取的文件夹路径
2 - 使用IO.Directory.GetFiles(字符串路径)功能
3 - 遍历列表,并获得相匹配乌尔文件名
的第一个文件 4 - 它传递给玩家
它应该是这个样子。

to solve this is easy
1 - get the folder path
2 - use the IO.Directory.GetFiles(string path) function
3 - loop through the list and get the first file that matches ur file name
4 - pass it to the player
it should look something like this

dynamic x = IO.Directory.GetFiles("ur folder path here").ToList;
dynamic fullnamewithext = x.Find(z => IO.Path.GetFileNameWithoutExtension(z) == "ur file name here");

这篇关于没有扩展名的MediaPlayer无法播放文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆