【问题标题】:How to get the list of songs using Spotify in Swift3 iOS?如何在 Swift3 iOS 中使用 Spotify 获取歌曲列表?
【发布时间】:2018-05-28 13:04:21
【问题描述】:

我正在使用 Swift3 语言开发一个音乐应用程序。用户将有弹出选项来显示使用音乐库和 Spotify 的歌曲列表。我可以将音乐库中的歌曲列表显示到我的表格视图中。现在我必须从 Spotify 获取播放列表。所以,我在accounts.spotify.com添加了应用程序,我可以使用SPTAudioStreamingController.sharedInstance().metadata一首播放歌曲,但完整的歌曲列表没有出来。

我点击这个链接:https://github.com/Sethmr/SpotifyInSwift & https://medium.com/@elonrubin/ios-spotify-sdk-swift-3-0-tutorial-b629af4b889d & https://developer.spotify.com/technologies/spotify-ios-sdk/tutorial/

问题是如何获取 Spotify 歌曲列表。如果有人有任何想法,请建议我。谢谢!

【问题讨论】:

  • 使用播放列表是一个很大的话题,您可能想熟悉spotify.github.io/ios-sdk/Classes/SPTPlaylistList.html 和与播放列表相关的其他类。如果您有一些无法编写的代码,请回来,人们可能会为您提供帮助。
  • 感谢您的建议,看来我需要调用这个 + playlistsForUser:withAccessToken:callback: 方法来获取播放列表?

标签: ios swift spotify


【解决方案1】:

还有一个可以尝试here

还有一些控件

获取专辑:

_ = Spartan.getAlbum(id: albumId, market: .us, success: { (album) in
    // Do something with the album    
}, failure: { (error) in
    print(error)      
})

获取多个曲目:

_ = Spartan.getTracks(ids: trackIds, market: .us, success: { (tracks) in
    // Do something with the tracks
}, failure: { (error) in
    print(error)
})

试试吧,也许对你有帮助 https://github.com/Daltron/Spartan

也可以通过this answer(Samantha's)

SPTPlaylistList.playlists(forUser: session.canonicalUsername, withAccessToken: session.accessToken, callback: { (error, response) in
                self.activityIndicator.stopAnimating()
                if let listPage = response as? SPTPlaylistList, let playlists = listPage.items as? [SPTPartialPlaylist] {
                    self.playlists = playlists    // or however you want to parse these
                    self.tableView.reloadData()
                    if listPage.hasNextPage {
                        self.getNextPlaylistPage(currentPage: listPage)
                    }
                }
            })

更新:

也参考这个sample code

【讨论】:

  • 谢谢@manukv,你能告诉我如何获得 session.canonicalUsername 吗?
  • canonicalUsername 是 SPTSession 类的属性
  • 获取 accessToken 的同一会话
  • 好的,我得到了那个属性。让我试试这个。
  • 我已经使用 SPTSession 类获得了我的 CanonicalUserName,在实施上述方法后,我得到了 : ------ of 0 个项目作为响应...似乎列表为空。
猜你喜欢
  • 2020-07-15
  • 2017-05-04
  • 1970-01-01
  • 2015-01-13
  • 1970-01-01
  • 2016-07-01
  • 2017-09-19
  • 2016-02-26
  • 1970-01-01
相关资源
最近更新 更多