Dearest reader,
Mommy's Best Games, Inc. is a small, private game developer founded in 2007. Our current game in development is Pig Eat Ball. This is behind the scenes thoughts about game development and marketing.

More game titles are on the right, from Serious Sam Double D XXL to our first, award-winning title Weapon of Choice. Enjoy!

Feel free to contact me if you need more game information!
Nathan

Friday, November 4, 2011

Add Ringtones to XNA games for Windows Phone 7

(This is for game developers offering ringtones through their games--for end users adding their own ringtones to their Windows Phone 7, check here.)

Shoot 1UP for Windows Phone 7 will be coming out early next year. We're excited to offer 3 custom ringtones created from game music, that you'll be able to add to your phone from within the game. Turns out though, none of the online tutorials explained everything necessary for our XNA game to install ringtones.

When we heard about the Mango update, we were excited to support new features like ringtones and 'live tiles'. Searching for help on creating ringtones in the game we found the official MSDN walkthrough.

You can have MP3s or WMAs of the ringtones and you can add the sound from the XAP itself or pull it from isolated storage. Since our game was not generating the ringtone itself (as they were previously recorded), our ringtones are added to the solution and will be pulled from the XAP as shown in the MSDN example.
This shows a .wma being used, but we used .mp3s which work as well.

try
{
    saveRingtoneChooser.Source = new Uri("appdata:/myTone.wma");
    //saveRingtoneChooser.Source = new Uri("isostore:/myTone.wma"); 

    saveRingtoneChooser.DisplayName = "My custom ringtone";

    saveRingtoneChooser.Show();
}
catch (System.InvalidOperationException ex)
{
    MessageBox.Show("An error occurred.");
}
 

The Problem?
When we ran the game and checked for the ringtone file--the file never existed on the phone after we deployed.

The Answer?
We had have "Copy to Output Directory:" set to Copy if newer. This isn't obvious since the default which works with all other content is "Do not copy".




From what we've seen, Live Tiles images work like this too. If you want to use them, you must set them to "Copy if newer" to get them to show up on the phone, as they seems they circumvent the traditional content pipeline. And I believe this issue is only for XNA games (not Silverlight) but if I'm wrong, please inform me in the comments.

Good luck to all devs adding additional, cool content made possible by the Mango update! I think the 'new' WP7 is really sharp and it can help all new games really shine.

7 comments:

Jo8n said...

Awesome! Good to know about the tones and tiles for future use.

I have a question--if you set the Build Action to Content, does that resolve the issue? I've been doing that for stuff I want to refer to in my XAP but don't want in my dll. Not sure if there are other implications though.

Thanks
-Jonathan

Mike said...

You need to set the Build Action to Content and set it to either Copy Always or Copy if Newer. Files only get added to the DLL if their Build Action is set as Resource or Embedded Resource.

Nathan Fouts said...

@Jo8n
If you set BuildAction to Content, it will use whatever is set in the ContentImporter and Processors settings. I'm not certain (but could be off) because of the special way the ringtones are used.

SaveRingtoneTask uses a Uri, it acts differently from just adding a sprite to your game (like normal content).

Nathan Fouts said...

@Mike
Right, I think the Copy part is the key.

@Jo8n,
So I did a test and setting Build Action to Content alone didn't work, the key still seems to be Copy if newer (or Copy always).

I also checked the downloaded solution and example and they had sdkCustomRingtonesCS worked fine (as the ringtones were set to Copy).
I think we just lazily only checked the online docs and since it didn't actually address the content files issue, and we've only worked on sprites and in-game music in our games, we didn't know about the copy trick.

And I'm glad to hear it helps! I figured for those other devs that hadn't known about this either it'd be good to share (since for us, searching the web didn't help).

Jo8n said...

@Nathan/Mike,

Ahh. I've only used it with png's and jpg's in SL which is probably a very specific importer/processor for which it probably automatically does the copy.

It's definitely good to know as I wanted to start on some Live Tiles in my next iteration. Bring any and all info b/c I'm finally almost to the point of realizing that anything I think I know is just hiding something I really don't.

Thanks again!

Sly said...

I have always used Build Action set to None and Copy if Newer. Build Action of Content seems to do nothing for XNA projects. This has always been the case since 7.0 for files we have had to add, such as XML and other files that do nto go in the Content Project.

Tai Chi uniform said...

And even though i have an understanding of I'll need to retain concentrate on my info board for that complete year, a producer new one particular will go beneath it in February. I definitely really feel it creeping up on me...the vitality and excitement...the produce for 'FUN'. It is previously began. I've vowed to no lengthier invest my child-free nights within the front inside the tv. I've began a conditioning sort to improve my energy, and I've signed up for that escape of Dating. I want to acquire around, do factors, recognizing life. I am tired of viewing it pass me by.


http://usacambridges.blogspot.com/
http://windowskey-jay.blogspot.com/
http://keyswindows.blogspot.com/