views:

505

answers:

3

Hi, I'm building a voice recorder. Recoding and playing works fine on simulator. But on iphone it doesn't work. (I followed the exact steps as mentioned in iPhoneOSProgrammingGuide/AudioandVideoTechnologies)

    printf("%s(player)\n",[[self.soundFileURL absoluteString] UTF8String]);

 AVAudioPlayer *newPlayer =
 [[AVAudioPlayer alloc] initWithContentsOfURL: self.soundFileURL error: nil];

 if([self.soundFileURL isFileURL]){
  printf("isFileURL\n");
 }

 self.player = newPlayer;
 [newPlayer release];

 [player prepareToPlay];
 [player setDelegate: self];
    //recorderLabel.text=@"Playing..";
    [player play];
 printf("playing..\n");

The debugger out put is file://localhost/var/mobile/Applications/9A607A45-974B-4E9F-9839-FD21B3BC9DD8/Documents/1251828741.caf(player) isFileURL playing..

+1  A: 

The iPhone OS on-device does not have the same audio codecs available to it that the iPhone OS in-simulator does. In my projects I have had problems playing back .caf files encoded one way but not another... a bit of trial and error will help here (I ended up using 16BLE PCM).

I would try altering the recorded audio file's encoding in an attempt to find an audio codec supported by the device.

fbrereto
A: 

Make sure sound isn't turned off on the iPhone.

Add the following to your delegate (self):

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)playedPlayer successfully:(BOOL)flag {
    NSLog(@"Done playing %@", flag ? @"with success" : @"with failure" );
}

- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error {
    NSLog(@"Error while decoding: %@", [error localizedDescription] );
}

This might give you some clues.

mahboudz
A: 

.caf file for iPhone need to be encoded as a mono channel and not with a stereo channel then only it will work with iPhone.

yogesh