Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop sound in iPhone

SystemSoundID soundID;
NSString *path = [[NSBundle mainBundle] pathForResource:@"static" ofType:@"caf"]; 
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);

I have implemented above code in my application.

It works perfectly, but the problem is I don't know how to stop it.

i.e Sound is of 10 sec.

Before 10 sec. if user taps button, sound should be stopped? How can I do so?

like image 265
Sagar Kothari Avatar asked Feb 28 '23 05:02

Sagar Kothari


2 Answers

Try AudioServicesDisposeSystemSoundID, it stops sounds immediately. You'll need to recreate the sound if you intend to use it again.

like image 59
mikestew Avatar answered Mar 12 '23 02:03

mikestew


Use the following instruction for disposes of a system sound object and associated resources:

AudioServicesDisposeSystemSoundID(soundID);
like image 34
Alessandro Pirovano Avatar answered Mar 12 '23 02:03

Alessandro Pirovano