audio play – second time does not start from beginning

audio play – second time does not start from beginning

BY 20 Jul 2014 Web Application Development

I am trying to play audio (wav file) using the audioid.play() method.

It works fine when the action is triggered first time after the app is loaded.

But for the second time, it does not start from beginning of the audio file. It always starts from middle of the file after the first time.

I think “audioid.currentTime = 0;” should make the start point 0 but it does not work.

What is it that I am doing wrong  below?

 

 function stopaudio2 () {
    audio2.currentTime = 0;
	audio2.removeEventListener('ended', stopaudio2, false);
}


function onClick() {
	audio2.currentTime = 0;
	audio2.addEventListener('ended', stopaudio2, false);
    audio2.play();
}

 

Written by