How To Loop With AVAudioPlayer

Discussion in 'iPhone/iPad Programming' started by mandude, Dec 14, 2009.

  1. macrumors member

    Joined:
    Nov 19, 2009
    #1
    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:mad:"Vengeance" ofType:mad:"mp3"];

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

    [player play];
    }
     
  2. Moderator emeritus

    kainjow

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

Share This Page