简体   繁体   English

如何在javascript中从随机时间播放歌曲? (例如:从第 5 秒开始)

[英]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();这个,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(); document.getElementById('rock').play();

The HTMLMediaElement.currentTime property gives the current playback time in seconds. HTMLMediaElement.currentTime 属性以秒为单位给出当前播放时间。 Setting this value seeks the media to the new time.设置此值会将媒体搜索到新时间。

HTMLMediaElement.currentTime HTMLMediaElement.currentTime

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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