Alex Tau Alex Tau - 3 months ago 13
iOS Question

AVPlayer Can't Play

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];


The link is valid. If I load it in a webView it plays right away.
Please help.

Answer

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; 

Hope it will work for you!!!

Comments