How To Loop With AVAudioPlayer

Discussion in 'iOS Programming' started by mandude, Dec 14, 2009.

  1. mandude macrumors member

    Nov 19, 2009
    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;

    m. file:

    -(void)viewDidLoad {

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

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

    [player play];
  2. kainjow Moderator emeritus


    Jun 15, 2000
    Try this
    player.numberOfLoops = -1;
    From the docs, a negative number indicates it loops forever.

Share This Page