Update:iOS do not resume playback after app suspended. Attempted fix for #973

This commit is contained in:
advplyr 2024-02-07 18:02:25 -06:00
parent 0da6fca727
commit 826d414d9f

View file

@ -534,14 +534,24 @@ class AudioPlayer: NSObject {
return return
} }
switch type { // When interruption is from the app suspending then don't resume playback
case .ended: if #available(iOS 14.5, *) {
guard let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt else { return } let reasonValue = userInfo[AVAudioSessionInterruptionReasonKey] as? UInt ?? 0
let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue) let reason = AVAudioSession.InterruptionReason(rawValue: reasonValue)
if options.contains(.shouldResume) { if (reason == .appWasSuspended) {
self.play(allowSeekBack: true) logger.log("AVAudioSession was suspended")
return
} }
default: () }
switch type {
case .ended:
guard let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt else { return }
let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
if options.contains(.shouldResume) {
self.play(allowSeekBack: true)
}
default: ()
} }
} }