【问题标题】:Play Spotify playlist or album music in my iOS app在我的 iOS 应用中播放 Spotify 播放列表或专辑音乐
【发布时间】:2023-03-11 07:45:01
【问题描述】:

Error Domain=com.spotify.ios-sdk.playback Code=1 “由于未指定的问题,操作失败。” UserInfo={NSLocalizedDescription=由于未指定的问题,操作失败

这是我的代码

func getAlbums(authSession:SPTSession){

    SPTPlaylistList.playlists(forUser: authSession.canonicalUsername, withAccessToken: authSession.accessToken) { (error, response) in
        if let listPage = response as? SPTPlaylistList, let albums = listPage.items as? [SPTPartialPlaylist]{

            for item in albums{
                let stringFromUrl =  item.uri
                // use SPTPlaylistSnapshot to get all the playlists
                print("************************\(item.name)************************")
                SPTPlaylistSnapshot.playlist(withURI: stringFromUrl, accessToken: authSession.accessToken!) { (error, snap) in
                    if let s = snap as? SPTPlaylistSnapshot {
                        print("====================\(s.name)=====================")

                        // get the tracks for each playlist
                        SpotifyManager.MyAlbums.append(s)
                        if SpotifyManager.MyAlbums.count == albums.count{
                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: relodNotification), object: nil)
                        }
                    }
                }
            }
        }
    }
}

这个错误来自这个方法

@objc func play() {

    print(songInfo.uri)
    SpotifyManager.player?.playSpotifyURI(self.songInfo.uri.absoluteString, startingWith: 0, startingWithPosition: 0, callback: { (err) in

        print(err.debugDescription)

    })
}

如果有人遇到此类问题,请给我在我的应用中播放 Spotify 音乐的最佳解决方案。

【问题讨论】:

  • 你通过循环重复列表,而没有循环,播放器获取列表并自行处理循环

标签: ios swift spotify


【解决方案1】:

只需删除循环,因为播放器会自动为您执行此操作!

【讨论】:

  • 但是我必须显示所有专辑或播放列表的列表,当点击特定专辑或播放列表时将显示该播放列表中所有歌曲的列表,然后我将点击特定歌曲并播放相同的歌曲.所以我需要循环。
猜你喜欢
  • 2021-07-26
  • 1970-01-01
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多