When the player encounters a boss in the game I'm working on, I want to have the music change. It seems simple enough with the MediaPlayer class to fade out the current song, switch to another, and then fade the new song in. However, at the point where the second song starts, the game freezes for a split second. The songs in question aren't particularly large either - the first song is 1.7mb and the second song is 3.1mb, both mp3 format. This is the code I'm using to do it:
protected void switchSong(GameTime gameTime)
{
if (!bossSongPlaying)
{
MediaPlayer.Volume -= ((float)gameTime.ElapsedGameTime.TotalSeconds/10);
if (MediaPlayer.Volume < 0.05f)
{
MediaPlayer.Play(bossSong);
MediaPlayer.Volume = 1.0f;
bossSongPlaying = true;
}
}
}
What can I do to eliminate that momentary hang?