html5 显示音频 currentTime [英] html5 display audio currentTime

查看:42
本文介绍了html5 显示音频 currentTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示 html 5 音频元素的当前时间和该元素的持续时间.我一直在浏览互联网,但找不到一个功能脚本,它允许我显示音频文件的长度和当前的时间,例如1:35/3:20.

I would like to display the current time of of an html 5 audio element and the duration of that element. I've been looking over the internet but can't find a functional script which allows me to display how long the audio files is and what the time currently is e.g. 1:35 / 3:20.

有人有任何想法:)?

推荐答案

举个例子:

<audio id="track" src="http://upload.wikimedia.org/wikipedia/commons/a/a9/Tromboon-sample.ogg"
       ontimeupdate="document.getElementById('tracktime').innerHTML = Math.floor(this.currentTime) + ' / ' + Math.floor(this.duration);">
    <p>Your browser does not support the audio element</p>
</audio>
<span id="tracktime">0 / 0</span>
<button onclick="document.getElementById('track').play();">Play</button>

这应该适用于 Firefox 和 Chrome,对于其他浏览器,您可能需要添加替代编码.

This should work in Firefox and Chrome, for other browsers you'll probably need to add alternative encodings.

这篇关于html5 显示音频 currentTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆