sbooth / SFBAudioEngine

A powerhouse of audio functionality for macOS and iOS
https://sbooth.github.io/SFBAudioEngine/
MIT License
552 stars 87 forks source link

playReturningError failure #259

Closed developer-poplar closed 10 months ago

developer-poplar commented 1 year ago

On ios devices, playReturningError is invalid when the audio is interrupted by another app,I'm using SFBAudioPlayer

sbooth commented 1 year ago

Do you observe the same behavior in the simulator? I tried to reproduce the problem with SimplePlayer-iOS in the simulator but didn't observe the issue.

developer-poplar commented 1 year ago

Sorry, I can't simulate audio termination in the emulator at the moment,But I found something new. When playReturningError was called again after the termination, it worked, but with a long delay, about 60 seconds

developer-poplar commented 1 year ago

After the re-test, if interrupted by an incoming call,is ok. This problem will occur only when the audio is interrupted by other apps,for instance Apple Music

8kdesign commented 11 months ago

Encountered the same issue with interruption. It stops being able to play after I switch to TikTok and come back to my app.

developer-poplar commented 11 months ago

Encountered the same issue with interruption. It stops being able to play after I switch to TikTok and come back to my app.

I used a maybe not very good method to solve this problem, but it worked. I recorded the playback progress in real time in the child thread, flagged any external audio interruptions, and when I needed to play again, I reset SFBAudioPlayer and called seekToPosition to the recorded point in time

sbooth commented 10 months ago

I believe this is caused by AVAudioEngine stopping automatically when the audio session is interrupted. This leaves the player in an inconsistent state internally. Observing AVAudioSessionInterruptionNotification in the player and pausing/restarting appropriately seems to fix the issue.