user409333
user409333

Reputation:

repeat playing automatically

I use below code for play sound

NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"01" ofType:@"mp3"]]; 
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[audioPlayer play];

I want to repeat this sound file automatically when it's finish How ?

Upvotes: 8

Views: 4929

Answers (2)

Harshad
Harshad

Reputation: 2361

player.numberOfLoops = -1;
 [player prepareToPlay];

    [player play];

Upvotes: 0

Vladimir
Vladimir

Reputation: 170849

audioPlayer.numberOfLoops = someNumber;

or for "infinite" number of loops:

audioPlayer.numberOfLoops = -1;

Upvotes: 18

Related Questions