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

查看:227
本文介绍了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.

任何一个有任何想法:)

Any one got any ideas :)?

推荐答案

下面是一个例子:

<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天全站免登陆