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

224
Views
audio duration is undefined

I'm trying to make a simple web app for audiobooks listening. And I'm trying to set a timeline length. I wanted to do it by summing up duration of all chapters. But when I do it this way:

let timelineLength = 0;
let chapterLength;
currentPart.forEach(chapter => {
    chapterLength = chapter.duration;
    timelineLength += chapterLength;
});

chapterLength is NaN so timelineLength is also NaN. When I type chapters[index].duration in chrome console after the app's been loaded it works just fine. I have no idea what I'm doing wrong.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

This worked:

currentPart.forEach(chapter => {
    chapter.addEventListener('loadeddata', () => {
    chapterLength = chapter.duration;
    timelineLength += chapterLength;
    });
});

I had to wait for the data to load.

about 4 years ago · Santiago Gelvez 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!