¿Cómo puedo reproducir un sonido con IBAction
presionando UIbutton
una vez y pausándolo presionando el botón nuevamente usando AVAudioPlayer
? También quiero cambiar el estado de ese UIButton
cuando se reproduce el sonido y cuando no lo está.Reproducir/Pausa con el mismo botón [AVAudioPlayer]
Aquí está mi código:
- (IBAction)Beat
{
if ([Media2 isPlaying])
{
[Media2 pause];
[Button17 setSelected:NO];
}
else
{
Path = [[NSBundle mainBundle] pathForResource:@"Beat" ofType:@"mp3"];
AVAudioPlayer *Media2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:Path] error:NULL];
[Media2 setDelegate:self];
[Media2 play];
[Button17 setSelected:YES];
}
}