Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio stream with AVPlayer

There's a lot of streaming apps out there for iOS. They all use a player, which I assume is the AVPlayer. Yet it seems impossible to find a decent documentation with sample code that works ! I'm pretty sure it's nothing but a few line of codes, but I just can't figure out what's wrong...

I have an EXC_BAD_ACCESS error when trying to call the "play" method. But the url is good and there is an instance of the player.

- (void)viewDidLoad {
    [super viewDidLoad];

// Load the array with the sample file
NSString *urlAddress = @"http://mystreamadress.mp3";

//Create a URL object.
urlStream = [NSURL URLWithString:urlAddress];   
self.player = [AVPlayer playerWithURL:urlStream];   

[urlAddress release];
}

The urlStream is a property with retain attribute. Then I have an IBAction that fires when the button is clicked and that tries to play it, and that's where it crashes.

- (IBAction)playButtonPressed
{       
    [player play];  
}

Can my problem be because I'm trying to play MP3 or what ? The real url adress I'm using works fine when I use a webview to load it.

If anyone could point me to a good sample (not the AVFoundation ou AVPlayer docs from Apple nor the AVTouchController project) it would be realy appreciated.

Thanks !

like image 431
Patrice Cote Avatar asked Feb 19 '11 22:02

Patrice Cote


1 Answers

urlAddress release is causing the issue I think.

You didn't create your NSString with alloc, init so by releasing it you are overreleasing it and getting the EXC_BAD_ACCESS.

Unless you explicitly create an NSString with alloc and init then the convenience methods of creating the string are autoreleased.

like image 115
Walter Avatar answered Nov 07 '22 10:11

Walter