在我的项目中,我有一个表视图.. 有附件按钮。
所以当我点击按钮时,声音会播放......
如果声音已经在播放,那么它将停止......
这是我的代码....
-(void)playAudio:(int)index
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:
[NSString stringWithFormat:@"%@",soundListArray[index]] ofType:@"mp3"];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundFilePath] error:nil];
audioPlayer.numberOfLoops = 0;
audioPlayer.delegate = self;
[audioPlayer play];
}
当播放器完成时,我也会停止它。
我已经搜索了很多......
我也在每次停止后都应用了这个,但它不会影响......
audioPlayer = nil;
audioPlayer.delegate = nil;