sorinu26
sorinu26

Reputation: 1172

How to get time passed since video started with YouTube iframe api?

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.

Upvotes: 0

Views: 484

Answers (1)

SataGNUk
SataGNUk

Reputation: 96

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

Upvotes: 1

Related Questions