AVPlayer无法播放 [英] AVPlayer Can't Play
本文介绍了AVPlayer无法播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用AVPlayer播放远程mp3.我无法使其正常运行,也无法看到其无法正常工作的原因.代码:
I want to play a remote mp3 with AVPlayer. I can't make it work and I can't see the reason why it doesn't work. Code:
NSString *urlstr=@"..some link to a mp3"
NSURL *url=[NSURL URLWithString:urlstr];
self.player = [[[AVPlayer alloc] initWithURL:url] retain];
[player play];
链接有效.如果我将其加载到webView中,它将立即播放. 请帮忙.
The link is valid. If I load it in a webView it plays right away. Please help.
推荐答案
我有解决方案.请尝试以下代码:
I have get a solution. Please try the following code:
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;
希望它会为您服务!
这篇关于AVPlayer无法播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文