You cannot stop the sound that is played through " AudioServicesPlaySystemSound ", but you can use " AVAudioPlayer " instead.
Keep a link to your â AVAudioPlayer â in your object, and then you can call â stop â when you need to stop it.
Play
#import <AudioToolbox/AudioToolbox.h> #import <AVFoundation/AVAudioPlayer.h> AVAudioPlayer *player; // ... NSString *path; NSError *error; path = [[NSBundle mainBundle] pathForResource:@"albina" ofType:@"m4a"]; if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error]; player.volume = 0.5f; [player prepareToPlay]; [player setNumberOfLoops:0]; [player play]; }
Stop
if (player != nil) { if (player.isPlaying == YES) [player stop]; }
source share