moshikafya
moshikafya

Reputation: 3320

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);
}

Upvotes: 6

Views: 10443

Answers (1)

nsgulliver
nsgulliver

Reputation: 12671

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.

Upvotes: 5

Related Questions