isarathg
isarathg

Reputation: 878

How can I play a music such that it automatically replay it after its end?

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

Answers (1)

schaechtele
schaechtele

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

Related Questions