Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

playing system sounds in iOS

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);
}
like image 758
moshikafya Avatar asked Mar 08 '13 22:03

moshikafya


1 Answers

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.

like image 138
nsgulliver Avatar answered Oct 23 '22 18:10

nsgulliver