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

146
Views
getting NaN when asking for video duration

Can anyone help me understand why console.log(this.getPlayerDuration()) inside of setAttendancePromptTimeLimit() is returning NaN?

// video-player.js    

const videoP = document.querySelector('#in-course-player')

class videoPlyer {
  constructor(videoElem){
        this.vidPlayer = videoElem
    }
  play =  function(cb){
    arguments.length ? cb : console.log('play')
  }
    
  addListener = (elem, event, cb) => {
        elem.addEventListener(event, cb)
    }

  getPlayerCurrentTime = () => this.vidPlayer.currentTime

  getPlayerDuration = () => this.vidPlayer.duration

  showVideoDuration = function(cb){
    arguments.length ? cb : this.addListener(this.vidPlayer, 'loadedmetadata', () => 
        console.log(this.getPlayerDuration()))
    }


  setAttendancePromptTimeLimit = cb => {

    // returns NAN
    console.log(this.getPlayerDuration())
  }

  init = () => {
    //returns 16.1
    this.showVideoDuration()  
    //returns NAN 
    this.setAttendancePromptTimeLimit()    
  }
 }

 const coursePlayer = new videoPlyer(videoP)
 coursePlayer.init()
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

[...] If no media data is available, the value NaN is returned. [...]
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/duration

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!