Does anyone knows how to change current time of song correctly in JavaScript?

pavelkeyzik

Pavel Keyzik

Posted on April 5, 2021

Does anyone knows how to change current time of song correctly in JavaScript?

Hi, everyone! I'm trying to make custom audio player in JavaScript and when I try to change current time of song then on some songs it sets currentTime to 0. I tried to find solution and it seems like bug in Chrome or something. Maybe someone know how to fix it?

My code is so simple:

const audio = new Audio();

function playSong(songURL) {
  audio.src = songURL;
  audio.play();
}

function seek(value) {
  audio.currentTime = value;
}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
pavelkeyzik
Pavel Keyzik

Posted on April 5, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related