duc*_*i9y 2 mpmediaitemcollection mpmusicplayercontroller ios
我希望在用户的库中获取一个MPMediaItemCollection或NSArray所有艺术家.这是我当前的代码(显然不起作用):
- (void)viewDidLoad
{
[super viewDidLoad];
MPMediaQuery *artistsQuery = [MPMediaQuery artistsQuery];
self.artistsArray = artistsQuery.collections;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.artistsArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ArtistsCell"];
cell.textLabel.text = [(MPMediaItemCollection *)self.artistsArray[indexPath.row] valueForProperty:MPMediaPlaylistPropertyName];
NSLog(@"%@", cell.textLabel.text);
return cell;
}
Run Code Online (Sandbox Code Playgroud)
对于艺术家列表,请使用MPMediaItemPropertyArtist而不是MPMediaPlaylistPropertyName媒体项属性键.
由于您的数据源使用的是a MPMediaItemCollection,因此请使用该representativeItem属性获取每个集合的艺术家标题字符串.
然后将textLabel's文本设置为艺术家字符串.
MPMediaItemCollection *artistCollection = self.artistsArray[indexPath.row];
NSString *artistTitle = [[artistCollection representativeItem] valueForProperty:MPMediaItemPropertyArtist];
cell.textLabel.text = artistTitle;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
945 次 |
| 最近记录: |