Engines/FlatRedBallXNA/FlatRedBall/Audio/AudioManager.cs
/// <summary>
/// Plays the argument song, optionally restarting it if it is already playing.
/// </summary>
/// <param name="toPlay">The song to play.</param>
/// <param name="forceRestart">Whether the song should be restarted. If the toPlay parameter differs from the currently-playing song then it will 
/// restart regardless of the forceRestart value. This value only matters when the currently-playing song is passed.</param>
/// <param name="isSongGlobalContent">Whether the song uses a Global content manager. This is important if StopAndDisposeCurrentSongIfNameDiffers is called.
/// StopAndDisposeCurrentSongIfNameDiffers is called by Glue, so the isSongGlobalContent param matters even if your code is not directly calling this function.</param>
Plays the argument song, optionally restarting it if it is already playing.
Plays the argument song optionally restarting it if it is already playing .
public static void PlaySong(Song toPlay, bool forceRestart, bool isSongGlobalContent)
        {
            bool shouldPlay = true;
			shouldPlay = IsCustomMusicPlaying == false || (mDoesUserWantCustomSoundtrack.HasValue && mDoesUserWantCustomSoundtrack.Value == false);
#if WINDOWS_PHONE
            if (!shouldPlay && !mDoesUserWantCustomSoundtrack.HasValue && AreSongsEnabled)
            {
                Guide.BeginShowMessageBox(
                    "Stop music?",
                    "Would you like to stop your current music and listen to the music for this game?",
                    new string[] { "Yes", "No" }, 0, MessageBoxIcon.Alert, UserPermissionCallback, null);
            }
#endif
            if (toPlay.Name != mLastSongNameRequested || forceRestart || 
                CurrentlyPlayingSong == null)
            {
                mSongLastRequested = toPlay;
                mIsSongUsingGlobalContent = isSongGlobalContent;
                mLastSongNameRequested = toPlay.Name;
            }
            else
            {
                shouldPlay = false;
            }
            if (shouldPlay && AreSongsEnabled)
            {
                mCurrentSong = toPlay;
                CurrentlyPlayingSong = mCurrentSong;
                mIsSongUsingGlobalContent = isSongGlobalContent;
				#if ANDROID
				try
				{
                	MediaPlayer.Play(toPlay);
				}
				catch(Java.IO.IOException e)
				{
					string message = e.Message;
					if(message.Contains("0x64"))
					{
						int msToWait = 100;
						System.Threading.Thread.Sleep(msToWait);
						MediaPlayer.Play(toPlay);
					}
					else
					{
						throw e;
					}
				}
				#else
				Microsoft.Xna.Framework.Media.MediaPlayer.Play(toPlay);
				#endif
            }
        }
public static void PlaySong ( Song toPlay , bool forceRestart , bool isSongGlobalContent ) { bool shouldPlay = true ; shouldPlay = IsCustomMusicPlaying == false || ( mDoesUserWantCustomSoundtrack . HasValue && mDoesUserWantCustomSoundtrack . Value == false ) ; if WINDOWS_PHONE if ( ! shouldPlay && ! mDoesUserWantCustomSoundtrack . HasValue && AreSongsEnabled ) { Guide . BeginShowMessageBox ( " " , " " , new string [ ] { " " , " " } , 0 , MessageBoxIcon . Alert , UserPermissionCallback , null ) ; } endif if ( toPlay . Name != mLastSongNameRequested || forceRestart || CurrentlyPlayingSong == null ) { mSongLastRequested = toPlay ; mIsSongUsingGlobalContent = isSongGlobalContent ; mLastSongNameRequested = toPlay . Name ; } else { shouldPlay = false ; } if ( shouldPlay && AreSongsEnabled ) { mCurrentSong = toPlay ; CurrentlyPlayingSong = mCurrentSong ; mIsSongUsingGlobalContent = isSongGlobalContent ; if ANDROID try { MediaPlayer . Play ( toPlay ) ; } catch ( Java . IO . IOException e ) { string message = e . Message ; if ( message . Contains ( " " ) ) { int msToWait = 100 ; System . Threading . Thread . Sleep ( msToWait ) ; MediaPlayer . Play ( toPlay ) ; } else { throw e ; } } else Microsoft . Xna . Framework . Media . MediaPlayer . Play ( toPlay ) ; endif } }
Plays the argument song, optionally restarting it if it is already playing.
Plays the argument song optionally restarting it if it is already playing .
// November 19, 2014 // For some reason the // automated test project // would always crash when // trying to play a song on // a certain screen.  I was able // to avoid the crash by putting a // breakpoint and waiting a while before // continuing execution.  I suppose it means // that the song needs a little bit of time before // it is played.  So I just added a catch and put  // This needs a second before it starts up
toPlay
Song
The song to play.
The song to play .
forceRestart
bool
Whether the song should be restarted. If the toPlay parameter differs from the currently-playing song then it will
restart regardless of the forceRestart value. This value only matters when the currently-playing song is passed.
Whether the song should be restarted . If the toPlay parameter differs from the currently - playing song then it will restart regardless of the forceRestart value . This value only matters when the currently - playing song is passed .
isSongGlobalContent
bool
Whether the song uses a Global content manager. This is important if StopAndDisposeCurrentSongIfNameDiffers is called.
StopAndDisposeCurrentSongIfNameDiffers is called by Glue, so the isSongGlobalContent param matters even if your code is not directly calling this function.
Whether the song uses a Global content manager . This is important if StopAndDisposeCurrentSongIfNameDiffers is called . StopAndDisposeCurrentSongIfNameDiffers is called by Glue so the isSongGlobalContent param matters even if your code is not directly calling this function .