得到了在tableView中显示的数组的索引。需要在didSelectRowAtIndexpath
中播放。
MPMediaItem *item = [arrAnand objectAtIndex:3];
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
player2 = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[player2 play];
需要让index匹配当前选择的应该怎么做?
谢谢
在 didSelectRowAtIndexPath 方法中,你可以使用参数 indexPath 来获取用户当前点击的行索引。你可以使用 indexPath.row 来获取用户选择的行号,然后将其与数组中的索引相匹配。
例如:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MPMediaItem *item = [arrAnand objectAtIndex:indexPath.row];
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
player2 = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[player2 play];
}
这样就可以让索引匹配当前选择的了。