简体   繁体   中英

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?

Put this in your interface block in the .h .

AVAudioPlayer* audioPlayer;

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

You have declared AVAudioPlayer* audioPlayer as a method local variable. Change the scope of that variable to class level. Follow Daniel A. White's suggestion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM