我想使用AVPlayer播放远程mp3。但是无法使其工作,也不知道出现问题的原因。代码:
NSString *urlstr=@"..some link to a mp3"
NSURL *url=[NSURL URLWithString:urlstr];
self.player = [[[AVPlayer alloc] initWithURL:url] retain];
[player play];
链接有效。如果我在webView中加载它,它会立即播放。 请帮忙。
我想使用AVPlayer播放远程mp3。但是无法使其工作,也不知道出现问题的原因。代码:
NSString *urlstr=@"..some link to a mp3"
NSURL *url=[NSURL URLWithString:urlstr];
self.player = [[[AVPlayer alloc] initWithURL:url] retain];
[player play];
我有一个解决方案。请尝试以下代码:
NSString *urlstr=@"http://www.3rdeyelab.com/mp3/mp3/tailtoddle_lo.mp3"
NSURL *url=[NSURL URLWithString:urlstr];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
player = [[AVPlayer playerWithPlayerItem:playerItem] retain];
[player play];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
fileURLWithPath
方法来初始化URL:NSURL *url = [NSURL fileURLWithPath:urlstr];