admin管理员组

文章数量:1302939

Check out this demo page: .htm

Click the Play Sound button twice, in quick succession. Because it hasn't yet finished playing the first time around by the time you hit the button again, nothing happens, and the click appears to be ignored. How could one re-code it so that it would stop the current playback, reset the playback position to the very beginning of the sound, and restart it upon each click of the Play Sound button?

Check out this demo page: http://www.phon.ucl.ac.uk/home/mark/audio/play10.htm

Click the Play Sound button twice, in quick succession. Because it hasn't yet finished playing the first time around by the time you hit the button again, nothing happens, and the click appears to be ignored. How could one re-code it so that it would stop the current playback, reset the playback position to the very beginning of the sound, and restart it upon each click of the Play Sound button?

Share Improve this question asked Sep 7, 2012 at 13:47 wwaawawwwaawaw 7,13710 gold badges35 silver badges42 bronze badges 2
  • NOTE: I only ask because it seems the docs are broken: developer.mozilla/en-US/docs/XPCOM_Interface_Reference/… – wwaawaw Commented Sep 7, 2012 at 13:51
  • 1 Implement your own play controls? "Seeking through media" developer.mozilla/en-US/docs/… – Alex K. Commented Sep 7, 2012 at 13:53
Add a ment  | 

2 Answers 2

Reset to default 9

You can change the it to something like this

var thissound=document.getElementById('audioElemID');
thissound.currentTime=0;
thissound.play();
thissound=document.getElementById(soundobj);
thissound.currentTime = 0;

本文标签: javascriptHow can one reset an HTMLAudioElement39s current playback position to 0Stack Overflow