AVAudioPlayer returning -43

Moderator
Posts: 623
Joined: 2007.09
Post: #1
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:

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.

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Member
Posts: 96
Joined: 2011.07
Post: #2
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.
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #3
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.

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Member
Posts: 96
Joined: 2011.07
Post: #4
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.
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #5
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!

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  AVAudioPlayer kae_ 8 9,007 Aug 10, 2010 04:13 AM
Last Post: kae_
  performance bug in AVAudioPlayer captainfreedom 2 4,078 Aug 4, 2010 12:03 PM
Last Post: captainfreedom
  AVAudioPlayer stutters the game when changing song AdrianM 0 3,847 May 13, 2010 03:59 PM
Last Post: AdrianM
  OpenAL and AVAudioPlayer in the Simulator AkumaStreak 4 6,098 Jul 12, 2009 11:05 AM
Last Post: Madrayken
  AVAudioPlayer captainfreedom 5 4,300 Jun 4, 2009 07:24 AM
Last Post: captainfreedom