简体   繁体   中英

How to play a song from a random time in javascript ? (Ex:from the 5th second)

I'm trying to play a song from a specific time code. This, document.getElementById('rock').play(); play the song from the beginning. Is there a way to choose the beginnning time? Thank you.

document.getElementById('rock').play();

The HTMLMediaElement.currentTime property gives the current playback time in seconds. Setting this value seeks the media to the new time.

HTMLMediaElement.currentTime

let song = document.getElementById('rock');
song.currentTime = 35;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM