Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create index.html #5

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<audio id="player" controls>
<source src="1.mp3" type="audio/mpeg">
<source src="2.mp3" type="audio/mpeg">
<source src="3.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
// 获取audio元素的引用
var player = document.getElementById("player");
// 获取audio元素的子元素,即source标签的集合
var sources = player.children;
// 定义一个函数,用来随机选择一个source标签,并设置为当前的播放源
function randomPlay() {
// 生成一个随机数,范围是0到sources的长度减1
var index = Math.floor(Math.random() * sources.length);
// 获取对应索引的source标签
var source = sources[index];
// 设置audio元素的src属性为source标签的src属性
player.src = source.src;
// 播放audio元素
player.play();
}
// 当audio元素加载完成时,调用randomPlay函数
player.addEventListener("loadeddata", randomPlay);
// 当audio元素播放结束时,调用randomPlay函数
player.addEventListener("ended", randomPlay);
</script>
Loading