我有这段代码,但我不知道如何让歌曲从 0:19 秒开始。你能帮我一下吗?
<div class="fin-subheading">
· ROLEPLAY ·
<audio id='music' volume='0.5' autoplay controls>
<source src="anonymous.mp3" type="audio/mpeg">
</audio>
</div>
<script>
var audio = document.getElementById("music");
audio.volume = 0.3;
</script>
最佳答案
您可以在 src
属性本身中指定播放范围。请参阅文档 here :
When specifying the URI of media for an or element, you can optionally include additional information to specify the portion of the media to play. To do this, append a hash mark ("#") followed by the media fragment description.
A time range is specified using the syntax:
#t=[starttime][,endtime]
所以代替:
<source src="anonymous.mp3" type="audio/mpeg">
简单地说:
<source src="anonymous.mp3#t=n,m" type="audio/mpeg">
其中 n
和 m
分别是开始时间和结束时间。
范围也可以是无界的。例如,您可以这样做:
<source src="anonymous.mp3#t=19" type="audio/mpeg">
从 19 秒开始一直播放到最后;甚至是这个:
<source src="anonymous.mp3#t=,19" type="audio/mpeg">
将从头开始持续 19 秒。
关于HTML 自动播放歌曲和 StartAt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65640018/