首页 > 解决方案 > iOS Spotify Streaming SDK - 错误:上下文失败 1006

问题描述

我正在使用“旧”的 Streaming SDK,因为新的不能满足我的需求。我让它工作得很好,但是对于某些曲目我无法开始播放。我正在将消息打印到控制台,这是我得到的输出:

正在播放:真实

didReceivePlaybackEvent: SPPPlaybackNotifyPlay

didReceivePlaybackEvent: SPPPlaybackNotifyAudioFlush

didReceivePlaybackEvent: SPPPlaybackNotifyMetadataChanged

didReceivePlaybackEvent: SPPPlaybackNotifyAudioFlush

didReceivePlaybackEvent: SPPPlaybackNotifyAudioDeliveryDone

正在播放:假

didReceivePlaybackEvent: SPPPlaybackNotifyPause

*** 收到错误:(1006)上下文失败

didReceivePlaybackEvent: SPPPlaybackNotifyMetadataChanged

这些消息来自委托方法:

func audioStreaming(_ audioStreaming: SPTAudioStreamingController, didReceiveError error: Error) {

    let nsError = error as NSError
    print("*** Received error: (\(nsError.code))\(nsError.localizedDescription)")
}

    func audioStreaming(_ audioStreaming: SPTAudioStreamingController, didChangePlaybackStatus isPlaying: Bool) {
        print("is playing: \(isPlaying)")
    }

    func audioStreaming(_ audioStreaming: SPTAudioStreamingController, didReceive event: SpPlaybackEvent) {
        print("didReceivePlaybackEvent: \(event)")
    }

我相信我正确初始化了我的播放器,它取自 Spotify 回购的官方示例应用程序:

do {
    try player.start(withClientId: clientID, audioController: nil, allowCaching: true)
    player.delegate = self
    player.playbackDelegate = self
    player.diskCache = SPTDiskCache(capacity: 1024 * 1024 * 64)
    player.login(withAccessToken: session.accessToken)
    setBitrate(preferredBitrate)
} catch let error {
    delegate?.didReceiveError(self, error: error, priority: .test)
    closeSession()
}

我查看了错误的文档,但代码 1006 或名称没有错误SPTErrorContextFailed

for err in [
    SPTErrorCodeFailed,
    SPTErrorCodeNoError,
    SPTErrorCodeInitFailed,
    SPTErrorCodeUnsupported,
    SPTErrorCodeNeedsPremium,
    SPTErrorCodeNullArgument,
    SPTErrorCodeUninitialized,
    SPTErrorCodeFailed,
    SPTErrorCodeBadCredentials,
    SPTErrorCodeInvalidArgument,
    SPTErrorCodeNotActiveDevice,
    SPTErrorCodeWrongAPIVersion,
    SPTErrorCodeTrackUnavailable,
    SPTErrorCodeApplicationBanned,
    SPTErrorCodeGeneralLoginError,
    SPTErrorCodeTravelRestriction,
    SPTErrorCodePlaybackRateLimited,
    SPTErrorCodeGeneralPlaybackError
    ] {
        if nsError.code == err {
            print(err)  // It is not printed because there is no error 
                        // 1006 declared
        }
}

正如我所说,所有这些大部分时间都有效,但是对于某些曲目,我得到了错误并且无法播放。我还使用所有可用比特率测试了轨道,但这并没有改变任何事情。

这里可能是什么问题?

标签: iosswiftspotify

解决方案


我想到了。有些曲目在我所在的地区不可用,但我的后端没有正确识别这些曲目。我修复了这个问题,现在只有可播放的曲目被传递给播放器,问题不再发生。

如果无法播放曲目,它将在 Spotify 桌面应用程序中显示为灰色


推荐阅读