2

I'm trying to build a custom keyboard for iOS 8 that a custom play sound when a key is pressed. I'm using a AVAudioPlayer and small mp3-files.

This works fine in the simulator, but on a real device I don't get any sounds.

RequestOpenAccess is enabled.

Please not that I'm not trying to play the default keyboard click sound, but a custom sound. Most existing questions seems to be about the default system sound.

edit: I've also tried using .caf and .aiff files and loading and playing them with SystemSoundID.

Johan Nordberg
  • 3,621
  • 4
  • 33
  • 58
  • Do you have any error or warnning in the console when you try to play the sound? – LastMove Jan 14 '15 at 11:14
  • No, nothing. It's just silent. It's like the sound loads, but can't play because the app freeze for about the same time as the length of the audio. – Johan Nordberg Jan 14 '15 at 11:34
  • If the app freeze maybe you can use Xcode Instruments like Time profiler to saw in which method the app freeze. – LastMove Jan 14 '15 at 11:47
  • we need a little bit more information here - do you maybe have some code? – stefreak Jan 14 '15 at 12:12
  • Here's a link to my small test project on BitBucket. It just tries to play the same sound for all the buttons. https://bitbucket.org/tfsjohan/phonetickeyboard/src – Johan Nordberg Jan 19 '15 at 09:08

2 Answers2

2

This snippet plays custom sound in my keyboard project.

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"your_custom_sound" 
                                                      ofType:@"mp3"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);

Cited from:

How to play tock sound when tapping custom keyboard buttons

Community
  • 1
  • 1
merge
  • 403
  • 5
  • 10
  • There is no problem with performance. By the way, the sound file size is 8KB in my project. – merge Jan 26 '15 at 12:11
0

I'm positive this is not your case but it often happens that the sound on the device is turned off. I made the mistake searching for an hour why sound didn't work. If it could only be that, it would be a quick fix ;)

Tokuriku
  • 1,332
  • 13
  • 22
  • Wish was that simple. :) I even made sure I have the default click sound on for the built in keyboard and can here that just fine. – Johan Nordberg Jan 19 '15 at 21:40