import { apiGetVideoInfo } from '../public/api/index.js'; import { fetchApi,onError} from '../public/api/fetch.js'; class VideoPlayer { constructor(intPayStatus, intVideoId, CctvOpening, strVideoPlayUrl, strDownUrl) { this.intPayStatus = intPayStatus; this.intVideoId = intVideoId; this.CctvOpening = CctvOpening; this.strVideoPlayUrl = strVideoPlayUrl; this.strDownUrl = strDownUrl; } init() { this.intDplay(); } intDplay() { if (this.intPayStatus !== 1 && checkIsMemberFn()) { this.fetchVideoInfo(); return; } if (this.shouldShowCctvOpening()) { this.setupCctvOpening(); } else { this.startMainVideo(); } } fetchVideoInfo() { let strApiUrl = apiGetVideoInfo + '?vid=' + this.intVideoId; fetchApi(strApiUrl, null,successFn, onError) function successFn(res) { if (res.code == '000') { videoInfoJs.setDownUrl(res.data.downurl); videoInfoJs.setPlayUrl(res.data.playurl); } } } shouldShowCctvOpening() { const disallowedDevices = ['UCBrowser', 'QuarkBrowser', 'VIVODevice']; return this.CctvOpening.length > 0 && !checkIsMemberStatus() && !disallowedDevices.includes(detectBrowserOrDevice()); } setupCctvOpening() { this.strCctvHref = this.CctvOpening[0].href; this.strCctvUrl = this.CctvOpening[0].cover; this.strCctvUrl.indexOf(".m3u8") > 0 ? this.showCctvVideo() : this.showCctvImg(); this.bindCctvClickEvent(); } showCctvVideo() { this.boolIsShowCctvVideo = true; this.intCountDownTimes = this.intCctvOpeningTimes; $(".isShow_cctv_video").show(); this.beforePlay(this.strCctvUrl, true); } showCctvImg() { this.boolIsShowCctvImg = true; this.intCountDownTimes = this.intCctvOpeningTimes; $(".isShow_cctv_img img").attr('src', this.strCctvUrl); $(".isShow_cctv_img").show(); } bindCctvClickEvent() { if (this.cctvEventBound) return; $(".isShow_cctv_video").on('click', () => { if (this.intCountDownTimes === this.intCctvOpeningTimes) { this.beforePlay(this.strCctvUrl); return; } if (checkIsLoginFn()) { $(".isShow_cctv_img, .isShow_cctv_video").hide(); this.intCountDownTimes = 0; clearInterval(this.CctvInterval); this.setPlayUrl(this.strVideoPlayUrl); } }); this.cctvEventBound = true; } startMainVideo() { this.intCountDownTimes = 0; this.setPlayUrl(this.strVideoPlayUrl); this.setDownUrl(this.strDownUrl); } // ... Any other methods or helpers you might need can be added here. } // 使用方式: // const player = new VideoPlayer(intPayStatus, intVideoId, CctvOpening, strVideoPlayUrl, strDownUrl); // player.init();