Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to implement a song into a game that begins playing and continually loops on Windows Phone 7 via XNA 4.0. On the emulator, this works fine, however when deployed to a phone, it simply gives a black screen before going back to the home screen. Here is the rogue code in question, and commenting this code out makes the app run fine on the phone:

// in the constructor fields
private Song song;

// in the LoadContent() method
song = Content.Load<Song>("song");

// in the Update() method
if (MediaPlayer.GameHasControl && MediaPlayer.State != MediaState.Playing)
{
    MediaPlayer.Play(song);
}

The song file itself is a 2:53 long, 2.28mb .wma file at 106kbps bitrate.

Again this works perfectly on emulator but does not run at all on phone. Thanks for any help you can provide!

share|improve this question
4  
Try sticking in a try-catch and check out what exception you're getting. That should help with getting some help on this. –  Ray Dey Jan 28 '11 at 23:23
    
Good advice. The exception thrown is "System.InvalidOperationException: Song playback failed, please verify that song is not DRM protected." Also, I have tried with the song encoded as an MP3 and got the same results (worked in emulator, does not work in phone). A side question: is there an easy way to print/save debug text on the phone..? My only option was to draw the text on screen, heh. –  Michael Zehnich Jan 29 '11 at 4:27

2 Answers 2

The answer from Michael Zehnich is indeed correct. However I stumbled upon another problem that cause the same exception.

The problem for me was that I was missing the ID_CAP_MEDIALIB capability in my WMAppManifest.xml.

<Capability Name="ID_CAP_MEDIALIB"/>

Hope this helps.

share|improve this answer
up vote 13 down vote accepted

We figured this out. The information is available online but it's really well hidden, so I'll post it here for good measure.

Basically if the phone is tethered to a computer and the Zune software is running, it locks the media on the phone, which means that MediaPlayers in apps will never have permission to play a Song.

In order to get it to work, the user must un-tether the phone (i.e. unplug the USB cord), or use the Windows Phone Connect tool which has been designed with this in mind with regards to debugging: http://msdn.microsoft.com/en-us/library/gg180729%28v=VS.92%29.aspx - I haven't tried the tool, but untethering worked like a charm.

Also, when the app doesn't have permission to play a song, it will crash unless the exception is handled, so make sure to use try/catch blocks. The caught exception can simply be ignored.

share|improve this answer
1  
Ah, the joys of DRM. –  Jari Komppa Jan 29 '11 at 11:00
1  
Good to know, annoying as hell as I imagine quite a few developers run into this issue. –  Ray Dey Jan 29 '11 at 19:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.