Home > front end >  How to change current time in audio playback?
How to change current time in audio playback?

Time:05-15

I am trying to play an audio file with an offset of 10 seconds into the recording:

const audio = new Audio('audio.mp3');
audio.currentTime = 10
console.log('currentTime: '   audio.currentTime)
console.log('duration: '   audio.duration)
audio.play();

The output:

curretTime: 10
duration: NaN

Now this code will play the audio - but it will start from the beginning. How do I start the playback 10 seconds into the audio? Also, why is the duration printing as "NaN" ?

CodePudding user response:

you are missing "n" from currentTime. should be audio.currentTime = 10;

  • Related