playing system sounds in iOS

10,349

If you are using valid soundID and playing the sound on device then the code you have presented should work.

Alternatively you can use the following code to play the custom sound or audio file if it helps you

- (IBAction) playSystemSound: (id) sender {
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"audio" ofType:@"mp3"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
    AudioServicesPlaySystemSound (soundID);
}

Apple has provided sample code for playing sounds you could check that out also.

Share:
10,349
moshikafya
Author by

moshikafya

Updated on June 17, 2022

Comments

  • moshikafya
    moshikafya almost 2 years

    I am trying to understand how to play those sounds in iOS. I did found a few code snippets but they dont play anything when I use it. What am I doing wrong?

    http://iphonedevwiki.net/index.php/AudioServices

    - (IBAction) playSystemSound: (id) sender {
    
        AudioServicesPlaySystemSound (1100);
    }
    
  • moshikafya
    moshikafya about 11 years
    not sure i understand where those sound fit in: iphonedevwiki.net/index.php/AudioServices
  • moshikafya
    moshikafya about 11 years
    the sample code doesnt help since i cant switch tones. it plays only one tone. check it out already.
  • nsgulliver
    nsgulliver about 11 years
    @moshikafya the code you have presented should also work if you have valid soundID and you playing on the Device not on the Simulator, just tested myself