MediaPlayer 不会在一台计算机上播放音乐(System.InvalidOperationException 类型的第一次机会异常)
我在使用 XNA 播放音乐时遇到问题,并且此问题仅发生在一台计算机上。在此计算机上,当它尝试执行 MediaPlayer.Play(someMusic)
时,我在标题中收到错误消息。但是(见下文),该问题与 Visual Studio 无关。
我已经尽我所能研究了这一点。其他人也遇到过这个问题,但是这些建议都没有解决我的问题。此问题的主要原因(至少对于其他人来说)是连接了 Windows Phone 并运行了 Zune。显然它锁定了媒体库。所以我要说的是:
- 我在编码 XNA 时没有/从未连接过 Windows Phone(没有开发人员解锁的手机)
- 作为尝试解决此问题的一部分,我已经完全卸载了 Zune,但问题仍然存在持续存在。
其他一些建议似乎围绕 Visual Studio 环境中的设置,或围绕音乐文件本身的问题。对此,我可以说:
- 我已经构建了包含此问题的可执行文件,这些可执行文件并不总是表现出此问题,但其本身并未更改。
- 这些可执行文件曾经在相关计算机上播放音乐,但现在不再这样做。
- 这些可执行文件确实在我的其他计算机上播放音乐。
我真的很难过。以下是我尝试过的其他一些方法:
- 卸载从问题出现之前到现在的所有程序
- 注册表清理
- 卸载并重新安装 Windows Media Player
我运行的是 Windows 7 64 位。其中一台没有出现此问题的计算机也运行相同的操作系统。
令人沮丧的是,这台计算机是我的主要开发计算机。这台计算机宇宙的某个黑暗角落似乎发生了一些变化。非常感谢任何建议。
I am having an issue with playing music using XNA, and this issue is only occurring on one computer. On this computer, I get the error message in the title when it tries to execute MediaPlayer.Play(someMusic)
. However (see below), the problem is independent from Visual Studio.
I have researched this as well as I can. Other people have had this issue, however none of the suggestions have solved my problem. The primary cause of this issue (at least for others) is having their Windows Phone connected and Zune running. Apparently it locks the media library. So let me say that:
- I do not / have never had my Windows Phone connected while coding XNA (do not have a developer-unlocked phone)
- As part of my attempt to fix this problem, I have uninstalled Zune completely, and the problem still persists.
Some of the other suggestions seem to revolve around settings in the Visual Studio environment, or issues revolving around the music file itself. To this, I can say that:
- I have already-built executables that contain this problem, executables which did not always exhibit this problem but which themselves have not been changed.
- These executables used to play music on the computer in question, but no longer do.
- These executable do play music on my other computers.
I am truly stumped. Here are some of the other things I've tried:
- Uninstalling every program from before the problem started to the present
- Registry cleaning
- Uninstalling and reinstalling Windows Media Player
I am running Windows 7 64-bit. One of the other computers that is not having this issue is also running the same OS.
It is frustrating because this computer is my chief development computer. It seems like something has been changed in some dark corner of this computer's universe. Any suggestions are extremely appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在深入研究之前,请验证您尝试在此机器上播放的每首歌曲是否都会发生这种情况。
如果是这样,请用 try...catch 包围您的 MediaPlayer.Play 代码
以下是 MediaPlayer.Play 代码实际执行的操作:
似乎它返回一些异常代码,包装为 InvalidOperationException 内的内部异常(假设这是您看到的异常) )。
请查看这个内部异常并检查您收到的异常是什么。
这可能有助于揭示造成这种情况的确切原因。
Before diving deeper, verify that this occurs for EVERY SONG you're attempting to play on this machine.
If it does, surround your MediaPlayer.Play code with try...catch
Here's what the code of MediaPlayer.Play actually does somewhere down the line:
It appears that it returns some exception code, wrapped as an inner exception inside the InvalidOperationException (assuming this is the exception you're seeing).
Please peek into this inner exception and check what is the exception you're receiving.
This may help shed some light on the exact cause for this.
下载 Windows Phone SDK 7.1(2011 年 9 月 28 日发布)后,我的音乐功能已已恢复。
After downloading the Windows Phone SDK 7.1 (released 9/28/11), my music functionality has been restored.
确保您已安装 Windows Media Player。 XNA 使用一些 WMP DLL 文件来播放音乐。如果未安装 WMP,它无法找到它们并抛出异常并带有非常误导性的消息。
Make sure that you have Windows Media Player installed. XNA uses some of the WMP DLL files to play music. With WMP not installed, it can't find them and throws the exception with a very misleading message.