playing a .caf file: works fine in simulator but not in iPhone

时光怂恿深爱的人放手 提交于 2019-11-29 18:06:08

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.

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.

.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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!