0

Spotify トラックを再生するアプリがあります。アプリがバックグラウンドに移動すると完全に機能しますが、「呼び出し」または「iOS ポップアップ」によって中断されると、再生が停止します。.plistに追加Required background modesApp 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 に答える