sagarkothari
sagarkothari

Reputation: 24810

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?

Upvotes: 4

Views: 2845

Answers (3)

Ralph David Abernathy
Ralph David Abernathy

Reputation: 5508

I would suggest using the AVFoundation framework. Here is an amazing tutorial on how to play, pause, and stop sound using the AVAudioPlayer.

Upvotes: 0

Alessandro Pirovano
Alessandro Pirovano

Reputation: 2541

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

AudioServicesDisposeSystemSoundID(soundID);

Upvotes: 4

mikestew
mikestew

Reputation: 857

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

Upvotes: 4

Related Questions