2016-05-19 9 views
1

ビデオcurrentTimedurationを別の形式で表示したいとします。00:25/00:30のようにビデオの現在時間と継続時間を表示するにはどうすればよいですか?

それは今それを表示する方法は次のとおりです。

0:9 /午後12時33分

私はそれがこのようにそれを表示したい:

午後12時09分/ 00:33

またはビデオ期間が1分を超える場合

3:10/12:27

現在のコード私が今持っている

video.on('timeupdate', function() { 

     // Set to minute and seconds 
     var time = video[0].currentTime; 
     var minutes = Math.floor(time/60); 
     var seconds = Math.floor(time); 

     // Set the current play value 
     currentTimer.text(minutes + ':' + seconds); 
    }); 

    video.on('loadedmetadata', function() { 

     // Set to minute and seconds 
     var time = video[0].duration; 
     var minutes = Math.floor(time/60); 
     var seconds = Math.floor(time); 

     // Set the video duration 
     durationTimer.text(minutes + ':' + seconds); 
    }); 

答えて

2

このコードは、あなたが欲しいものを行う必要があります。

function format(s) { 
 
    m = Math.floor(s/60); 
 
    m = (m >= 10) ? m : "0" + m; 
 
    s = Math.floor(s % 60); 
 
    s = (s >= 10) ? s : "0" + s; 
 
    return m + ":" + s; 
 
    } 
 

 
alert(format(120)); 
 
alert(format(250)); 
 
alert(format(31));

+0

ありがとうございます。それは私が望むことをする。私は自分自身でこのオーナを思いつくことができたらいいと思う:P – Red

関連する問題