I gave it a shot on WP7 forums @ MS and no one could help, so trying here.
I cooked up a simple app,开发者_C百科 that has a button. Upon clicking, it plays a sound with the MediaElement control. When I click the button the first time, it does not play at all. The second and subsequent times, it plays the sound fine.
The first time around, the MediaOpened event of the MediaElement if fired off, but the MediaEnded never fires. The subsequent times, the events work as expected.
I posted a small project here documenting the issue.
http://www.angryhacker.com/toys/MediaElementTest.zipIt is probably a bug with Native Media Library and is caused by
MediaPlayer.GameHasControl
When app has been loaded you could call button_click(null,null) with volume 0.0 - just a guess.
Do you want to play a music whole game or just something short like this one? As a workaround use SoundEffect class.
To close out the question. Here are comments by a dev on the WP7 team.
精彩评论