适用于 iOS 的 Spotify API:从 iOS Spotify API 下载、保存、访问曲目

问题描述 投票:0回答:1

我想知道是否可以使用 Spotify iOS API (CocoaLibSpotify iOS Library) 将曲目下载到 iPhone / iPod / iPad 设备。如果是这样,我还需要访问它们并随时玩。稍后我将在我的应用程序中使用它们。

我想我们可以使用

sp_track_offline_status
来检查正在播放的曲目的离线状态。但我无法克服这一点。

任何示例代码片段都会有很大帮助。

简化要求:下载 Spotify 曲目并将其保存到 iOS 设备中

作为更新,响应 iKendac 的回答,

offlineStatus
属性已变为“1”,这意味着播放器已同步用于本地存储。

SP_PLAYLIST_OFFLINE_STATUS_YES = 1, ///< Playlist is synchronized to local storage
  1. 这是否意味着播放列表中的所有曲目都已下载?

我不这么认为,因为还有以下几种状态:

typedef enum sp_playlist_offline_status {
  SP_PLAYLIST_OFFLINE_STATUS_NO          = 0, ///< Playlist is not offline enabled
  SP_PLAYLIST_OFFLINE_STATUS_YES         = 1, ///< Playlist is synchronized to local storage
  SP_PLAYLIST_OFFLINE_STATUS_DOWNLOADING = 2, ///< This playlist is currently downloading. Only one playlist can be in this state any given time
  SP_PLAYLIST_OFFLINE_STATUS_WAITING     = 3, ///< Playlist is queued for download
} sp_playlist_offline_status;

我从来没有得到过 2 或 3

offlineStatus

  1. 我的
    offlineDownloadProgress
    属性也总是显示“0”。
    如果我没记错的话,它必须从“0”增加到“1”。

代码片段:

[SPAsyncLoading waitUntilLoaded:playList 
                        timeout:kSPAsyncLoadingDefaultTimeout 
                           then:^(NSArray *loadedItems, NSArray *notLoadedItems) {    
    playList.markedForOfflinePlayback = YES;
    currentPlaylist = playList;
    statusTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(checkOfflineStatus) userInfo:nil repeats:YES];

我正在检查状态如下:

-(void)checkOfflineStatus {

  NSLog(@"playlist offline progress is: %f",currentPlaylist.offlineDownloadProgress);

  NSLog(@"offline status: %d",currentPlaylist.offlineStatus);

}

输出如下所示:

2012-07-06 20:34:05.891 简单播放器[6571:10703]播放列表离线进度为:0.000000
2012-07-06 20:34:05.892 简单播放器[6571:10703]离线状态:1
2012-07-06 20:34:06.039 简单播放器[6571:10703]播放列表离线进度为:0.000000
2012-07-06 20:34:06.039 简单播放器[6571:10703]离线状态:1

接下来我可以做什么?

ios api spotify
1个回答
3
投票

您不能简单地将 Spotify 曲目下载为 MP3 文件或其他文件以进行独立播放。

但是,只要用户保持登录 CocoaLibSpotify 的状态,您就可以将库缓存曲目用于稍后离线播放,就像 iOS Spotify 客户端一样。

SPPlaylist
具有用于启用离线访问的
markedForOfflinePlayback
属性,然后播放列表的
offlineDownloadProgress
offlineStatus
属性提供更多信息。

CocoaLibSpotify 附带一个 Mac 示例应用程序,可以缓存播放列表以供离线播放,以了解其工作原理。该 API 在 Mac OS X 和 iOS 版本的 CocoaLibSpotify 上均可用且相同。

© www.soinside.com 2019 - 2024. All rights reserved.