我想知道是否可以使用 spotify ios api(CocoaLibSpotify IOS 库)将轨道下载到 iphone/ipod/ipad 设备。如果是这样,我还需要访问它们并随时播放。稍后我将在我的应用程序中使用它们。
我想我们可以使用 sp_track_offline_status 检查正在播放的轨道的离线状态。但我无法度过难关。
任何示例代码片段都会有很大帮助。
简化需求 :下载Spotify轨道并将其保存到iOS设备中
作为更新,为了响应 iKenndac 的回答,offlineStatus 属性已变为“1”,这意味着播放器已同步用于本地存储。
SP_PLAYLIST_OFFLINE_STATUS_YES = 1,///< 播放列表同步到本地存储
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。
如果我没记错的话,它必须从“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
接下来我能做什么?
最佳答案
您不能简单地将 Spotify 轨道下载为 MP3 文件或任何独立播放的文件。
但是,您可以让库缓存轨道以供以后离线播放,只要用户保持登录到 CocoaLibSpotify,就像 iOS Spotify 客户端一样。SPPlaylist
有markedForOfflinePlayback
启用离线访问的属性,然后是 offlineDownloadProgress
和 offlineStatus
播放列表的属性提供更多信息。
CocoaLibSpotify 附带一个 Mac 示例应用程序,该应用程序缓存播放列表以供离线播放以查看其工作原理。该 API 在 Mac OS X 和 iOS 版本的 CocoaLibSpotify 上均可用且相同。
关于iphone - 用于 ios 的 Spotify API : download , 保存,从 ios spotify api 访问轨道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11347903/