i’m new in Objective C, i’m developing an app that play sound on touch event of an uibutton.
When i touch the button, it change is image and audio starts to playing. When audio is finish to play, i want to put the original image of uibutton. How can i do that? How can i catch the event of the audio that is finish?
i’m using that code:
- (SystemSoundID) createSoundID: (NSString*)name
{
NSString *path = [NSString stringWithFormat: @"%@/%@",
[[NSBundle mainBundle] resourcePath], name];
NSURL* filePath = [NSURL fileURLWithPath: path isDirectory: NO];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
return soundID;
}
In
viewDidLoad
i call
freq = [self createSoundID: @"freq.wav"];
and in function that is called on button’s touch i use:
AudioServicesPlaySystemSound(freq);
How can i do? Thank you!
Not sure if it’s possible with the AudioService API but you can use
AVAudioPlayerinstead and assign a delegate that implements theAVAudioPlayerDelegateprotocol and does something whenaudioPlayerDidFinishPlaying:successfully:is called.Remember to add the
AVFoundationframework.Example:
In your interface definition:
…
…
In your implementation:
…
…
…
…