Fix bugs with music not resuming when iOS app is reactivated (#16178)

* Pause instead of stopping music on resign

The [audioSource stop] causes the music to be stopped, and therefore it fails to resume later on a call to [audioSource resume], due to the addition of the if (!stopped) check in resume added in 26a04b38f2

* Don't re-pause music that has already been paused

In this situation:

1. Start game, music plays
2. Switch to Music app, game music paused, start other music
3. Switch to game, game music not resumed due to other music playing
4. Switch to Music app, stop other music
5. Switch back to game, game music should resume due to no other music playing

At step 5 the game music doesn't currently resume. This is because at step 4 when switching to the Music app, the game music gets re-paused (actually isPlaying is false, so systemPaused is set to NO, even though the music *is* still paused). This causes the music to not be resumed at step 5.

This change fixes this, by skipping the pause logic if systemPaused is already true.

Note that this is dependent on https://github.com/cocos2d/cocos2d-x/pull/16178

* Fix typo in previous fix.
This commit is contained in:
SaxonDruce 2016-07-21 17:41:24 +08:00 committed by minggo
parent 233f2111b9
commit bbedddbf08
1 changed files with 11 additions and 9 deletions

View File

@ -644,15 +644,17 @@ static BOOL configured = FALSE;
case kAMRBStopPlay:
for( CDLongAudioSource *audioSource in audioSourceChannels) {
if (audioSource.isPlaying) {
audioSource->systemPaused = YES;
audioSource->systemPauseLocation = audioSource.audioSourcePlayer.currentTime;
[audioSource stop];
} else {
//Music is either paused or stopped, if it is paused it will be restarted
//by OS so we will stop it.
audioSource->systemPaused = NO;
[audioSource stop];
if (!audioSource->systemPaused) {
if (audioSource.isPlaying) {
audioSource->systemPaused = YES;
audioSource->systemPauseLocation = audioSource.audioSourcePlayer.currentTime;
[audioSource pause];
} else {
//Music is either paused or stopped, if it is paused it will be restarted
//by OS so we will stop it.
audioSource->systemPaused = NO;
[audioSource stop];
}
}
}
break;