
CHAPTER 7 ■ ADDING SOUNDS TO YOUR XNA 3.0 PROJECT
586
Linkthesoundfiletothisobjectasusual,usingthecontentpipelineintheLoadContent
method:
mySong = Content.Load<Song>("sample");
You’re ready to play the file, using this simple command:
MediaPlayer.Play(mySong);
The MediaPlayer is a static class, which can play only one sound at a time. This makes it
idealforplayingbackgroundscores,butyouwillneedtheapproachexplainedinrecipe7-1to
play other sound effects in your game.
Both the Song object and MediaPlayer class have some useful properties, such as the total
length of a song and the position of the MediaPlayer in the current ...