Audio currentTime 属性
将时间位置设置为 1 秒:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> </head> <body> <audio id="myAudio" controls> <source src="/examples/horse.ogg" type="audio/ogg"> <source src="/examples/horse.mp3" type="audio/mpeg"> 您的浏览器不支持 audio 元素。 </audio><br> <button onclick="getCurTime()" type="button">获取当前时间位置</button> <button onclick="setCurTime()" type="button">设置时间点为 1 秒 </button> <script> var x = document.getElementById("myAudio"); function getCurTime() { alert(x.currentTime); } function setCurTime() { x.currentTime = 1; } </script> </body> </html>
定义和用法
urrentTime 属性设置或返回音频播放的当前位置(以秒计)
当设置该属性时,播放会跳跃到指定的位置。
浏览器支持
所有主流浏览器都支持 currentTime 属性。
注意: Internet Explorer 8 或更早的浏览器不支持该属性。
语法
返回 currentTime 属性:
audioObject.currentTime
设置 currentTime 属性:
audioObject.currentTime=seconds
属性值
值 | 描述 |
---|---|
seconds | 指示音频播放的当前位置(以秒计)。 |
技术细节
返回值: | 一个数字,表示当前的播放时间(以秒计)。 |
---|
