Search code examples
iphonesdkaudiomp3avaudioplayer

Playing mp3 on iphone sdk?


-(IBAction)musiconButtonClicked:(id)sender{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"NextRevIt" ofType:@"mp3"];
    AVAudioPlayer* audioPlayer = [[AVAudioPlayer alloc ] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [audioPlayer play];
}


-(IBAction)musicoffButtonClicked:(id)sender{
    [audioPlayer stop]; <----says this is undeclared?
}

I can get the audio to play fine, but how do i make a button that stops the audio?


Solution

  • Put this in your interface block in the .h.

    AVAudioPlayer* audioPlayer;
    

    You will need to check for an instance and release it as well.