我寫一個移動web的頁面,里面有一個播放器,總時長的顯示用的是vedio的duration屬性,用函數(shù)將秒換算成00:00的格式,但是在測試的時候部分手機顯示時長,部分手機顯示00:01,部分手機顯示00:NaN,當前時間用的是vedio.currentTime,也是用那個函數(shù)換算的,就一直顯示正常。測試了四五部手機,蘋果下顯示正常,安卓里UC下部分顯示不正常,這是為什么?秒數(shù)換算代碼:function formatSeconds(timer){? ? ? ? var theTime = parseInt(timer);// 秒? ? ? ? var theTime1 = 0;// 分 var theTimer=0? ? ? ? if(theTime > 60) {? ? ? ? ? ?theTime1 = parseInt(theTime/60);? ? ? ? ? ?theTime = parseInt(theTime%60); ? if(theTime1<10){theTime1="0"+theTime1;} ? if(theTime<10){theTime="0"+theTime;} ? theTimer=theTime1+":"+theTime; }else{ if(theTime<10){theTime="0"+theTime;} theTimer="00"+":"+theTime; } return theTimer; }插入當前時長和總時長的代碼:var starttime=document.getElementById("starttime"); var timer=setInterval(function(){ starttime.innerHTML=formatSeconds(myVedio.currentTime); },500); var stoptime=document.getElementById("stoptime");? ? ? ? stoptime.innerHTML=formatSeconds(myVedio.duration);
部分手機上duration不起作用
為了我的天府之國
2016-08-19 12:09:46