PDA

View Full Version : How To Loop With AVAudioPlayer




mandude
Dec 14, 2009, 08:46 PM
hey if anyone wants to help i'd really appreciate it. So i got this beautiful song that starts playing on the viewDidLoad method. now i just need to to play over and over and over again.... thanks.. here's the code:


h. file:
@implementation....... {
NSString *playerPath;
AVAudioPlayer *player;
}
@propoperty (nonatomic, retain) NSString *playerPath;
@propoperty (nonatomic, retain) AVAudioPlayer *player;
@end



m. file:

-(void)viewDidLoad {

playerPath = [[NSBundle mainBundle] pathForResource:@"Vengeance" ofType:@"mp3"];

player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:playerPath] error:NULL];

[player play];
}



kainjow
Dec 14, 2009, 10:04 PM
Try this
player.numberOfLoops = -1;
From the docs, a negative number indicates it loops forever.