5

I don't know squat about audio or the Terminal. I've use this Terminal command to convert a wav file for use in iOS:

afconvert -v -f 'caff' -d LEI16 -s 1 /users/myUserName/Desktop/hibeep.wav /users/myUserName/Desktop/hibeep.caf

After adding the file to my project, nothing happens when I execute:

NSURL * softURL = [[NSBundle mainBundle] URLForResource: @"hibeep" withExtension: @"caf"];
CFURLRef softSoundURL = (__bridge CFURLRef) softURL;
AudioServicesCreateSystemSoundID(softSoundURL, &_beepSound);
AudioServicesPlaySystemSound (_beepSound);

Yet, when I click on hibeep.caf in the Project Navigator, the sound will play fine.

I have tried this in both the simulator and on an iPad.

Any suggestions?

Thanks

Carl Carlson
  • 500
  • 4
  • 17

3 Answers3

14

TL;DR;

afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v

Long version: I know this is old, but this thread has solved my problem, so here's solution to the problem in the question.

CAF is only a container and you are using the wrong codec for the data held in the container. Quote from apple doc:

Custom alert sounds are played by the iOS system-sound facility, so they must be in one of the following audio data formats:

Linear PCM MA4 (IMA/ADPCM) µLaw aLaw

Here's the proper terminal command when converting WAV to CAF (MA4)

afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
Raimundas Sakalauskas
  • 2,016
  • 21
  • 24
  • I tried everything but push notifications doesn't seem to work with custom sound. Placed CAF in project root && /Library/Sounds/ && xCode -> /Resources It's been 2 days, i'm running out of ideas.. – Becario Senior Apr 29 '17 at 01:04
  • What was the type of original source? I bet it's wrong codec within CAF file as explained in my answer. I as a iOS user, I have also noticed that iOS 9+ likes to mess up notification sounds for all the apps. Reinstalling the app usually helps. Maybe it's the case while developing too? Try deleting the app and redeploying. Apart from these 2 possible solutions, there's nothing much more I can do here :( – Raimundas Sakalauskas May 02 '17 at 15:57
  • Something that is not quite right is the following: in Xcode when I click on the sound files, there is a window in the right showing info related to that file. There is a property "Codecs: ---". Maybe some problem reading codec file? I'm pretty sure it's the right codec. I exported the sound file with Adobe premiere. I tried all accepted codecs but none seemed to like Xcode (never shown). – Becario Senior May 04 '17 at 08:38
  • Did you try running command line command written above? "-d ima4 -f caff" is the important part as this defines the codec to use. – Raimundas Sakalauskas May 08 '17 at 12:01
  • Yesterday I removed and added platform and solved many strange problems. Did not check yet the sound notifications, I will do it today. Could you tell me exacly where to drop the sound files? wich path? is something that i still could not understand clearly. – Becario Senior May 09 '17 at 09:01
  • Impossible, did that conversion but codec still not appears in file properties (Xcode) nor the sound is played. I dropped the sound files under /Resources Don't know what else do. – Becario Senior May 09 '17 at 21:06
3

Try to select your audio file and check if the target is selected xcode

3CC
  • 502
  • 3
  • 11
0

I tried everything but push notifications doesn't seem to work with custom sound. Placed CAF in project root && /Library/Sounds/ && xCode -> /Resources It's been 2 days, i'm running out of ideas.

A strange thing is that when I select a sound file in xCode, there is a window showing properties of that file but codecs: --- doesn't seem to detect. I exported wav files from Adobe Premiere using the codecs Apple asks for. Tried to add those wav files to project but did not work, tried to convert those wav to caf put did not work either... sigh.

Becario Senior
  • 704
  • 10
  • 18