简体   繁体   English

从a点到b点的html5音频循环

[英]html5 audio loop from point a to b

according to the spec , 根据规范

html5 audio has the following properties: html5 audio具有以下属性:

loop Indicates if the audio data should play in a loop. loop指示音频数据是否应在循环中播放。 The default value is false. 默认值为false。

loopStart An optional value in seconds where looping should begin if the loop attribute is true. loopStart一个可选的值,以秒为单位,如果loop属性为true,则应该开始循环。 Its default value is 0, and it may usefully be set to any value between 0 and the duration of the buffer. 它的默认值是0,它可以有用地设置为0和缓冲区持续时间之间的任何值。

loopEnd An optional value in seconds where looping should end if the loop attribute is true. loopEnd一个可选值,以秒为单位,如果loop属性为true,则循环应该结束。 Its default value is 0, and it may usefully be set to any value between 0 and the duration of the buffer. 它的默认值是0,它可以有用地设置为0和缓冲区持续时间之间的任何值。

I am trying to loop a segment of an audio file, from second 5 to 8 for example. 我试图循环一段音频文件,例如从第二个5到8。

I have tried many combinations, including with/without using: #t= url param | 我尝试了很多种组合,包括使用/不使用:#t = url param | loopstart/loopend attributes in the DOM | DOM中的loopstart / loopend属性 loop attribute 循环属性

Nothing works so far (chrome browser). 到目前为止没有任何工作(Chrome浏览器)。 Perhaps theese properties are simply not supported yet. 也许还没有支持theese属性。 I am trying to avoid using javascript to set the currenttime of the audio. 我试图避免使用javascript来设置音频的当前时间。

HTML HTML

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

JAVASCRIPT JAVASCRIPT

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

fiddle 小提琴

I have looked at: Seamless audio loop to an arbitrary position and gapless looping audio html5 我看过: 无缝音频循环到任意位置无间隙循环音频html5

Try with this. 试试这个。

JS JS

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

HTML HTML

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM