【问题标题】:Get Spotify Track artwork on UITableView在 UITableView 上获取 Spotify Track 艺术作品
【发布时间】:2014-03-21 12:20:11
【问题描述】:

我正在尝试使用 spotify API 获取艺术作品或专辑封面。我正在使用:

NSString *url = @"http://ws.spotify.com/search/1/track.json";

NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                               ([Utils isEmptyString:_searchBar.text] ? @"music" : _searchBar.text), @"q", nil];

[self sendRequestWith:url params:params method:RequestMethodGET success:^(AFHTTPRequestOperation *operation, id response, NSDictionary *userData) {
    NSDictionary *result = (NSDictionary *)response;
    if(result){
        [_trackList removeAllObjects];
        NSArray *tracks = [Utils getDictionaryValue:result by:@[@"tracks"]];
        for (NSDictionary *trackData in tracks) {
            WPTrack *track = [[WPTrack alloc] initWithSpotifyJSON:trackData];
            [_trackList addObject:track];
        }
        [listViewController updateWithObjects:_trackList];
    }
} failure:^(AFHTTPRequestOperation *operation, NSError *error, NSDictionary *userData) {

} userData:nil];

我得到的当前方法似乎没有返回曲目的缩略图。但它会返回曲目的“href”,我可以使用它来通过https://embed.spotify.com/oembed/?url=spotify:track:6bc5scNUVa3h76T9nvpGIH 搜索曲目的图像。但是,这可能是另一个请求,它可能会减慢我在 UITableView 上的加载速度。有没有更好的方法一起完成这个过程?

【问题讨论】:

    标签: ios spotify libspotify


    【解决方案1】:

    通常的做法是在 api 响应中不包含富媒体内容,因为客户端必须等到所有内容都发送完毕,这可能需要很长时间。为了加快这个过程,您应该解析收集到的信息并将其显示给用户,同时您还有另一个异步操作,使用块来检索图像并显示它。

    Using Async call with cell example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 2017-02-22
      • 2018-05-11
      • 1970-01-01
      • 2017-01-10
      相关资源
      最近更新 更多