If it works with the debugger and not in the actual application, you can be almost certain it's a timing issue.
In your case, the problem is that you're not waiting for the sound to load before trying to play it. It works on the emulator because the execution is paused, giving enough time to load the sound.
Before setting the source, subscribe to the MediaOpened
event of the MediaElement. Then, in that event, call the Play
method to play the sound.
Alternatively, you can set the AutoPlay
property to true
to automatically play the sound once it has finished downloading.