MediaPlayer will not play music on one computer (first chance exception of type System.InvalidOperationException)
I am having an issue with playing 开发者_StackOverflow中文版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.
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.
After downloading the Windows Phone SDK 7.1 (released 9/28/11), my music functionality has been restored.
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.
精彩评论