tanhakabir / SwiftAudioPlayer

Streaming and realtime audio manipulation with AVAudioEngine
https://medium.com/chameleon-podcast/creating-an-advanced-streaming-audio-engine-for-ios-9fbc7aef4115
MIT License
567 stars 109 forks source link

[BUG] audio interruptions(phone call / Siri) will make the song skip to wrong time #112

Closed dylancom closed 3 years ago

dylancom commented 3 years ago

Audio interruptions (such as receiving a phone call, opening Siri) will pause the song. If you press "play" again after an interruption, the song suddenly skips forward (leading sometimes to a song ending too early / skipped parts).

EDIT: It will skip exactly the amount of how long Siri was open.

Reproduction: Run the Example on a Phone, and play the Soundbite song. Now open Siri (by holding the home button or voice command) and notice the song will pause. After Siri closes, press play and notice the song is suddenly skipping many seconds forward.

Expected behavior: After an audio interruption, pressing play should play from the position where the song paused. Besides that, normally the song should be auto-playing again (instead of having to manually press play again), but I guess this is because AVAudioEngine was used? (AVPlayer handles toggling pause/play automatically after an interruption)

dylancom commented 3 years ago

Code Examples: https://developer.apple.com/documentation/avfaudio/avaudiosession/responding_to_audio_session_interruptions https://github.com/tanguyantoine/react-native-music-control/blob/master/ios/MusicControlManager.m#L419