WPF MediaElement问题 [英] WPF MediaElement problem

查看:344
本文介绍了WPF MediaElement问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的WPF应用程序有问题,它看起来像这样:

我有一个必须在后台运行的第三方应用程序.

当提到的应用程序启动时,我的应用程序无法打开任何WMV视频剪辑(在启动该应用程序之前或将其杀死之后-一切正常,视频可以正常播放).

我从MediaElement.MediaFailed事件中得到的错误是:

Hi,

I have a problem with my WPF application and it looks like this:

I have a third party application that has to work in the background.

When the mentioned application is started, my application can not open any WMV video clip (before I start this application or after I kill it - everything is ok and the video is playing fine).

The error I get from MediaElement.MediaFailed event is this:

Message: Cannot find the media file.<br />
Exception: System.Runtime.InteropServices.COMException<br />
Exception from HRESULT: 0xC00D1197



也许您会有一些想法可以帮助您……请做:)



Maybe you will have some ideas that could help ... please do :)

推荐答案

您的解释很清楚(很好,谢谢,这太罕见了!).同时,我们不知道该第三方应用程序的确切功能.你知道吗?此第三方应用程序对您尝试在MediaElement中使用的同一WMV文件执行什么操作?

看起来您的第三方应用程序通过使用独占访问选项打开该文件并保持文件句柄处于打开状态,从而锁定了同一WMV文件.
如果您确实确定在两种情况下都确实存在正确的媒体文件,则您的异常消息会误导您.在某些情况下会发生.

如果是这种情况,则可以使用以下代码直接进行验证(运行第3方应用程序时):

Your explanation is clear (well, thank you, this is so rare!). At the same time, we don''t know what that 3rd-party application does exactly. Do you know? What exactly this 3rd-party application does to the same WMV file you try to use in your MediaElement?

It looks like your third party application locks the same WMV file by opening it with exclusive access options and keeping file handle opened.
If you''re really sure the right media file actually exists in both cases, your exception message is misleading. It happens in some cases.

You can validate directly if this is the case with the following code (when your 3rd-party application is running):

StreamReader reader = new StreamReader("myMediaFile.WMF", false);
reader.Read(); //just one character
reader.Close();



如果文件被您的第三方应用程序锁定,则此代码将引发异常.

您可以从另一端对其进行测试:由某个应用程序锁定文件,然后尝试使用MediaElement运行WPF应用程序以查看其是否引发完全相同的异常.

请在此答案的评论中发布您的步骤和结果.如果需要更多诊断,请准备在某些文本文件中输出完整的异常转储(用完整的异常堆栈转储完成,并递归所有内部异常).



If the file is locked by your third-party application, this code will throw exception.

You can test it from the other side: lock the file by some application, then try running your WPF application with MediaElement to see if it throws exactly same exception.

Please post your steps and results in comments to this Answer. Be prepared to output a complete exception dump (completed with full exception stack dump, with all inner exceptions, recursively) in some text file if more diagnostics is required.


这篇关于WPF MediaElement问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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