This commit is contained in:
make
2025-04-21 17:49:17 +08:00
parent 7ef217c1b9
commit 2337ab4f7d
942 changed files with 209166 additions and 0 deletions

View File

@@ -0,0 +1,670 @@
//本地储存
const storageObj = {
loginStatus: window.location.hostname + 'loginStatus', //登录状态
userInfo: window.location.hostname + 'userInfo',
tokenKey: window.location.hostname + 'mi_login_token', //token 本地储存key
isMember: window.location.hostname + 'isMember', //是否会员 本地储存key
isBingPhoneReturn: window.location.hostname + 'isBingPhoneReturn', //是否绑定手机页面返回
}
/**
* 检查是否已经会员
* @returns boolean
*/
function checkIsMemberFn() {
//获取本地储存登录状态,判断是否登录
var boolMemberToken = localStorage.getItem(storageObj.tokenKey)
var boolLoginStatus = localStorage.getItem(storageObj.loginStatus)
//获取本地储存,判断是否登录会员
var boolIsMember = localStorage.getItem(storageObj.isMember)
if (!boolMemberToken) {
$(".try-detail-video").show()
return false
}
if (!boolLoginStatus) {
$(".try-detail-video").show()
return false
}
if (!boolIsMember || boolIsMember == 'false') {
$(".try-detail-video").show()
return false
} else {
$(".try-detail-video").hide()
return true
}
}
document.addEventListener('DOMContentLoaded', function () {
let videoPlayer = null;
var videoInfoJs = {
intPlayLine: 1,
intPayStatus: intPayStatus, //0免费视频 ,1vip 视频 , 2付费视频
strShareDomain: strShareDomain ?? document.domain,
strVideoTitle: $('.rank-title').text(),
strDownUrl: "",
strVideoPlayUrl: strDefaultVideoPlayUrl,
boolIsUC: navigator.userAgent.indexOf("UBrowser") > -1,
boolIsPcWidths: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
CctvOpening:[],
strCctvHref: '',
strCctvUrl: '',
boolIsShowCctvVideo: false,
boolIsShowCctvImg: false,
intCctvOpeningTimes: 10,
intCountDownTimes: 10,
CctvInterval: null,
intVideoId: intVideoId,
init() {
this.intDplay()
this.addEvent()
// videoInfoJs.intShare()
},
/**
* 绑定绑定点击事件-初始化
*/
addEvent() {
//点击反馈按钮
// $(".feedbackBtn").on("click", () => {
// this.videoFeedbackSave()
// })
// //点击刷新vip
// $(".rinseNewVip").on("click", () => {
// this.rinseNewVipFum()
// })
},
/**
* 初始化播放
* 片头的要求是:
* 1.免费视频,无登入的情况下不能跳过,点跳过弹出未登入窗口
* 2.登录了账号的情况下可以点击跳过
* 3.vip视频不需要片头,vip用户自动跳过片头
*/
intDplay() {
//付费视频
if (this.intPayStatus != 0) {
if (checkIsMemberFn()) {
this.setPlayUrl(this.strVideoPlayUrl)
// let strApiUrl = apiGetVideoInfo + '?vid=' + this.intVideoId;
// fetchApi(strApiUrl, null,successFn, onError)
// function successFn(res) {
// if (res.code == '000') {
// videoInfoJs.strVideoTitle = res.data.title
// videoInfoJs.strDownUrl = res.data.downurl
// videoInfoJs.strVideoPlayUrl = res.data.playurl
// videoInfoJs.setPlayUrl(res.data.playurl)
// }
// }
}
} else {
// 免费视频
let boolLoadCctvOpening = true
if (this.CctvOpening.length > 0 && !checkIsMemberFn()) {
boolLoadCctvOpening = true
}else{
boolLoadCctvOpening = false
}
//只有dPlayer 会限制ua
if (boolLoadCctvOpening) {
this.strCctvHref = this.CctvOpening[0].href
this.strCctvUrl = this.CctvOpening[0].cover
if (this.strCctvUrl.indexOf(".m3u8") > 0) {
this.boolIsShowCctvVideo = true
this.intCountDownTimes = this.intCctvOpeningTimes
$(".isShow_cctv_video").show()
this.beforePlay(this.strCctvUrl, true);
} else {
this.boolIsShowCctvImg = true
this.intCountDownTimes = this.intCctvOpeningTimes
$(".isShow_cctv_img img").attr('src', this.strCctvUrl)
$(".isShow_cctv_img").show()
}
$(".isShow_cctv_video").on('click', () => {
// //片头未播放,先播放片头
// console.log('片头未播放,先播放片头')
// console.log(this.intCountDownTimes)
// console.log(this.intCctvOpeningTimes)
if (this.intCountDownTimes == this.intCctvOpeningTimes) {
this.beforePlay(this.strCctvUrl);
return;
}
if (checkIsLoginFn()) {
$(".isShow_cctv_img").hide()
$(".isShow_cctv_video").hide()
this.intCountDownTimes = 0
clearInterval(this.CctvInterval)
this.setPlayUrl(this.strVideoPlayUrl)
}
})
} else {
this.intCountDownTimes = 0;
this.setPlayUrl(this.strVideoPlayUrl)
}
}
},
/**
* 设置播放地址
* @param {string} strPlayUrl
*/
setPlayUrl(strPlayUrl) {
// 所有其他条件,允许播放
videoInfoJs.beforePlay(this.strVideoPlayUrl)
//this.checkPlaylineUrl(this.intPlayLine, this.strVideoPlayUrl);
// this.strVideoPlayUrl = strPlayUrl
// this.checkPlayLine(this.intPlayLine)
},
/**
* 切换播放线路
* @param {*} intPlayline
* @returns
*/
checkPlayLine(intPlayline) {
//vip专线,只有会员可以播放
if (intPlayline == 3 && !checkIsMemberFn()) {
return;
}
$(".line-li").eq(intPlayline - 1).addClass('activePlayLine').siblings().removeClass('activePlayLine')
//vip视频,只有会员可以播放
if (this.intPayStatus != 1 && !checkIsMemberFn()) {
return;
}
// 片头未播放完,未登录,不让播放
if (this.intCountDownTimes > 0 && !checkIsLoginFn()) {
return;
}
// 所有其他条件,允许播放
this.checkPlaylineUrl(intPlayline, this.strVideoPlayUrl);
},
/**
* 切换 播放线路
* @param {int} intPlayline
* @param {string} strDefaultUrl
* @returns
*/
checkPlaylineUrl(intPlayline, strDefaultUrl) {
let strNewPlayUrl = strDefaultUrl;
switch (intPlayline) {
case '1':
strNewPlayUrl = videoInfoJs.getNewsPlayDomainFn(strDefaultUrl, arrPlayDomainLine1)
break;
case '2':
strNewPlayUrl = videoInfoJs.getNewsPlayDomainFn(strDefaultUrl, arrPlayDomainLine2)
break;
case '3':
strNewPlayUrl = videoInfoJs.getNewsPlayDomainFn(strDefaultUrl, arrPlayDomainLine3)
break;
default:
strNewPlayUrl = videoInfoJs.getNewsPlayDomainFn(strDefaultUrl, arrPlayDomainLine1)
break;
}
videoInfoJs.beforePlay(strNewPlayUrl)
},
/**
* 播放前
* @param {string} strPlayUrl
* @param {boolean} boolIsFirstPlayCctv 是否首次播放广告
*/
beforePlay(strPlayUrl, boolIsFirstPlayCctv = false) {
if (this.boolIsUC && this.boolIsPcWidths > 768) { // ios 加载 Dplayer
alert('系统检测到您正在使用UC流氓浏览器,部分功能不兼容,建议切换至极速模式或更换其他浏览器访问!')
}
this.initDPlayer(strPlayUrl)
// this.initJyPlayer264(strPlayUrl)
},
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");
});
// 监听全屏退出事件
videoPlayer.on('fullscreen_cancel', function () {
DomDPlayer.classList.remove("dp-fullscreen");
});
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 < 20) { // 当前时间小于 20 秒
videoPlayer.seek(20); // 跳过到 20 秒
}
});
},
/**
* 初始化匠影播放器
* @param {string} strPlayUrl
* @param {boolean} boolIsFirstPlayCctv 是否首次播放广告
*/
initJyPlayer264(strPlayUrl, boolIsFirstPlayCctv = false) {
videoPlayer = new VideoPlayer("#dplayer", {
src: strPlayUrl,
autoplay: true,
controls: true,
muted: true,
debug: false,
allowFullscreen:true,
zIndex:99999,
allowKeyboard:true,
//封面
poster: "",
prefixAd: { // 视频前的广告
time: 10, // 开屏广告能够跳过时间(秒),默认是 5 秒,设为 0 则没有倒计时
list: [ // 支持多个视频广告,
{
src: 'https://v1.fentvoss.com/sdv1/202308/19/rKQfUHz6U12/video/index.m3u8', //广告视频M3U8地址
link: 'https://www.baidu.com' // 广告链接
}
]
},
adList: [ // 视频播放中的广告
{
adType: 'pause', //pause暂停时展示只支持图片|rolling顶部滚动只支持文字top-left|top-right|bottom-left|bottom-right
image:'/assets/images/zxtv/60-60.png', // 广告图片
text: '', // 广告文字
link: 'https://szchuanxia.cn/demo3/', // 广告链接
fontSize: '16', // 文字大小,
fontColor: '#fff' // 文字颜色,
},
{
adType: 'top-left', //pause暂停时展示只支持图片|rolling顶部滚动只支持文字top-left|top-right|bottom-left|bottom-right
image:'/assets/images/zxtv/60-60.png', // 广告图片
text: '', // 广告文字
link: 'https://szchuanxia.cn/demo3/', // 广告链接
fontSize: '16', // 文字大小,
fontColor: '#fff' // 文字颜色,
},
{
adType: 'top-right', //pause暂停时展示只支持图片|rolling顶部滚动只支持文字top-left|top-right|bottom-left|bottom-right
image:'/assets/images/zxtv/60-60.png', // 广告图片
text: '', // 广告文字
link: 'https://szchuanxia.cn/demo3/', // 广告链接
fontSize: '16', // 文字大小,
fontColor: '#fff' // 文字颜色,
},
{
adType: 'bottom-left', //pause暂停时展示只支持图片|rolling顶部滚动只支持文字top-left|top-right|bottom-left|bottom-right
image:'/assets/images/zxtv/60-60.png', // 广告图片
text: '', // 广告文字
link: 'https://szchuanxia.cn/demo3/', // 广告链接
fontSize: '16', // 文字大小,
fontColor: '#fff' // 文字颜色,
},
{
adType: 'bottom-right', //pause暂停时展示只支持图片|rolling顶部滚动只支持文字top-left|top-right|bottom-left|bottom-right
image:'/assets/images/zxtv/60-60.png', // 广告图片
text: '', // 广告文字
link: 'https://szchuanxia.cn/demo3/', // 广告链接
fontSize: '16', // 文字大小,
fontColor: '#fff' // 文字颜色,
},
]
});
console.log('调用播放事件-play')
videoPlayer.on('play', (data)=>{
console.log('play')
// if (this.intCountDownTimes > 0) {
// if (videoInfoJs.boolIsShowCctvImg || videoInfoJs.boolIsShowCctvVideo) {
// // if (boolIsFirstPlayCctv && publicJs.strEquipmentCode == 'ios') {
// // return;
// // }
// //videoInfoJs.countDownFn()
// }
// }
})
videoPlayer.on('pause', (data)=>{
// events callback
console.log(data)
})
videoPlayer.on('ended', (data)=>{
// events callback
console.log(data)
})
videoPlayer.on('error', (data)=>{
console.log('error')
//videoInfoJs.beforePlay(videoInfoJs.checkPlaylineUrl(videoInfoJs.intPlayLine, strPlayUrl));
console.log(data)
})
console.log('player-end')
},
/**
* h264播放
* @param {string} strPlayUrl
* @param {boolean} boolIsFirstPlayCctv 是否首次播放广告
*/
initDPlayer264(strPlayUrl, boolIsFirstPlayCctv = false) {
let DomDPlayer = document.getElementById('dplayer')
if(videoPlayer == null){
videoPlayer = new DPlayer({
container: DomDPlayer,
autoplay: true,
screenshot: false,
//logo: dplayerLogo,
video: {
url: strPlayUrl,
type: 'hls',
},
pluginOptions: {
hls: {
maxBufferLength: 600,
},
},
});
}else{
videoPlayer.src = strPlayUrl
}
videoPlayer.play()
videoPlayer.on('fullscreen', function () {
DomDPlayer.classList.add("dp-fullscreen");
});
videoPlayer.on('fullscreen_cancel', function () {
DomDPlayer.classList.remove("dp-fullscreen");
});
videoPlayer.on('error', function () {
//videoInfoJs.beforePlay(videoInfoJs.checkPlaylineUrl(videoInfoJs.intPlayLine, strPlayUrl));
});
videoPlayer.on('play', function () {
// if (videoInfoJs.boolIsShowCctvImg || videoInfoJs.boolIsShowCctvVideo) {
// if (boolIsFirstPlayCctv && publicJs.strEquipmentCode == 'ios') {
// return;
// }
// videoInfoJs.countDownFn()
// }
});
},
/**
* 返回最新播放域名
* @param {string} strDefaultUrl
* @param {arr} arrPlayDomain
* @returns
*/
getNewsPlayDomainFn(strDefaultUrl, arrPlayDomain) {
let activeIndx = 1
if (strDefaultUrl.indexOf('old') != -1) {
activeIndx = 0
}
let strRandPlayDomain = videoInfoJs.getRandDomainFun(arrPlayDomain[activeIndx].domain)
return replaceDomainFun(strRandPlayDomain, strDefaultUrl)
},
/**
* 提取播放域名-随机一个
* @param {string} strPlayDomain
* @returns {string}
*/
getRandDomainFun(strPlayDomain) {
let ArrPlayDomain = ''
if (strPlayDomain.indexOf(",") > 0) {
ArrPlayDomain = strPlayDomain.split(",")
} else {
ArrPlayDomain = strPlayDomain.split(",")
}
let randNum = (Math.ceil(Math.random() * ArrPlayDomain.length - 1));
return ArrPlayDomain[randNum];
},
// /**
// * 刷新vip
// */
// rinseNewVipFum() {
// console.log(apiGetUserInfo)
// if (getLoginStatus()) {
// //用户详情
// let apiUrl = strApiDoMain+apiGetUserInfo + `?si_id=${strSite}`
// fetchApi(apiUrl, null, successFn, onError)
// function successFn(res) {
// if (res.code == '000') {
// var data = res.data
// localStorage.setItem(storageObj.userInfo, JSON.stringify(data))
// if (data.mu_is_vip) {
// // 会员
// localStorage.setItem(storageObj.isMember, true)
// } else {
// // 不是会员
// localStorage.setItem(storageObj.isMember, false)
// }
// checkIsMemberFn()
// }
// }
// showCustomAlert('刷新VIP成功');
// // layerPopup('刷新VIP成功', 3)
// }
// },
//反馈事件
videoFeedbackSave() {
if (checkIsLoginFn()) {
// $("#err-form-zd").removeClass('yc')
// $("#err-form").removeClass('yc')
}
},
/**
* 出错视频 反馈事件
* @returns
*/
errVideoFeedbackFn() {
var strCurrentWebHref = window.location.href + '?playLine=' + videoInfoJs.intPlayLine
var strBugTxt = $("#bugtxt").val();
var strBugRemark = $("#bugbeizhu").val();
var strBugTitle = $('.video-title').text()
if (strBugTxt == "请选择") {
alert("请选择报错类型~");
return false;
} else {
let postData = {
'title':strBugTitle,
'type':strBugTxt,
'content':strBugRemark,
'pay_url':strCurrentWebHref,
'content_type':3,
}
fetchApi(apiFeedbackCreate, postData,successFun, onError,false)
function successFun(res) {
if (res.code == '000') {
layer.open({
shadeClose: false,
skin: "msg",
content: '反馈成功,我们会尽快解决您反馈的问题~',
time: 3
});
layer.close(layer.index);
$("#err-form-zd").addClass('yc')
$("#err-form").addClass('yc')
} else {
alert(res.msg);
layer.close(layer.index);
$("#err-form-zd").addClass('yc')
$("#err-form").addClass('yc')
}
}
}
},
/**
* 倒计时
*/
countDownFn() {
this.CctvInterval = setInterval(() => {
this.intCountDownTimes--
$(".huiyuan_mian_cctv1 span").text(this.intCountDownTimes)
if (this.intCountDownTimes == 4 && this.CctvOpening.length > 1) {
//第二张广告图
if (this.boolIsShowCctvImg) {
$(".isShow_cctv_img img").attr('src', this.CctvOpening[1].cover)
}
}
if (this.intCountDownTimes <= 0) {
//广告展示完毕
if (this.boolIsShowCctvVideo) {
this.boolIsShowCctvVideo = false
$(".isShow_cctv_img").hide()
$(".isShow_cctv_video").hide()
} else {
this.boolIsShowCctvVideo = false
$(".isShow_cctv_img").hide()
$(".isShow_cctv_video").hide()
}
this.intCountDownTimes = 0
this.setPlayUrl(this.strVideoPlayUrl)
clearInterval(this.CctvInterval)
}
}, 1000)
}
}
videoInfoJs.init()
});
// function filterCctv(data) {
// arrCctvData = filterItemsByCctvCode(data, "WONDERFUL_VIDEO_AD");
// arrCctvOpenData = filterItemsByCctvCode(data, "VIDEO_START_AD");
// arrCctvCenterData = filterItemsByCctvCode(data, "VIDEO_PLAYER_AD");
// arrCctvVideoList = filterItemsByCctvCode(data, "VIDEO_GUESS_AD");
// arrCctvRollingData = filterItemsByCctvCode(data, "VIDEO_ROLLING_AD");
// arrCctvLocationData = filterItemsByCctvCode(data, "VIDEO_LOCATION_AD");
// // 视频开屏前广告,
// arrVideoOpenStartCctvList = arrCctvOpenData.map(item => ({
// src: item.a_content.cover.value, // 使用从 a_content.target 获取的新 URL
// link: item.a_content.target.value // 假设所有广告使用相同的链接,可根据需要调整
// }));
// // 视频播放中的广告--这块数据逻辑需要你们填充
// arrCctvPlayContent = arrCctvCenterData.map(item => ({
// adType: "pause", //pause暂停时展示只支持图片|rolling顶部滚动只支持文字top-left|top-right|bottom-left|bottom-right
// image: item.a_content.cover.value, // 广告图片
// text: "", // 广告文字
// link: item.a_content.target.value, // 广告链接
// fontSize: "16", // 文字大小,
// fontColor: "#fff" // 文字颜色,
// }));
// // 视频跑马灯广告
// arrCctvRollingContent = arrCctvRollingData.map(item => ({
// adType: "rolling",
// text: item.a_content.text.value,
// link: item.a_content.target.value,
// fontSize: item.a_content.font_color.value || "16",
// fontColor: item.a_content.font_size.value || "#fff"
// }));
// const arrAdType = ["top-left", "top-right", "bottom-left", "bottom-right"];
// const arrCctvLocationFirstData = [];
// arrAdType.forEach(adType => {
// const ad = arrCctvLocationData.find(ad => ad.a_content.ad_type.value === adType);
// if (ad) {
// arrCctvLocationFirstData.push(ad);
// }
// });
// arrCctvLocationContent = arrCctvLocationFirstData.map(item => ({
// adType: item.a_content.ad_type.value,
// image: item.a_content.cover.value,
// link: item.a_content.target.value,
// text: item.a_content.text.value,
// fontSize: item.a_content.font_color.value || "16",
// fontColor: item.a_content.font_size.value || "#fff"
// }));
// }