Fun Infused Games  |   Smooth Operator RSS 

  Home   |    Archive   |    Subscribe   |    Search   |    About
A Simple SoundBank Class for Windows Phone 7
Date 3/22/2011    Tags WP7    (0)

When you convert your XBLIGs to Windows Phone 7, you will find yourself without XACT support. For me this meant a ton of "soundBank.PlayCue()" calls that would no longer work. Rather than go through the tedious task of replacing them all with new SoundEffect objects, I created my own SoundBank class that allows me to use the calls exactly as they were but plays then in a WP7 kind of way. This class certainly doesn't encapsulate all the functionality of SoundBank but it does give you enough to play your cues.

In the constructor for the following class you pass in an instance of your ContentManager object. Inside the constructor is where you can load all your sounds (add the wave files to your content project). The constructor adds the sounds to a dictionary object. The first string will be the name you would use in your PlayCue() method in your XBLIG version.

Once you load your sounds, just call PlayCue() the same as you used to. For instance if I wanted to play my AsteroidDestroyed sound, I just call soundBank.PlayCue("AsteroidDestroyed").

public class SoundBank
    private Dictionary<string, SoundEffect> sounds;

    public SoundBank(ContentManager content)
        sounds = new Dictionary<string, SoundEffect>();

        sounds.Add("AsteroidDestroyed", content.Load<SoundEffect>("Audio\\AsteroidDestroyed"));
        sounds.Add("Awardment", content.Load<SoundEffect>("Audio\\Awardment"));

    /// <summary>
    /// Play a sound.
    /// </summary>
    public void PlayCue(string cueName)
        if (sounds.ContainsKey(cueName))

This article has been view 1596 times.


No comments for this article.

Add Comments

Name *
  Name the animal in the picture below:

Comment *
Insert Cancel

Xbox (1)  C# (14)  Visual Studio (1)  Cool (2)  iOS (3)  PC (1)  Rant (50)  Sports (11)  XBLIG (32)  Abduction Action (1)  Design (2)  Fin (1)  Volchaos (11)  VolChaos (1)  Nastier (4)  Game Dev (11)  Abdction Action! (1) (18)  Nasty (34)  SQL (1)  XNA (40)  World of Chalk (2)  Video Games (7)  Web (19)  Abduction Action! (27)  Hypership (28)  WP7 (8)  Advise (14)  FIN (20)  Trivia or Die (3)  Development (13)  Absurd (2)  Trivia Or Die (1)