Possible Duplicate:
playing a .caf file: works fine in simulator but not in iPhone
I’m trying to use SimpleAudioEngine to play background music in an iPhone app I’m working on. I play the background music using the following code:
[[SimpleAudioEngine sharedEngine] preloadBackgroundMusic: @"MenuTheme.mp3"];
[[SimpleAudioEngine sharedEngine] playBackgroundMusic: @"MenuTheme.mp3" loop: YES];
This works fine.
However, when I convert MenuTheme.mp3 to MenuTheme.caf using terminal with the following line:
afconvert -f caff -d LEI16 "MenuTheme.mp3" "MenuTheme.caf"
and I use SimpleAudioEngine again to play the .caf file, it doesn’t work.
Any ideas on how to troubleshoot this? The .caf file does play when I click it. In terminal, when I write:
afinfo "MenuTheme.caf"
It tells me the data format is 2 ch, 44100 Hz, ‘lpcm’ (0x0000000C) 16-bit little-endian signed integer no channel layout.
I really don’t know what’s wrong, but I’m also very new to using audio on the iPhone. Any help is appreciated. Thanks.
edit: afconvert misspelled
I think it is
afconvertnotfconvertas metioned in your question. (I believe that was a typo, right?) I don’t see obvious problem on your command line. I usually use:to convert my wave files to CAF.
Since you cannot play the CAF files by clicking it, I suggest to have a try to convert it to other formats like wave or AIFF:
and try to play them in Finder. If it doesn’t work either, try to convert the MPEG Layer 3 file to wave first by some third-party tools such as Audacity and try again with
afconvert.P.S. I usually use CAF for sound effects, and use AIFF for background music. Please refer to: Sound on iOS: Best Practices.