Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
MasterSongVolume is the default value used when calling PlaySong. This value can be null if no default is used, or a value between 0 and 1 can be assigned where 1 is full volume and 0 is silent.
Setting MasterSongVolume sets the currently playing song's volume as well if any of the following are true:
The Song is a MonoGame/FNA Song which has been played through the AudioManager's PlaySong method
The Song is a MonoGame/FNA Song which has been played through the XNA MediaPlayer
The Song is an ISong (such as an NAudio_Song) and has been played thorugh the AudioManager's PlaySong method.
Setting MasterSongVolume does not affect the volume of NAudio_Song instances which have been played through the NAudio_Song's Play method. For more information, see the NAudio_Song page.
The Play method can be used to play a SoundEffect, optionally specifying the volume to play at. The Play method performs the following additional logic:
It only plays the SoundEffect if AreSoundEffectsEnabled is true.
It checks if the SoundEffect has already been played this frame, preventing the same SoundEffect from playing twice in one frame. This behavior depends on the value of SoundEffectPlayingBehavior.
It increments NumberOfSoundEffectPlays which can be used to measure how many times sound effects have played.
It checks if the argument SoundEffect has been disposed (debug only) and throws an informative exception if so.
The following assumes that Explosion is a SoundEffect. This can be created by adding a .wav file to Glue.
Sounds can be played with a custom volume:
The CurrentlyPlayingSong member returns the song that is currently playing. This value is set as follows:
When PlaySong is called it is set to the song passed to the method
When StopSong is called it is set to null
When the CurrentlyPlayingSong finishes playing it is set to null
If a song is played through the MediaPlayer the AudioManager checks this every frame and automatically sets the CurrentlyPlayingSong
PlaySong plays the argument song, optionally restarting it if it is already playing. This method is automatically called if a song file is added to the FlatRedBall Editor, but it can also be explicitly called for more control over song playing.
Microsoft.Xna.Framework.Media.Song is the default class in MonoGame and FNA for playing music. PlaySong ultimately uses the MediaPlayer.Play method to play a song, so it is inherits the limitations of MediaPlayer, including being able to play only one song at a time. MonoGame's MediaPlayer also suffers from noticeable seek time on MP3s, including looping.
The PlaySong method can also receive any class which implements ISong. The most common type of ISong implementation is the NAudio song. NAudio provides additional flexibility and better seeking/looping compared to MonoGame and FNA, so it is recommended for games which require more song playing flexibility.
For more information on loading an NAudio_Song intance, see the MP3 loading page.
PlaySongs can be used to add multiple songs to the AudioManager to play in order. Once the entire SongPlaylist has finished, it begins playing again from the beginning.
The following code can be used to play multiple songs which are part of GlobalContent.
AreSoundEffectsEnabled can be used to make the Play function produce no audio. This is often set by options screens so that the game code does not need to be cluttered with if-checks surrounding all audio playing.
Setting AreSoundEffectsEnabled to false will not stop any already-playing SoundEffects.