iDevGames Forums
AVAudioPlayer returning -43 - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: AVAudioPlayer returning -43 (/thread-9297.html)



AVAudioPlayer returning -43 - FlamingHairball - Aug 23, 2011 07:40 PM

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.


RE: AVAudioPlayer returning -43 - ipeku - Aug 26, 2011 07:10 PM

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.


RE: AVAudioPlayer returning -43 - FlamingHairball - Aug 27, 2011 05:51 AM

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.


RE: AVAudioPlayer returning -43 - ipeku - Aug 28, 2011 09:01 AM

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.


RE: AVAudioPlayer returning -43 - FlamingHairball - Aug 31, 2011 10:29 AM

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!