Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
TypeError: player.currentTime is not a function error in videojs

I have a working player in videojs and I'm trying to get the current position of the progress bar, In the documentation provided by videojs they use myPlayer.currentTime() to get and set the time in seconds but it is not working for me.

My code:

var tag = document.createElement("script");

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
//    after the API code downloads.
var player;

function onYouTubeIframeAPIReady() {
  player = new YT.Player("player", {
    host: "https://www.youtube.com",
    /* no need to specify player 
    size here since it is handled 
    by the player-size div */
    videoId: video_id,
    playerVars: {
      enablejsapi: 1,
      playsinline: 1,
      start: 0,
      disablekb: 0
    },
    events: {
      onReady: onPlayerReady,
      onStateChange: onPlayerStateChange
    }
  });
}

function onPlayerStateChange(event) {
  console.log("player state: " + player.getPlayerState());

  if (player.getPlayerState() == 2){
    console.log("STOPED AT:" + player.currentTime()); // This is where i want to log the current time of the playing video
  }
}

function updateVideoId(video_id) {
  player.loadVideoById(video_id, -1);
}

function stopVideo() {
  player.stopVideo();
}

function onPlayerReady(event) {
  document.getElementById("play").addEventListener("click", function() {
    player.playVideo();
  });
}

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The code above is YouTube's API, not Video.js.

If you want to play a YouTube video in Video.js and use Video.js's API, you need to use the YouTube tech for Video.js

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!