NAudio_Song
Last updated
Last updated
The NAudio_Song class provides more control over the playing of a song compared to using MonoGame/FNA's Song class.
The easiest way to load an NAudio_Song is to use the FRB Editor, add an MP3 to a Screen's Files, and to select NAudio_Song as the type. For more information on loading through the FRB Editor, see the FRB Editor's MP3 page.
Alternatively, NAudio_Song instances can also be loaded in code. The following code shows how to load an NAudio_Song. The loaded song is registered with FlatRedBall so that it can be unloaded when the content manager is unloaded (usually for a screen).
Once an NAudio_Song is loaded, it can be played in your game.
If you have loaded your song through the FRB Editor, it will play by default. You can control this through the Song tab.
NAudio_Song instances can be played through the AudioManager. If your game only needs one song playing at a time, then the AudioManager.PlaySong
is a convenient way to play the song.
The code above plays the song through the AudioManager, which means that the standard behavior for song playing is applied:
The song plays only if songs are enabled (AudioManager.AreSongsEnabled
)
The song respects the default song volume (AudioManager.MasterSongVolume
)
The song is registered as the current song, stopping other songs from playing
The song clears the AudioManager
's Playlist (AudioManager.PlaySongs
)
Although these behaviors may be convenient in some cases, you can directly access the NAudio_Song methods and properties for more control.
For example, a song can be played directly without using the AudioManager using the Play method as shown in the following code:
Keep in mind that the AudioManager will not be notified of the song playing, so mixing AudioManager behavior with direct Play calls may cause overlapping songs to play, or other confusing behavior.
This may be desirable if you would like to play two songs at the same time, or if you would like to crossfade songs. For information about fading songs, see the Volume section.
NAudio_Song's Volume property can be used to make a song play more quietly. By default the volume value is at 1, which means full volume. A value of 0 silences the song. Values above 1 can be used, and the song will play louder, but it is not recommended for final products.
The following code shows how to adjust the volume of a song using the keyboard:
The Volume property can be changed gradually over time to create a fade as well. The following method uses the TweenerManager to gradually change the volume over one second: