Skip to content

Commit 826d414

Browse files
committed
Update:iOS do not resume playback after app suspended. Attempted fix for #973
1 parent 0da6fca commit 826d414

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

ios/App/Shared/player/AudioPlayer.swift

+17-7
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,24 @@ class AudioPlayer: NSObject {
534534
return
535535
}
536536

537-
switch type {
538-
case .ended:
539-
guard let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt else { return }
540-
let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
541-
if options.contains(.shouldResume) {
542-
self.play(allowSeekBack: true)
537+
// When interruption is from the app suspending then don't resume playback
538+
if #available(iOS 14.5, *) {
539+
let reasonValue = userInfo[AVAudioSessionInterruptionReasonKey] as? UInt ?? 0
540+
let reason = AVAudioSession.InterruptionReason(rawValue: reasonValue)
541+
if (reason == .appWasSuspended) {
542+
logger.log("AVAudioSession was suspended")
543+
return
543544
}
544-
default: ()
545+
}
546+
547+
switch type {
548+
case .ended:
549+
guard let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt else { return }
550+
let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
551+
if options.contains(.shouldResume) {
552+
self.play(allowSeekBack: true)
553+
}
554+
default: ()
545555
}
546556
}
547557

0 commit comments

Comments
 (0)