Reputation: 271
I am Using Following code to play sound
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];
}
i am Using following line to stop sound
-(IBAction)stop
{
[laughTone stop];
}
Problem is.. When i play sound again, its starting from the point where it was stopped.. i mean to say its working as pause.. help me out
Upvotes: 2
Views: 253
Reputation: 925
Try this:
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
}
Upvotes: 1
Reputation: 16240
Try resetting the time and then playing, again put the code in your play method:
laughTone.currentTime = 0;
[laughTone play];
Upvotes: 4
Reputation: 1408
-(IBAction)stop
{
[laughTone stop];
[laughTone playAtTime:0];
}
Upvotes: 8