Sound is a very important part of the game, and for sound it is divided into audio and music, and in this respect XNA also provides a convenient way to manage and play.
A Audio: Generally used to play some very short WAV format audio, such as clicks and other sound effects.
The SoundEffect in the Microsoft.Xna.Framework.Audio namespace includes the processing APIs for Audio, such as play, Stop, pause, and so on, which can also be looped.
SoundEffect SE =. Game.Content.Load ("Hit");
Se. Greateinstance (). Play ();
Se. Greateinstance (). Stop ();
Se. Greateinstance (). Pause ()/Pause
Se. Greateinstance (). Resume ()/Continue
Se. Greateinstance (). islooped = true;//Loop playback
If a lot of sound, you need to manage, you can load the time to add all the resources to a list of management, when needed to be transferred out.
Dictionary audiolist//can use Dictionary to save all sound resources, and its advantage is that resources can be indexed by name.
SoundEffect se = Game.Content.Load ("Sound Resource Name");/load Sound resources
Audiolist.add (Key, SE. CreateInstance ());//Storage resources
audiolist["Sound resource Name"]. Play ()//Get resources and playback
audiolist["Sound resource Name"]. state = = soundstate.playing//Get sound status
Two Music: Music that can be played in MP3 and other formats. Can be used to play background music.
The song in the Microsoft.Xna.Framework.Media namespace includes the processing API for song, such as the name of the music, album, Singer, Time, and so on. But this class can not be used for music play, Stop, Pause, repeat and other operations, you need to mediaplayer this static class to achieve.
Song = Content.load ("Kalimba");
Mediaplayer.isrepeating = true;
Mediaplayer.play (Song);