Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading