I need to play some system sound when users click button in my application which is running on iPad. How to implement it in iOS?
Disable the keyboard sounds on iPhone or iPadOpen the Settings app. Tap Sounds & Haptics. Scroll down to Keyboard Clicks and turn it off.
If you want to play a short sound (shorter than 30 sec), you can do it easily like this:
Note: You'll have to add AudioToolbox framework and import it (#import <AudioToolbox/AudioToolbox.h>
)
SystemSoundID mySSID;
NSString *path = [[NSBundle mainBundle] pathForResource:@"beep" ofType:@"wav"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: path], &mySSID);
AudioServicesPlaySystemSound(mySSID);
Also note that the file can be:
You should use AVAudioPlayer.
There's a great tutorial here on using AVAudioPlayer to play sounds. A very simple example of it's use:
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3",dataPath];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With