簡體   English   中英

當應用程序在后台運行時,如何在中斷后恢復Spotify播放器的播放?

[英]How to resume spotify player playback after interrupt when app is in background?

我有一個播放Spotify曲目的應用程序。 當應用移至后台時,它可以完美運行,但是當它被“調用”或“ iOS彈出窗口”打斷時,它將停止播放。 我在.plist中App plays audio添加了Required background modes 當應用程序在后台中斷結束后如何恢復播放。

我已經使用了音頻中斷回調。

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];
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM