2012-02-22 132 views
2

停止声音我使用下面的代码来播放声音如何在按下一个按钮

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]; 
    } 

问题是..当我再次播放声音,它从停止的地方开始..我的意思是说它的工作暂停..帮我出去

回答

4

尝试重置时间,然后再玩,再次把你的播放方法中的代码:

laughTone.currentTime = 0; 
[laughTone play]; 
+0

都能跟得上它不工作 – Shreedhar 2012-02-22 06:14:34

+0

@Shreedhar:好的编辑试试吧。 – Dair 2012-02-22 06:20:45

8
-(IBAction)stop 
{ 
    [laughTone stop]; 
    [laughTone playAtTime:0]; 
} 
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 

} 
相关问题