gpt4 book ai didi

Javascript onended 正在检测视频的结尾

转载 作者:行者123 更新时间:2023-11-27 23:10:29 26 4
gpt4 key购买 nike

我的代码中的所有内容都有效。它只是在完成当前歌曲/视频后不会切换到下一首歌曲/视频。我尝试添加一个 onended 事件处理程序(在标记和 JavaScript 中)但失败了。我也尝试过 jQuery,但它没有用。由于某些原因,它不会在歌曲结尾更改歌曲。相反,它会一遍又一遍地重播同一首歌曲。

<video id="vid" src="main/" playsinline autoplay loop>
<script>
var video = document.currentScript.parentElement;
video.volume = 0.1;
var lastSong = null;
var selection = null;
var playlist = ["main/songn.mp4", "main/songl.mp4", "/main/songt.mp4", "/main/songf.mp4"]; // List of Songs
var video = document.getElementById("vid");
video.autoplay=true;
video.addEventListener("ended", selectRandom);

function selectRandom(){
while(selection == lastSong){
selection = Math.floor(Math.random() * playlist.length);
}
lastSong = selection;
video.src = playlist[selection];

}

selectRandom();
video.play();

</script>
</video>

最佳答案

您只需要删除 loop如果要触发 end 事件 ( doc ),则来自视频标签的参数:

<video id="vid" src="main/" playsinline autoplay>

(您的代码将通过在歌曲结束时加载一首新歌曲来处理循环。)

顺便说一句,保留var video = document.getElementById("vid");引用你的<video>标签,它比第一个声明更短更干净。

关于Javascript onended 正在检测视频的结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46292535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com