1

I'm trying to play an mp3 audio file on iPhone executing the following code:

    NSURL *audioURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%@.mp3", FONYK_FILES_URL, [self.voicenote valueForKeyPath:@"Fonyker.fonykid"], [self.voicenote valueForKeyPath:@"Voicenote.vnid"]]];
    NSData *audioData = [NSData dataWithContentsOfURL:audioURL];
    NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                               NSUserDomainMask, YES) objectAtIndex:0] 
                          stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp3", [self.voicenote valueForKeyPath:@"Voicenote.vnid"]]];
    [audioData writeToFile:filePath atomically:YES];
    NSError *error = nil;
    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:filePath] error:&error];
    [audioPlayer play];

When it reaches the AVAudioPlayer instantiation it outputs this in the debugger:

2012-03-15 17:08:51.531 Fonyk[13004:10703] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:  dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-03-15 17:08:51.544 Fonyk[13004:10703] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:  dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security

Can't find anything related, any idea what's happening?

8vius
  • 5,786
  • 14
  • 74
  • 136
  • Have you added the required frameworks? Is this MP3 in a valid iOS format? – Eduardo Costa Mar 15 '12 at 22:03
  • Yes the framework is added. And I believe mp3 is a format in itself, does there have to be something special for it to work on iOS ? – 8vius Mar 15 '12 at 22:06
  • Some evil extension or compression algorithm... :) Have you tryed playing it using "audioUrl" (instead of cloning the file)? – Eduardo Costa Mar 15 '12 at 22:09
  • Yes, then I learned you can't do that, AVAudioPlayer expects a URL that starts with file:// – 8vius Mar 15 '12 at 22:18
  • Why not use "initWithData:error:"? – Eduardo Costa Mar 15 '12 at 22:21
  • 1
    Any chance of your problem is a duplicate of this one? http://stackoverflow.com/questions/7290418/avaudioplayer-error-loading-file – Eduardo Costa Mar 15 '12 at 22:25
  • Seems to be the same thing Eduardo, seems it's a simulator problem, guess I'll have to try and deploy to a device and check it, thank you – 8vius Mar 16 '12 at 03:02
  • possible duplicate of [What does this gdb output mean?](http://stackoverflow.com/questions/7961840/what-does-this-gdb-output-mean) – 8vius Apr 24 '12 at 17:16

1 Answers1

1

Try creating AVURLAsset and asynchronously loading it's tracks as described in the AV Foundation Programming Guide. In the completion block you can create an AVPlayerItem and pass that to the player.

According to AV Foundation Release Notes for iOS 5, starting in iOS 5 the player should load the tracks if they are not already loaded. In my experience, however, this doesn't work. Manually loading them works so that's what I do.

Frank
  • 3,029
  • 5
  • 34
  • 43
  • Got the same error, it has to be as Eduardo referred, it's a simulator problem. Thanks for this anyways, I'll check back when I'm able to run on the device. – 8vius Mar 16 '12 at 15:05
  • I am able to play mp3 files in the simulator. Another minor difference: I am using AVPlayer instead of AVAudioPlayer but I doubt that that is the issue. Best of luck. – Frank Mar 16 '12 at 15:11
  • Mind posting the code you use here? See if there's any difference. I just coded it up as it's shown in the guide. – 8vius Mar 16 '12 at 15:30