How to get time passed since video started with Yo

2019-09-06 10:02发布

问题:

I want to get time passed (in percent) since video started in using YouTube iframe api.

I've done this so far:

$(".timeInPercent").click(function() {

var playerTotalTime = player.getDuration();
var playerCurrentTime = Math.round(player.getCurrentTime());

var playerTimeDifference = playerTotalTime / playerCurrentTime;
var playerTimePercent = playerTimeDifference * 100;

progress(playerTimePercent, $('#progressBar'));
});

I need this for a custom progression bar I made. I just need to update this progress(playerTimePercent, $('#progressBar')); with time passed in percent.

回答1:

You need playerCurrentTime / playerTotalTime, rather than the other way around. Then multiply by 100 to get percentage, as you're doing.