获取音乐文件的播放时间及当前进度
程序员文章站
2022-03-12 22:14:20
首先将以下代码加入网页中: function currentposi...
首先将以下代码加入网页中:
<span id="text"></span>
function currentposition() {
if (document.winplayer.playstate != 2) return;
cpos.style.pixelleft = tobarposition(document.winplayer.currentposition);
text.innerhtml = toposition(winplayer.currentposition) + "/" + toposition(winplayer.duration) ;
}
//保留两个小数
function format2(str)
{
str=math.round(parsefloat(str)*100)/100
return str
}
function toposition(pos)
{
var levelt;
levelt = ((cmaxx - cminx) * pos) / document.winplayer.duration;
levelt =(parseint(levelt) + cminx)/60;
levelt =format2(levelt);
return levelt;
}
//以上是时间转换函数,如5.34,这后面的0.34相当于60*0.34=20秒,改进后的函数如下:
function toposition(pos)
{
var levelt;
levelt = ((cmaxx - cminx) * pos) / document.winplayer.duration;
levelt =(parseint(levelt) + cminx)/60;
levelt=parseint(levelt) + ":" + parseint((format2(levelt)-parseint(levelt))*60);
return levelt;
}
<span id="text"></span>
function currentposition() {
if (document.winplayer.playstate != 2) return;
cpos.style.pixelleft = tobarposition(document.winplayer.currentposition);
text.innerhtml = toposition(winplayer.currentposition) + "/" + toposition(winplayer.duration) ;
}
//保留两个小数
function format2(str)
{
str=math.round(parsefloat(str)*100)/100
return str
}
function toposition(pos)
{
var levelt;
levelt = ((cmaxx - cminx) * pos) / document.winplayer.duration;
levelt =(parseint(levelt) + cminx)/60;
levelt =format2(levelt);
return levelt;
}
//以上是时间转换函数,如5.34,这后面的0.34相当于60*0.34=20秒,改进后的函数如下:
function toposition(pos)
{
var levelt;
levelt = ((cmaxx - cminx) * pos) / document.winplayer.duration;
levelt =(parseint(levelt) + cminx)/60;
levelt=parseint(levelt) + ":" + parseint((format2(levelt)-parseint(levelt))*60);
return levelt;
}
上一篇: 用纯CSS3实现网页中常见的小箭头