我正在尝试以00:00的格式在我的网站上显示我的视频的当前时间和持续时间。但我不明白......
myVideo.on('timeupdate', function() {
$('.current').text(myVideo[0].currentTime);
$('.duration').text(myVideo[0].duration);
});
我找到了这个功能,但如果我老实说,我完全不知道如何将它实现到currentTime和duration属性......
var formatTime = function(seconds) {
minutes = Math.floor(seconds / 60);
minutes = (minutes >= 10) ? minutes : "0" + minutes;
seconds = Math.floor(seconds % 60);
seconds = (seconds >= 10) ? seconds : "0" + seconds;
return minutes + ":" + seconds;
}
http://gyazo.com/351cafacbeacddbeda7f31869269376e
EDITED
好的......我只需要这样做......希望这有帮助...哈哈
var formatTime = function(seconds) {
minutes = Math.floor(seconds / 60);
minutes = (minutes >= 10) ? minutes : "0" + minutes;
seconds = Math.floor(seconds % 60);
seconds = (seconds >= 10) ? seconds : "0" + seconds;
return minutes + ":" + seconds;
}
myVideo.on('timeupdate', function() {
$('.current').text(formatTime(myVideo[0].currentTime));
$('.duration').text(formatTime(myVideo[0].duration));
});