2010-02-04 124 views
1
-(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? 
} 

我能得到的音频播放罚款,但如何使一个按钮,停止音频?在iphone上播放mp3 sdk?

回答

4

.hinterface块将这个。

AVAudioPlayer* audioPlayer; 

您将需要检查一个实例并释放它。

+0

不要忘记@syntheize它在.M和dealloc的它如上所述。 – CW0007007 2011-12-13 14:21:22

0

您已经声明AVAudioPlayer* audioPlayer作为方法局部变量。将该变量的范围更改为类级别。按照丹尼尔A.白色的建议