我正在使用以下代码播放声音
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];
}
问题是..当我再次播放声音时,它从停止的位置开始...我的意思是说它的工作暂停..帮帮我
答案 0 :(得分:8)
-(IBAction)stop
{
[laughTone stop];
[laughTone playAtTime:0];
}
答案 1 :(得分:4)
尝试重置时间然后再播放,再次将代码放入播放方法中:
laughTone.currentTime = 0;
[laughTone play];
答案 2 :(得分:1)
试试这个:
NSString *Str = [[NSBundle mainBundle] pathForResource:@"Ahhh" ofType:@"wav"];
AVAudioPlayer *audioSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:ahhhPath] error:NULL];
-(IBAction)btnStopsound(id)sender
{
[audioSound stop];
audioSound.currentTime=0;
[audioSound play]; //restart the player
}