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

210
Views
Update position of seeker (i.e html input type range) while an audio is playing

I want the range slider automatically change while audio play.

<input type="range" name="seek" id="seeker" min="0" max="100" value="0" > 

let music = new Audio('https://www.computerhope.com/jargon/m/example.mp3');
music.play();
<input type="range" name="seek" id="seeker" min="0" max="100" value="0" > 

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

0

Since new Audio() actually creates a new <audio> element (it is just not injected into your DOM), you can still listen to DOM events. For your use-case, you will want to listen to the timeupdate event, and get the progress of the play through by dividing the total duration of the audio clip with currentTime:

music.addEventListener('timeupdate', () => {
  const percent = music.currentTime / music.duration * 100;
  seeker.value = percent;
});

However, if you want the users to use the <input> element to seek through the audio clip (I assumed that since you named your element #seeker), then you will also need to listen to the input event from the element. You can use simple math to calculate what currentTime value you have to set on the audio element.

Here is a proof-of-concept example. I have ensured that play() is only triggered by a button click, since most browsers do not autoplay audio files today.

const music = new Audio('https://www.computerhope.com/jargon/m/example.mp3');
const seeker = document.querySelector('#seeker');

music.addEventListener('timeupdate', () => {
  const percent = music.currentTime / music.duration * 100;
  seeker.value = percent;
});

// Allow seeking
seeker.addEventListener('input', (e) => {
  music.currentTime = e.target.value / 100 * music.duration;
});

document.querySelector('#play-button').addEventListener('click', () => {
  music.play();
});
<input type="range" name="seek" id="seeker" min="0" max="100" value="0">
<button type="button" id="play-button">Play</button>

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!