我有一个播放Spotify曲目的应用。当app移动到后台时它会完美运行,但是当它被“call”或“iOS弹出窗口”打断时,它会停止播放。
我已在 .plist 中将Required background modes
添加到App plays audio
。
当应用处于后台时,如何在中断结束时恢复播放。
答案 0 :(得分:0)
我使用了音频中断回调。
AudioSessionInitialize (NULL, NULL, interruptionListenerCallback,self);
AudioSessionSetActive(YES);
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
接收到播放管理器的中断呼叫播放/暂停方法后。
void interruptionListenerCallback (void *inUserData, UInt32 interruptionState)
{
// This callback, being outside the implementation block, needs a reference
//to the AudioPlayer object
CustomPlayerView *controller = (__bridge CustomPlayerView *) inUserData;
if (interruptionState == kAudioSessionBeginInterruption)
{
[controller.playbackManager setIsPlaying:NO];
}
else if (interruptionState == kAudioSessionEndInterruption)
{
[controller.playbackManager setIsPlaying:YES];
}
}