This commit is contained in:
Your Name
2026-05-26 16:53:21 +08:00
parent b764e7555d
commit 97aefcf86b
2 changed files with 118 additions and 68 deletions

View File

@@ -446,8 +446,35 @@ async function reportStats(data) {
} }
} }
function resolveDPlayerContainer() {
return document.getElementById('dplayer') || document.querySelector('.dplayer');
}
function updateDPlayerMaxHeight(maxHeight) {
const videoElement = document.querySelector("video");
const videoWrap = document.querySelector(".video-play-page .dplayer-video-wrap");
if (videoElement) {
videoElement.style.maxHeight = maxHeight;
}
if (videoWrap) {
videoWrap.style.maxHeight = maxHeight;
}
}
function initDPlayer(strPlayUrl) { function initDPlayer(strPlayUrl) {
let DomDPlayer = document.getElementById('dplayer') let DomDPlayer = resolveDPlayerContainer();
if (!DomDPlayer) {
console.warn('DPlayer 容器不存在');
return null;
}
if (!strPlayUrl) {
console.warn('DPlayer 播放地址为空');
return null;
}
videoPlayer = new DPlayer({ videoPlayer = new DPlayer({
container: DomDPlayer, container: DomDPlayer,
autoplay: true, autoplay: true,
@@ -468,25 +495,22 @@ function initDPlayer(strPlayUrl) {
// 监听全屏进入事件 // 监听全屏进入事件
videoPlayer.on('fullscreen', function () { videoPlayer.on('fullscreen', function () {
DomDPlayer.classList.add("dp-fullscreen"); if (DomDPlayer.classList) {
// 设置视频元素的样式,取消 max-height DomDPlayer.classList.add("dp-fullscreen");
document.querySelector("video").style.maxHeight = "none"; }
document.querySelector(".video-play-page .dplayer-video-wrap").style.maxHeight = "none"; updateDPlayerMaxHeight("none");
}); });
// 监听全屏退出事件 // 监听全屏退出事件
videoPlayer.on('fullscreen_cancel', function () { videoPlayer.on('fullscreen_cancel', function () {
DomDPlayer.classList.remove("dp-fullscreen"); if (DomDPlayer.classList) {
// 恢复 max-height 为 480px DomDPlayer.classList.remove("dp-fullscreen");
if (isMobile()) { }
document.querySelector("video").style.maxHeight = "218px"; if (isMobile()) {
document.querySelector(".video-play-page .dplayer-video-wrap").style.maxHeight = "218px"; updateDPlayerMaxHeight("218px");
} else { } else {
document.querySelector("video").style.maxHeight = strMaxPlayHeight ?? '480px'; updateDPlayerMaxHeight(strMaxPlayHeight ?? '480px');
document.querySelector(".video-play-page .dplayer-video-wrap").style.maxHeight = strMaxPlayHeight ?? '480px';
} }
}); });
videoPlayer.on('error', function () { videoPlayer.on('error', function () {
@@ -499,6 +523,8 @@ function initDPlayer(strPlayUrl) {
videoPlayer.on('timeupdate', function () { videoPlayer.on('timeupdate', function () {
}); });
return videoPlayer;
} }
function findFirstUrl(obj) { function findFirstUrl(obj) {
@@ -656,4 +682,3 @@ document.addEventListener("DOMContentLoaded", function () {
}) })

View File

@@ -252,35 +252,47 @@ document.addEventListener('DOMContentLoaded', function () {
// this.initJyPlayer264(strPlayUrl) // this.initJyPlayer264(strPlayUrl)
}, },
initDPlayer(strPlayUrl) { initDPlayer(strPlayUrl) {
let DomDPlayer = document.getElementById('dplayer') let DomDPlayer = document.getElementById('dplayer') || document.querySelector('.dplayer')
videoPlayer = new DPlayer({ if (!DomDPlayer) {
container: DomDPlayer, console.warn('DPlayer 容器不存在')
autoplay: true, return null
screenshot: false, }
//logo: dplayerLogo, if (!strPlayUrl) {
video: { console.warn('DPlayer 播放地址为空')
url: strPlayUrl, return null
type: 'hls', }
}, videoPlayer = new DPlayer({
pluginOptions: { container: DomDPlayer,
hls: { autoplay: true,
maxBufferLength: 600, screenshot: false,
}, //logo: dplayerLogo,
}, video: {
}); url: strPlayUrl,
type: 'hls',
},
pluginOptions: {
hls: {
maxBufferLength: 600,
},
},
});
videoPlayer.play() videoPlayer.play()
// 监听全屏进入事件 // 监听全屏进入事件
videoPlayer.on('fullscreen', function () { videoPlayer.on('fullscreen', function () {
DomDPlayer.classList.add("dp-fullscreen"); if (DomDPlayer.classList) {
}); DomDPlayer.classList.add("dp-fullscreen");
// 监听全屏退出事件 }
videoPlayer.on('fullscreen_cancel', function () { });
DomDPlayer.classList.remove("dp-fullscreen"); // 监听全屏退出事件
}); videoPlayer.on('fullscreen_cancel', function () {
if (DomDPlayer.classList) {
DomDPlayer.classList.remove("dp-fullscreen");
}
});
videoPlayer.on('error', function () { videoPlayer.on('error', function () {
}); });
@@ -295,12 +307,13 @@ document.addEventListener('DOMContentLoaded', function () {
}, 1000); // 等待一会儿确保视频已开始 }, 1000); // 等待一会儿确保视频已开始
}); });
// 监听当前播放时间 // 监听当前播放时间
videoPlayer.on('timeupdate', function () { videoPlayer.on('timeupdate', function () {
if (videoPlayer.video.currentTime < 20) { // 当前时间小于 20 秒 if (videoPlayer.video.currentTime < 20) { // 当前时间小于 20 秒
videoPlayer.seek(20); // 跳过到 20 秒 videoPlayer.seek(20); // 跳过到 20 秒
} }
}); });
}, return videoPlayer
},
/** /**
@@ -414,11 +427,19 @@ document.addEventListener('DOMContentLoaded', function () {
* @param {string} strPlayUrl * @param {string} strPlayUrl
* @param {boolean} boolIsFirstPlayCctv 是否首次播放广告 * @param {boolean} boolIsFirstPlayCctv 是否首次播放广告
*/ */
initDPlayer264(strPlayUrl, boolIsFirstPlayCctv = false) { initDPlayer264(strPlayUrl, boolIsFirstPlayCctv = false) {
let DomDPlayer = document.getElementById('dplayer') let DomDPlayer = document.getElementById('dplayer') || document.querySelector('.dplayer')
if(videoPlayer == null){ if (!DomDPlayer) {
videoPlayer = new DPlayer({ console.warn('DPlayer 容器不存在')
container: DomDPlayer, return null
}
if (!strPlayUrl) {
console.warn('DPlayer 播放地址为空')
return null
}
if(videoPlayer == null){
videoPlayer = new DPlayer({
container: DomDPlayer,
autoplay: true, autoplay: true,
screenshot: false, screenshot: false,
//logo: dplayerLogo, //logo: dplayerLogo,
@@ -438,24 +459,29 @@ document.addEventListener('DOMContentLoaded', function () {
videoPlayer.play() videoPlayer.play()
videoPlayer.on('fullscreen', function () { videoPlayer.on('fullscreen', function () {
DomDPlayer.classList.add("dp-fullscreen"); if (DomDPlayer.classList) {
}); DomDPlayer.classList.add("dp-fullscreen");
videoPlayer.on('fullscreen_cancel', function () { }
DomDPlayer.classList.remove("dp-fullscreen"); });
}); videoPlayer.on('fullscreen_cancel', function () {
if (DomDPlayer.classList) {
DomDPlayer.classList.remove("dp-fullscreen");
}
});
videoPlayer.on('error', function () { videoPlayer.on('error', function () {
//videoInfoJs.beforePlay(videoInfoJs.checkPlaylineUrl(videoInfoJs.intPlayLine, strPlayUrl)); //videoInfoJs.beforePlay(videoInfoJs.checkPlaylineUrl(videoInfoJs.intPlayLine, strPlayUrl));
}); });
videoPlayer.on('play', function () { videoPlayer.on('play', function () {
// if (videoInfoJs.boolIsShowCctvImg || videoInfoJs.boolIsShowCctvVideo) { // if (videoInfoJs.boolIsShowCctvImg || videoInfoJs.boolIsShowCctvVideo) {
// if (boolIsFirstPlayCctv && publicJs.strEquipmentCode == 'ios') { // if (boolIsFirstPlayCctv && publicJs.strEquipmentCode == 'ios') {
// return; // return;
// } // }
// videoInfoJs.countDownFn() // videoInfoJs.countDownFn()
// } // }
}); });
}, return videoPlayer
},
/** /**
@@ -667,4 +693,3 @@ document.addEventListener('DOMContentLoaded', function () {
// })); // }));
// } // }