The easiest way is to replay the player when it reaches the end:
-(void)startPlayer { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"]]; NSError *error; player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; player.delegate = self; if (error) { NSLog(@"Error in audioPlayer: %@", [error localizedDescription]); } else { [aPlayer play]; } } - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)aPlayer successfully:(BOOL)flag { aPlayer.currentTime = 0; [aPlayer play]; }
Call [self startPlayer]; once and it will work forever!
rdurand Mar 14 '14 at 13:16 2014-03-14 13:16
source share