Skip to content

Commit bbedddb

Browse files
SaxonDruceminggo
authored and
minggo
committed
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 26a04b3 * 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 #16178 * Fix typo in previous fix.
1 parent 233f211 commit bbedddb

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

cocos/audio/ios/CDAudioManager.m

+11-9
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,17 @@ - (void) applicationWillResignActive {
644644
case kAMRBStopPlay:
645645

646646
for( CDLongAudioSource *audioSource in audioSourceChannels) {
647-
if (audioSource.isPlaying) {
648-
audioSource->systemPaused = YES;
649-
audioSource->systemPauseLocation = audioSource.audioSourcePlayer.currentTime;
650-
[audioSource stop];
651-
} else {
652-
//Music is either paused or stopped, if it is paused it will be restarted
653-
//by OS so we will stop it.
654-
audioSource->systemPaused = NO;
655-
[audioSource stop];
647+
if (!audioSource->systemPaused) {
648+
if (audioSource.isPlaying) {
649+
audioSource->systemPaused = YES;
650+
audioSource->systemPauseLocation = audioSource.audioSourcePlayer.currentTime;
651+
[audioSource pause];
652+
} else {
653+
//Music is either paused or stopped, if it is paused it will be restarted
654+
//by OS so we will stop it.
655+
audioSource->systemPaused = NO;
656+
[audioSource stop];
657+
}
656658
}
657659
}
658660
break;

0 commit comments

Comments
 (0)