【问题标题】:iOS: Play Spotify Audio in silent modeiOS:以静音模式播放 Spotify 音频
【发布时间】:2017-05-09 05:17:07
【问题描述】:

我正在使用 spotify-iOS-SDK 开发应用程序,我已成功将我的应用程序连接到 Spotify,并且我的音频正在播放,但问题是:当我激活静音模式时,即使我的应用程序没有声音Spotify 音乐仍在播放。我检查了其他使用 Spotify-iOS-SDK (Demo Project, 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) ")
           }
    })
}

【问题讨论】:

  • didStartPlayingTrack 代表是否受到打击?您可能想查看audioStreamingDidBecomeInactivePlaybackDevicedidReceiveError 委托方法。
  • didStartPlayingTrack 运行流畅,我也在曲目播放后立即调用了一些函数,audioStreamingDidBecomeInactivePlaybackDevice 将在我的 PlaySongViewController 关闭后调用,不是因为我让我的手机静音,而对于@987654328 @ 不会在任何地方被调用

标签: audio swift3 ios10 spotify


【解决方案1】:

我已经弄清楚我错过了什么

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)
    }

}

【讨论】:

    猜你喜欢
    • 2012-04-12
    • 2015-12-17
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多