Categories
JavaScript Answers

How to set HTML5 audio position with JavaScript?

Spread the love

Sometimes, we want to set HTML5 audio position with JavaScript.

In this article, we’ll look at how to set HTML5 audio position with JavaScript.

How to set HTML5 audio position with JavaScript?

To set HTML5 audio position with JavaScript, we can set the currentTime property.

For instance, we write

const element = document.getElementById("audioPlayer");
element.play();
element.currentTime = 226;

to get the audio element with getElementById.

And then we set the currentTime property to the position of the audio in seconds.

Conclusion

To set HTML5 audio position with JavaScript, we can set the currentTime property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *