This commit is contained in:
make
2025-05-06 00:38:52 +08:00
parent a687e7ea93
commit 1c23e3dc7a
69 changed files with 2525 additions and 1694 deletions

View File

@@ -409,16 +409,98 @@ async function reportStats(data) {
}
}
function initDPlayer(strPlayUrl) {
let DomDPlayer = document.getElementById('dplayer')
videoPlayer = new DPlayer({
container: DomDPlayer,
autoplay: true,
screenshot: false,
//logo: dplayerLogo,
video: {
url: strPlayUrl,
type: 'hls',
},
pluginOptions: {
hls: {
maxBufferLength: 600,
},
},
});
videoPlayer.play()
// 监听全屏进入事件
videoPlayer.on('fullscreen', function () {
DomDPlayer.classList.add("dp-fullscreen");
// 设置视频元素的样式,取消 max-height
document.querySelector("video").style.maxHeight = "none";
});
// 监听全屏退出事件
videoPlayer.on('fullscreen_cancel', function () {
DomDPlayer.classList.remove("dp-fullscreen");
// 恢复 max-height 为 480px
document.querySelector("video").style.maxHeight = "480px";
});
videoPlayer.on('error', function () {
});
videoPlayer.on('play', function () {
// console.log('play')
// 确保视频准备好后再进行跳转
// setTimeout(() => {
// if (videoPlayer.video.readyState >= 2) {
// // readyState >= 2 表示元数据已加载
// videoPlayer.seek(20); // 跳转到 20 分钟
// }
// }, 1000); // 等待一会儿确保视频已开始
});
// 监听当前播放时间
videoPlayer.on('timeupdate', function () {
if (videoPlayer.video.currentTime < intJumpTimeFirst) { // 当前时间小于 20 秒
videoPlayer.seek(intJumpTimeFirst); // 跳过到 20 秒
}
if (videoPlayer.video.currentTime >= intJumpTimeTwoStart && videoPlayer.video.currentTime < intJumpTimeTwoEnd) { // 当前时间小于 20 秒
videoPlayer.seek(intJumpTimeTwoEnd + 1); // 跳过到 20 秒
}
});
}
function findFirstUrl(obj) {
for (const key in obj) {
const data = obj[key];
if (Array.isArray(data) && data.length > 0 && data[0].url) {
return data[0].url;
}
}
return null;
}
document.addEventListener("DOMContentLoaded", function () {
if (typeof strVideoId !== "undefined") {
// 使用示例
const statsData = {
v_id: strVideoId,
};
// 调用方法1
reportStats(statsData);
if (typeof strPlayType !== "undefined"){
if (strPlayType == 'default') {
strPlayUrl = findFirstUrl(arrPlayUrl)
} else {
var ActivePlayUrl = arrPlayUrl[strPlayType][intPlayUrlIndex - 1]
strPlayUrl = ActivePlayUrl.url
}
initDPlayer(strPlayUrl)
}
addHistoryFun()
}