Spotify iOS SDK - 没有后台播放

jac*_*rln 3 spotify ios

我无法让Spotify iOS SDK使用后台播放功能,以便在手机锁定或应用程序不再处于活动状态时继续播放曲目.

我有UIBackgroundModes我的Info.plist设立为这样:

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
    <string>fetch</string>
</array>
Run Code Online (Sandbox Code Playgroud)

在应用程序中设置SDK时,还有其他我缺少的东西或我需要启用的东西吗?

在此先感谢您的帮助

jac*_*rln 11

为了解决这个问题,我不得不扩展我的类以实现SPTAudioStreamingPlaybackDelegate和写入函数来激活和停用AVAudioSession

步骤1

func audioStreaming(_ audioStreaming: SPTAudioStreamingController!, didChangePlaybackStatus isPlaying: Bool) {
    if isPlaying {
        self.activateAudioSession()
    } else {
        self.deactivateAudioSession()
    }
}
Run Code Online (Sandbox Code Playgroud)

第2步

// MARK: Activate audio session

func activateAudioSession() {
    try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
    try? AVAudioSession.sharedInstance().setActive(true)
}

// MARK: Deactivate audio session

func deactivateAudioSession() {
    try? AVAudioSession.sharedInstance().setActive(false)
}
Run Code Online (Sandbox Code Playgroud)