Difference between revisions of "Audio Playback"
(Created page with "=Sound Effects= You will need to declare a SoundEffect: SoundEffect effect; In LoadContent you can then load in your sound effect: effect = Content.Load<SoundEffect>("MyS...") |
|||
Line 20: | Line 20: | ||
=Background Music= | =Background Music= | ||
+ | You will need to declare a Song: | ||
+ | |||
+ | Song song; | ||
+ | |||
+ | You will then need to load the song in LoadContent: | ||
+ | |||
+ | song = Content.Load<Song>("song_name"); | ||
+ | |||
+ | Finally when you want to play the music you can: | ||
+ | |||
+ | MediaPlayer.Play(song); | ||
+ | |||
+ | You can also do: | ||
+ | |||
+ | MediaPlayer.Pause(); | ||
+ | MediaPlayer.Resume(); | ||
+ | MediaPlayer.Stop(); | ||
+ | |||
+ | If you want the song to repeat forever then you can do: | ||
+ | |||
+ | MediaPlayer.IsRepeating = true; | ||
+ | |||
+ | Controlling the volume of the music is easy: | ||
+ | MediaPlayer.Volume+=0.05f; | ||
+ | MediaPlayer.Volume+=0.05f; |
Revision as of 10:32, 26 May 2024
Sound Effects
You will need to declare a SoundEffect:
SoundEffect effect;
In LoadContent you can then load in your sound effect:
effect = Content.Load<SoundEffect>("MySoundEffect");
You can then use the play method to play it when you want:
effect.Play();
Or you can set these and then play the sound effect:
float volume = 1.0f; float pitch = 0.0f; float pan = 0.0f; effect.Play(volume, pitch, pan);
Background Music
You will need to declare a Song:
Song song;
You will then need to load the song in LoadContent:
song = Content.Load<Song>("song_name");
Finally when you want to play the music you can:
MediaPlayer.Play(song);
You can also do:
MediaPlayer.Pause(); MediaPlayer.Resume(); MediaPlayer.Stop();
If you want the song to repeat forever then you can do:
MediaPlayer.IsRepeating = true;
Controlling the volume of the music is easy:
MediaPlayer.Volume+=0.05f; MediaPlayer.Volume+=0.05f;