0

我有一个播放 Spotify 曲目的应用程序。当应用程序移至后台时,它可以完美运行,但当它被“呼叫”或“iOS 弹出窗口”中断时,它会停止播放。我已添加Required background modes.plistApp plays audio中。如何在应用程序处于后台时中断结束时恢复播放。

4

1 回答 1

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];
}
}
于 2013-10-16T11:37:45.673 回答