13
\$\begingroup\$

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!

\$\endgroup\$
2
  • 4
    \$\begingroup\$ Try sticking in a try-catch and check out what exception you're getting. That should help with getting some help on this. \$\endgroup\$
    – Ray Dey
    Jan 28, 2011 at 23:23
  • \$\begingroup\$ 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. \$\endgroup\$ Jan 29, 2011 at 4:27

2 Answers 2

13
\$\begingroup\$

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Ah, the joys of DRM. \$\endgroup\$ Jan 29, 2011 at 11:00
  • 1
    \$\begingroup\$ Good to know, annoying as hell as I imagine quite a few developers run into this issue. \$\endgroup\$
    – Ray Dey
    Jan 29, 2011 at 19:15
2
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .