diff --git a/Modules/Sources/PocketCastsUtils/Feature Flags/FeatureFlag.swift b/Modules/Sources/PocketCastsUtils/Feature Flags/FeatureFlag.swift index 7c411e370d..1fb5c7e05d 100644 --- a/Modules/Sources/PocketCastsUtils/Feature Flags/FeatureFlag.swift +++ b/Modules/Sources/PocketCastsUtils/Feature Flags/FeatureFlag.swift @@ -319,6 +319,9 @@ public enum FeatureFlag: String, CaseIterable { /// Enable the Share Profile feature case shareProfile + /// Rewind ~1s on auto-resume after an audio interruption (e.g. CarPlay nav prompts) + case rewindOnResumeAfterInterruption + public var enabled: Bool { if let overriddenValue = FeatureFlagOverrideStore().overriddenValue(for: self) { return overriddenValue @@ -535,6 +538,8 @@ public enum FeatureFlag: String, CaseIterable { false case .shareProfile: BuildEnvironment.current == .debug + case .rewindOnResumeAfterInterruption: + true } } diff --git a/podcasts/PlaybackManager.swift b/podcasts/PlaybackManager.swift index 03276d603d..69d723b11e 100644 --- a/podcasts/PlaybackManager.swift +++ b/podcasts/PlaybackManager.swift @@ -2104,7 +2104,14 @@ class PlaybackManager: ServerPlaybackDelegate { let interruptionOption = userInfo[AVAudioSessionInterruptionOptionKey] as! NSNumber FileLog.shared.addMessage("PlaybackManager handleAudioInterrupt ended, should attempt to restart audio: \(interruptionOption) reason: \(interruptionReason?.description ?? "unknown")") if interruptionOption.uintValue == AVAudioSession.InterruptionOptions.shouldResume.rawValue, wasPlayingBeforeInterruption { - play(userInitiated: false) + if FeatureFlag.rewindOnResumeAfterInterruption.enabled { + let rewindInterval: TimeInterval = 1.0 + let resumeTime = max(0, currentTime() - rewindInterval) + FileLog.shared.addMessage("PlaybackManager rewinding \(rewindInterval)s before resuming after interruption (from \(currentTime()) to \(resumeTime))") + seekTo(time: resumeTime, startPlaybackAfterSeek: true) + } else { + play(userInitiated: false) + } wasPlayingBeforeInterruption = false } } else if interruptionType.uintValue == AVAudioSession.InterruptionType.began.rawValue {