If you're using XACT, then the process is fairly simple:
1) Add your music files to the Wave Bank
2) Add each of them as a Sound in the Sound Bank
3) Create a new Cue, call it "background_music" or something
4) Drag each of the pieces of music from the Sound Bank into the right panel next to the Cue. They should each be added and have a "probability" number attached to them.
You can now edit the probabilities individually if you want to, but more importantly a random piece of music will be played whenever you call Cue.Play("background_music"). Be sure to set each of them under the "Background Music" group if you want to properly support Custom Soundtracks.
2) To stop the music when you want, you need to save the Cue object when playing it. Then you can call Cue.Stop later on to stop the music:
| Cue cue; |
| |
| void StartLevel() |
| { |
| Cue cue2 = soundBank.GetCue("background_music"); |
| |
| //stop any music that might be playing |
| if (cue != null) |
| { |
| if(cue.IsPlaying) |
| cue.Stop(AudioStopOptions.Immediate); |
| } |
| cue = cue2; |
| cue.Play(); |
| } |
| |
| void EndLevel() |
| { |
| if (cue != null) |
| { |
| if (cue.IsPlaying) |
| cue.Stop(AudioStopOptions.AsAuthored); |
| } |
| } |
"No programmer can pick up a TV remote without thinking what it would take to add a stun gun. [...] Their motto is 'if it ain't broke, it doesn't have enough features yet'" - Scott Adams,
The Dilbert PrincipleThe signature that was too big for the 512 char limit