有没有大佬帮我修改下,我这套小视频网址php源码,播放下一个视频有问题,不知道咋改,没啥基础,让ai半自动写的,就只有播放下一个视频好像有问题,不能播放,其他好像没啥问题了
[Asm] 纯文本查看 复制代码 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小视频</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
display: flex;
flex-direction: column;
align-items: center;
}
#api-selector-container, #player-container, .controls-container {
width: 100%;
max-width: 800px;
display: flex;
justify-content: center;
margin: 10px auto;
padding: 0 10px;
box-sizing: border-box;
}
#api-selector-container label {
font-weight: bold;
margin-right: 10px;
}
#api-selector {
width: 100%;
max-width: 300px;
padding: 5px;
font-size: 16px;
}
video {
width: 100%;
height: auto;
border-radius: 10px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
}
.controls-container {
flex-wrap: wrap;
}
.control-button {
background: none;
color: #000;
line-height: 40px;
padding: 10px 20px;
margin: 10px 5px;
border: 2px solid #000;
border-radius: 10px;
font-weight: bold;
cursor: pointer;
transition: background-color 0.3s ease;
flex: 1;
text-align: center;
}
.control-button:hover {
background-color: #45a049;
color: #fff;
}
.full-screen-button {
position: absolute;
top: 10px;
right: 10px;
font-size: 24px;
cursor: pointer;
}
.footer-text {
text-align: center;
margin: 20px;
padding: 10px;
font-size: 14px;
color: #666;
background-color: #f5f5f5;
border: 2px solid #ccc;
border-radius: 10px;
max-width: 800px;
width: 90%;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.1);
}
/* 手机端适配 */
[url=home.php?mod=space&uid=945662]@media[/url] screen and (max-width: 600px) {
#api-selector {
font-size: 14px;
width: 80%;
}
.control-button {
padding: 8px 15px;
font-size: 14px;
margin: 8px 5px;
}
.full-screen-button {
font-size: 20px;
}
}
</style>
</head>
<body>
<div id="api-selector-container">
<label for="api-selector">选择API分类: </label>
<select id="api-selector">
<option value="https://sp.4n2.cn/?api=xjj">API分类1</option>
<option value="http://api.yujn.cn/api/zzxjj.php">API分类2</option>
</select>
</div>
<div id="player-container">
<video id="player" src="https://sp.4n2.cn/?api=xjj" controls playsinline></video>
<div class="full-screen-button">↵</div>
</div>
<div class="controls-container">
<button class="control-button" id="switch">自动播放: 开</button>
<button class="control-button" id="next1">下一个视频</button>
</div>
<footer class="footer-text">
<p>测试<br>测试</p>
</footer>
<script>
(function (window, document) {
var get = function (id) {
return document.getElementById(id);
}
var bind = function (element, event, callback) {
return element.addEventListener(event, callback);
}
var auto = true;
var player = get('player');
// 定义加载新视频的函数
var loadNewVideo = function () {
var newSource = get('api-selector').value + '?_t=' + Math.random();
// 先暂停当前视频,然后清空 src,延迟后再设置新 src 并播放
player.pause();
player.src = ""; // 先清空 src
player.load(); // 确保清空后重新加载
setTimeout(function () {
player.src = newSource;
player.load();
player.play().catch(error => console.log("播放失败: ", error));
}, 200); // 延迟 200ms 确保加载新视频
}
// 切换全屏模式
function toggleFullScreen(element) {
if (!document.fullscreenElement) {
element.requestFullscreen().catch(err => {
console.log("进入全屏失败");
});
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
}
// 下一个视频按钮绑定加载新视频
bind(get('next1'), 'click', loadNewVideo);
// 自动播放下一个视频
bind(player, 'ended', function () {
if (auto) loadNewVideo();
});
// 处理加载错误,切换到下一个视频
bind(player, 'error', function () {
console.log("加载视频出错,尝试加载下一个视频");
loadNewVideo();
});
// 自动播放切换
bind(get('switch'), 'click', function () {
auto = !auto;
this.innerText = '自动播放: ' + (auto ? '开' : '关');
});
// API选择更改时加载新视频
bind(get('api-selector'), 'change', loadNewVideo);
// 初始播放
player.play();
})(window, document);
</script>
</body>
</html> |