IOS: stop audio when I return in a view

386 views Asked by At

When I exit from a view I start a jingle and when i return in this view I want to stop this jingle (wma)

when I exit in IbAction I have this code:

NSString *path = [NSString stringWithFormat:@"%@/%@",
                  [[NSBundle mainBundle] resourcePath],
                  @"file.wav"];

NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);

but when I return in the view I try to write in viewWillAppear

AudioServicesRemoveSystemSoundCompletion(soundID);
AudioServicesDisposeSystemSoundID(soundID);

but it don't work, can you help me?

1

There are 1 answers

0
Pavel Oganesyan On BEST ANSWER

viewWillAppear: not will be called in some cases. You can use notification center ([NSNotificationCenter defaultCenter]) or delegate to let your view now when to stop music. There are some methods like postNotification: and addObserver:, check them.