views:

31

answers:

1

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.

A: 

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.

schaechtele