AVPlayer Can't Play

10,254

Solution 1

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!!!

Solution 2

If you use a local link as URL, so you should initiate url with fileURLWithPath method:

NSURL *url = [NSURL fileURLWithPath:urlstr];
Share:
10,254
Alex Tau
Author by

Alex Tau

iOS Dev

Updated on August 27, 2022

Comments

  • Alex Tau
    Alex Tau over 1 year

    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.