当在表视图中选择一行但它不播放时,我尝试使用 AVPlayer 播放 URL 中的音频。我究竟做错了什么?
这是代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *streamingString = [NSString stringWithFormat:@"%@.json?client_id=fc886d005e29ba78f046e5474e3fdefb", [streamURLArray objectAtIndex:indexPath.row]];
NSURL *streamingURL = [NSURL URLWithString:streamingString];
NSLog(@"%@", streamingURL);
AVPlayer *player = [AVPlayer playerWithURL:streamingURL];
[player play];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
}
当我记录它时,streamingURL 的一个例子是这样的。
http://api.soundcloud.com/tracks/146814101/stream.json?client_id=fc886d005e29ba78f046e5474e3fdefb
在 .h 文件中全局声明 AVAudioPlayer
像这样AVPlayer *player;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *streamingString = [NSString stringWithFormat:@"%@.json?client_id=fc886d005e29ba78f046e5474e3fdefb", [streamURLArray objectAtIndex:indexPath.row]];
NSURL *streamingURL = [NSURL URLWithString:streamingString];
NSLog(@"%@", streamingURL);
player = [AVPlayer playerWithURL:streamingURL];
[player play];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)