Html5 audio loop from point a to b

according to spec ,

html5 audio has the following properties:

Loop Indicates whether audio data should be looped. The default value is false.

Start of loop An optional value in seconds, where the loop should begin if the loop attribute is true. Its default value is 0, and it can be useful to set any value between 0 and the length of the buffer.

End of loop An optional value in seconds, where the loop should end if the loop attribute is true. Its default value is 0, and it can be useful to set any value between 0 and the length of the buffer.

I am trying to loop a segment of an audio file, for example, from the second 5 to 8.

I tried many combinations, including using / without using: # t = url param | loopstart / loopend attributes in the DOM | loop attribute

Nothing is working yet (Chrome browser). Perhaps these properties are simply not supported. I am trying to avoid using javascript to set the current sound time.

HTML

<audio controls="" src="http://www.tonycuffe.com/mp3/tail%20toddle.mp3#t=5,8"        loopstart="5" loopend="8" loop></audio>

JAVASCRIPT

var myAudio = document.getElementsByTagName('audio')[0];
myAudio.loopStart = 5;
myAudio.loopEnd = 8;
myAudio.play();

fiddle

I looked: Seamless audio bike in arbitrary position as well as brushless html5 loop

+4
source share
1 answer

Try it out.

Js

function audio () {
if (document.getElementById("music").currentTime >= 8) {document.getElementById("music").currentTime = 5}
}

HTML

<audio id="music" controls ontimeupdate="audio()">
<source src="http://www.tonycuffe.com/mp3/tail%20toddle.mp3" type="audio/mp3">
<audio>
0

Source: https://habr.com/ru/post/1531611/


All Articles