HTML:
<audio src="samples/brutaldeathmetal.mp3" id="audio" controls>
JavaScript:
var aud = document.getElementById('audio');
aud.addEventListener("ended", function(){
this.currentTime = 0;
this.pause();
});
this.currentTime = 0;
this.pause();
});
What this does is it sets the playtime back to zero seconds when the audio clip ends.
Among the many javascript functions and properties of this tag you can use .play(), .pause(), .ended, .paused, and .duration to manipulate it. And you can even set the .currentTime property to a number within the range of your clip's playback duration (in seconds) to start midway through the clip if you wanted.
Thank you!!
ReplyDeleteThank you!
ReplyDeleteGreat. It just works!
ReplyDeletedon't work for me my song just stop where i said it to but it don't reset so i can replay it from the begining
ReplyDeleteSo you can definitely change the durationTime to any valid number? Then you should be able to set it to 0 and then immediately pause it using the .pause() method to keep it from playing back again.
Delete