我正在使用以下代码播放声音
NSString *laughSoundPath = [[NSBundle mainBundle]pathForResource:@"laugh" ofType:@"wav"];
NSURL *laughURL = [[NSURL alloc]initFileURLWithPath:laughSoundPath];
laughTone = [[AVAudioPlayer alloc]initWithContentsOfURL:laughURL error:nil];
[laughTone prepareToPlay];
[laughTone setDelegate:self];
[laughURL release];
-(IBAction)play
{
[laughTone play];
}
我正在使用以下行停止声音
-(IBAction)stop
{
[laughTone stop];
}
问题是..当我再次播放声音时,它从停止的位置开始..我的意思是说它的工作是暂停..帮帮我
最佳答案
尝试重置时间然后播放,再次将代码放入您的play方法中:
laughTone.currentTime = 0;
[laughTone play];
关于iphone - 如何在按下按钮时停止声音,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9389868/