How to change current time in audio playback?

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);

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" ?

>Solution :

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

Leave a Reply