gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:22:24 25 4
gpt4 key购买 nike

我正在使用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) ")
}
})
}

最佳答案

我已经弄清楚了我所缺少的

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

}

关于audio - iOS:以静音模式播放Spotify音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43861684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com