AVAudioPlayer returning -43
Hey guys,
I'm trying to get AVAudioPlayer working in conjunction with MPMediaPicker in my app and I'm running into an odd issue.
AVPlayer works:
But no cigar for AVAudioPlayer:
player logs null, url logs as a valid mp3 url, and error is 'The operation could not be completed (-43)'.
I feel like I'm missing something really obvious here, but I can't figure out what, and Google is silent on this one. What gives?
Edit: For now, I'm just going to go with AVPlayer on this one. I didn't really need pan anyway… I would still be interested to know what the problem here is though, if anything pops out at you.
I'm trying to get AVAudioPlayer working in conjunction with MPMediaPicker in my app and I'm running into an odd issue.
AVPlayer works:
Code:
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker
didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
if ([mediaItemCollection count] < 1) {
return;
}
NSURL *url = [[mediaItemCollection.items objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL];
self.player = [[AVPlayer alloc] initWithURL:url];
[musicController dismissModalViewControllerAnimated:YES];
[player play];
NSLog(@"player = %@, url = %@", player, url);
}But no cigar for AVAudioPlayer:
Code:
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker
didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
if ([mediaItemCollection count] < 1) {
return;
}
NSURL *url = [[mediaItemCollection.items objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL];
NSError *error;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[musicController dismissModalViewControllerAnimated:YES];
[player play];
NSLog(@"player = %@, url = %@, error = ", player, url, error);
}player logs null, url logs as a valid mp3 url, and error is 'The operation could not be completed (-43)'.
I feel like I'm missing something really obvious here, but I can't figure out what, and Google is silent on this one. What gives?
Edit: For now, I'm just going to go with AVPlayer on this one. I didn't really need pan anyway… I would still be interested to know what the problem here is though, if anything pops out at you.
It might be a streaming issue. AVFoundation currently doesn't support streaming. Only file:// is supported as a valid URL at least on iOS3 (haven't tested on 4 or 5) but that might change.
respect,
pk
iFrog is coming.
Ah, I see.
Reading through the docs (again), I also found that AVAudioPlayer can only initialize using a method supported by CoreAudio, whereas the ipod-library urls are AVFoundation only(except, apparently, for AVAudioPlayer). I'm currently working around it with AVPlayer.
Reading through the docs (again), I also found that AVAudioPlayer can only initialize using a method supported by CoreAudio, whereas the ipod-library urls are AVFoundation only(except, apparently, for AVAudioPlayer). I'm currently working around it with AVPlayer.
I was reading through the specs also. Apparently, AVFoundation does support streaming (since iOS4 with the AVPlayer which they seem to promote as the player for streaming). But in the case of AVAudioPlayer this is not the case although they don't explicitly state that. The thing probably is that AVAudioPlayer (with its prepareToPlay method for example) is designed more for local multimedia assets.
respect,
pk
iFrog is coming.
That's what I'm thinking - I imagine the special ipod-library urls implement some kind of streaming behavior for security.
Got the project working with AVPlayer though, so all's well that ends well I guess. Thanks for your help!
Got the project working with AVPlayer though, so all's well that ends well I guess. Thanks for your help!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| AVAudioPlayer | kae_ | 8 | 7,297 |
Aug 10, 2010 04:13 AM Last Post: kae_ |
|
| performance bug in AVAudioPlayer | captainfreedom | 2 | 3,487 |
Aug 4, 2010 12:03 PM Last Post: captainfreedom |
|
| AVAudioPlayer stutters the game when changing song | AdrianM | 0 | 3,290 |
May 13, 2010 03:59 PM Last Post: AdrianM |
|
| OpenAL and AVAudioPlayer in the Simulator | AkumaStreak | 4 | 5,287 |
Jul 12, 2009 11:05 AM Last Post: Madrayken |
|
| AVAudioPlayer | captainfreedom | 5 | 3,809 |
Jun 4, 2009 07:24 AM Last Post: captainfreedom |
|

