언어 설정

Menu
Sites
Language
audio play - second time does not start from beginning

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();
}

 

Responses

4 댓글
mekabe remain

I'd appreciate any replies...

thx.

 

Dominik Koleda

What is the source of you file? is it cached, loaded from localStorage?

http://stackoverflow.com/questions/9563887/setting-html5-audio-position

mekabe remain

hi,

I load the file from local storage just before I play it in the code.

so, what is it that I am doing wrong ?

 

mekabe remain

the command I use in the onload function is:

 audio2 = document.getElementById("audio2");

and it is defined in the index.html as:

 <audio id="audio2" preload="auto" src="audio/audio2.wav"></audio>

 

so how can I force it to start from first second each time ?