- Home /
Question on Coroutine and iOS Application Pause Interaction
Hello everyone, I've got a question regarding how coroutines behave when paused/suspended by iOS.
What I'm trying to do: When the player loads the game, a audio clip is played (a song) at random, as the song ends, a brief pause occurs before starting the next randomized song. This works just fine until the game is paused/suspended.
What happens: When pausing the application and then later resuming, the application thinks that the current song has ended (is no longer playing), will pause briefly, then start the next song. What confuses me is that somehow the script thinks the audio stopped playing, but is still executing the next lines from within the coroutine. So, why does the script think the audio is no longer playing while it is still executing from within the same coroutine?
Any ideas are appreciated.
Below is the code in question:
IEnumerator AudioClipRotation ()
{
Debug.Log ("at the first line of the AudioClipRotation coroutine");
audioSource.clip = AudioMethods.RandomizeAudioClip(audioClipArray);
audioSource.Play ();
while (true) //run indefinitely
{
//Debug.Log ("at the first line of the AudioClipRotation coroutine WHILE loop");
while (audioSource.isPlaying)
{
Debug.Log ("audio is still playing");
yield return null;
}
Debug.Log ("about to wait for next song");
yield return new WaitForSeconds (waitBetweenSongs);
Debug.Log ("about to play next randomized song");
audioSource.clip = AudioMethods.RandomizeAudioClip(audioClipArray);
audioSource.Play ();
}
}
Your answer
Follow this Question
Related Questions
C# try catch block doesn't work for iOS? 2 Answers
JIT compilation requirement for System.Reflection.PropertyInfo.GetValue? 1 Answer
A node in a childnode? 1 Answer
Automatically load asset bundles on start from cache 0 Answers
Multiple Tiled GPU warning: RenderTexture color surface errors? 0 Answers