If you’re making a game for the Zune, it’s an obvious feature to be able to play music, integrating the user’s playlist as a soundtrack to the game. XNA Game Studio 3.0 adds some new framework features that makes it easy not only to play music, but also to play one-off sound effects (in .WAV format), eliminating the need to use a full-featured tool like XACT to play simple sounds.
XNA Game Studio 3.0 introduces a new class called SoundEffect that allows you to quickly and easily play sound effects.
- using Microsoft.Xna.Framework.Audio;
- Load the SoundEffect using Content.LoadContent<SoundEffect>(path)
- Call the Play(); method on the SoundEffect instance.
Playing Music from the User’s Library
There are two important classes for playing media: MediaPlayer and MediaLibrary. MediaPlayer is a static class that eventually manipulates the Zune audio player directly. MediaLibrary is a class you can instantiate that contains a list of songs. Playing music is really easy:
- MediaLibrary library = new MediaLibrary();
Easy as pie. The XNA team has done a fantastic job of making it really easy to use media in your games!