C# Class SunsetHigh.BGMusic

Static class for managing all the background music for the game, using the NAudio library. Currently supports playing, pausing, resuming, stopping, fading in and out, and looping. Fading effects are recommended when changing screens/songs. When providing song file names, please specify the file extension (it's not necessary, but recommended).
Mostrar archivo Open project: ErraticUnicorn/MOSH

Public Methods

Method Description
dispose ( ) : void

Disposes of all resources contained in BGMusic. Call this method at the end of the Game's life.

fadeIn ( ) : void

Song starts from silence and fades in to full volume. Default fade in time.

fadeIn ( double fadeTime ) : void

Song starts from silence and fades in to full volume

fadeOut ( ) : void

Song starts from full volume and fades out to silence. Default fade out time.

fadeOut ( double fadeTime ) : void

Song starts from full volume and fades out to silence

isLooping ( ) : bool

Specifies whether a song is looping (true by default)

isPaused ( ) : bool

Specifies whether the soundtrack is paused (false if is playing)

playSong ( string fileName ) : void

Begins playing a song with the specified file name. Only .mp3, .wma, and .m4a are supported.

setLooping ( bool looping ) : void

Sets whether a song should loop upon ending (true by default)

setPaused ( bool pause ) : void

Sets whether the soundtrack is paused or not

setVolume ( float volume ) : void

Changes the volume of playback; BGMusic.SILENCE can be used for muting the song, while BGMusic.FULL_VOLUME can unmute.

stopSong ( ) : void

Stops song and disposes of it (cannot be resumed afterward)

transitionToSong ( string fileName ) : void

Fades out the current song and starts playing the new song after a short lag. Default fade time and lag times are used.

transitionToSong ( string fileName, double fadeTime, double lagTime ) : void

Fades out the current song and starts playing the new song after a short lag

transitionToSongWithFadeIn ( string fileName ) : void

Fades out the current song and starts fading into the new song after a short lag. Default fade and lag times are used.

transitionToSongWithFadeIn ( string fileName, double fadeTime, double lagTime ) : void

Fades out the current song and starts fading into the new song after a short lag

Private Methods

Method Description
OnFadeOver ( object source, System.Timers.ElapsedEventArgs e ) : void
OnFadeOverFadeIn ( object source, System.Timers.ElapsedEventArgs e ) : void
tryAllFileTypes ( string fileName ) : bool

Method Details

dispose() public static method

Disposes of all resources contained in BGMusic. Call this method at the end of the Game's life.
public static dispose ( ) : void
return void

fadeIn() public static method

Song starts from silence and fades in to full volume. Default fade in time.
public static fadeIn ( ) : void
return void

fadeIn() public static method

Song starts from silence and fades in to full volume
public static fadeIn ( double fadeTime ) : void
fadeTime double Time to fade in, in milliseconds
return void

fadeOut() public static method

Song starts from full volume and fades out to silence. Default fade out time.
public static fadeOut ( ) : void
return void

fadeOut() public static method

Song starts from full volume and fades out to silence
public static fadeOut ( double fadeTime ) : void
fadeTime double Time to fade out, in milliseconds
return void

isLooping() public static method

Specifies whether a song is looping (true by default)
public static isLooping ( ) : bool
return bool

isPaused() public static method

Specifies whether the soundtrack is paused (false if is playing)
public static isPaused ( ) : bool
return bool

playSong() public static method

Begins playing a song with the specified file name. Only .mp3, .wma, and .m4a are supported.
public static playSong ( string fileName ) : void
fileName string File name of the song in the "Content" directory
return void

setLooping() public static method

Sets whether a song should loop upon ending (true by default)
public static setLooping ( bool looping ) : void
looping bool True if the song should loop, false otherwise
return void

setPaused() public static method

Sets whether the soundtrack is paused or not
public static setPaused ( bool pause ) : void
pause bool
return void

setVolume() public static method

Changes the volume of playback; BGMusic.SILENCE can be used for muting the song, while BGMusic.FULL_VOLUME can unmute.
public static setVolume ( float volume ) : void
volume float
return void

stopSong() public static method

Stops song and disposes of it (cannot be resumed afterward)
public static stopSong ( ) : void
return void

transitionToSong() public static method

Fades out the current song and starts playing the new song after a short lag. Default fade time and lag times are used.
public static transitionToSong ( string fileName ) : void
fileName string File name of the new song to play in the "Content" folder
return void

transitionToSong() public static method

Fades out the current song and starts playing the new song after a short lag
public static transitionToSong ( string fileName, double fadeTime, double lagTime ) : void
fileName string File name of the new song to play in the "Content" folder
fadeTime double Time to fade out, in milliseconds
lagTime double Lag time between the two songs (excluding fade time), in milliseconds
return void

transitionToSongWithFadeIn() public static method

Fades out the current song and starts fading into the new song after a short lag. Default fade and lag times are used.
public static transitionToSongWithFadeIn ( string fileName ) : void
fileName string File name of the new song to play in the "Content" folder
return void

transitionToSongWithFadeIn() public static method

Fades out the current song and starts fading into the new song after a short lag
public static transitionToSongWithFadeIn ( string fileName, double fadeTime, double lagTime ) : void
fileName string File name of the new song to play in the "Content" folder
fadeTime double Time to fade out and fade in (each), in milliseconds
lagTime double Lag time between the two songs (excluding fade time), in milliseconds
return void