How to resume background music after out-going phone call (iOS)?

旧城冷巷雨未停 提交于 2019-12-05 04:26:53

strange from your code is, you're telling that you do use AVAudioPlayer, why do you then implement AVAudioSessionDelegate?

And you have bad implementation of delegate methods. See docs

from AVAudioPlayerDelegate:

- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player

- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withFlags:(NSUInteger)flags

So try to implement them like this, and it should be working properly

On iOS, an app can not start playing audio when already in the background. If your app's audio is stopped because a foreground app has taken control of the audio session, there is (currently) no way to take it back.

You can resume it. After finishing your audio session you have to notify other app that my app deactivate the audio session and you can make use of it. Use the following code.

[[AVAudioSession sharedInstance] setActive:NO withFlags:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!