iOS:以静音模式播放Spotify音频

时间:2017-05-09 05:17:08

标签: audio swift3 ios10 spotify

我使用spotify-iOS-SDK开发应用程序,我已成功将我的应用程序连接到Spotify并且我的音频正在播放,但问题是:当我激活静音模式时,我的应用程序没有声音尽管spotify音乐仍然在播放。我已经使用Spotify-iOS-SDK(演示项目,MusixMatch)检查了其他应用程序,所有这些应用程序都可以释放声音

这是我的代码:

        self.spotifyPlayer = SPTAudioStreamingController.sharedInstance()
        self.spotifyPlayer!.playbackDelegate = self
        self.spotifyPlayer!.delegate = self

        try! spotifyPlayer?.start(withClientId: auth.clientID)            
        self.spotifyPlayer!.login(withAccessToken: authSession.accessToken)

然后,将调用此函数:

func audioStreamingDidLogin(_ audioStreaming: SPTAudioStreamingController!) {
    let uri = "spotify:track:" + trackId
    self.spotifyPlayer?.playSpotifyURI(uri, startingWith: 0, startingWithPosition: 0, callback: { (error) in
           if (error != nil) {
                print("error: \(error) ")
           }
    })
}

1 个答案:

答案 0 :(得分:3)

我已经弄明白我错过了什么

func audioStreaming(_ audioStreaming: SPTAudioStreamingController!, didChangePlaybackStatus isPlaying: Bool) {
    print("isPlaying: \(isPlaying)")
    if (isPlaying) {
        try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        try! AVAudioSession.sharedInstance().setActive(true)
    } else {
        try! AVAudioSession.sharedInstance().setActive(false)
    }

}