Reputation: 878
AVAudioPlayer *myExampleSound;
NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"myaudiofile" ofType:@"caf"];
myExampleSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL];
myExampleSound.delegate = self;
[myExampleSound play];
How can I play myExampleSound such that it automatically replay after its end? I am using the above code.
Anyone please help.
Upvotes: 1
Views: 205
Reputation: 1130
The AVAudioPlayerDelegate has got a method
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
which is called after the sound has finished playing. You have to implement this method and then you are able to play your sound again.
Upvotes: 1