Skip to content

Commit

Permalink
Update:iOS do not resume playback after app suspended. Attempted fix …
Browse files Browse the repository at this point in the history
…for #973
  • Loading branch information
advplyr committed Feb 8, 2024
1 parent 0da6fca commit 826d414
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions ios/App/Shared/player/AudioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -534,14 +534,24 @@ class AudioPlayer: NSObject {
return
}

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)
// When interruption is from the app suspending then don't resume playback
if #available(iOS 14.5, *) {
let reasonValue = userInfo[AVAudioSessionInterruptionReasonKey] as? UInt ?? 0
let reason = AVAudioSession.InterruptionReason(rawValue: reasonValue)
if (reason == .appWasSuspended) {
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: ()
}
}

Expand Down

0 comments on commit 826d414

Please sign in to comment.