PageSourceSearch

https://www.cnmc.com.cn/cnmc/lib/tempalte/scheme/js/pingzi_video.js

js cnmc.com.cn collected 2026-10-02 10:59:31 UTC 16,056 bytes, 534 lines download raw bytes

1$(document).ready(function() {
2	/*
3	 *  pc端判断
4	 */
5	function IsPC() {
6		var userAgentInfo = navigator.userAgent;
7		var Agents = ["Android", "iPhone",
8			"SymbianOS", "Windows Phone",
9			"iPad", "iPod"
10		];
11		var flag = true;
12		for(var v = 0; v < Agents.length; v++) {
13			if(userAgentInfo.indexOf(Agents[v]) > 0) {
14				flag = false;
15				break;
16			}
17		}
18		return flag;
19	}
20	/*
21	 * 随机数
22	 * */
23	function _charecter() {
24		var character = String.fromCharCode(Math.floor(Math.random() * 26) + "A".charCodeAt(0));
25		return character;
26	}
27	/*
28	 *  è¡¥0
29	 */
30	function addzero(num) {
31		if(num < 10) {
32			return("0" + num);
33		} else {
34			return num;
35		}
36	}
37	/*
38	 *  视频事件监听事件
39	 * 
40	 * 	@eventName 视频事件名称
41	 *  @m	视频对象
42	 * 	@fun 回调函数
43	 * 
44	 */
45	var eventTester = function(eventName, m, fun) {
46		if(window.addEventListener) {
47			m.addEventListener(eventName, function() {
48				if(fun) {
49					fun(this);
50				}
51				//console.log((new Date()).getTime(),eventName);
52			}, false);
53		} else {
54			m.attachEvent('on' + eventName, function() {
55				if(fun) {
56					fun(this);
57				}
58				// console.log((new Date()).getTime(),eventName);
59			});
60		}
61	}
62	/*
63	 *  视频播放
64	 * 
65	 */
66	//视频播放
67	$(".m-video").on("click", function() {
68		if($(".video-box").length > 0) {
69			return;
70		}
71		document.ondragstart = function() {
72			return false;
73		};
74		window.onresize = function() {
75			iteme = setTimeout(function() {
76				if(!checkFull()) {
77					//要执行的动作
78					$("body").removeClass("noscroll");
79					$(".video-box").removeClass("quanping");
80					$(".video-fullscreen").find("i").removeClass("i-suoxiao").addClass("i-quanping");
81				} else {
82					$("body").addClass("noscroll");
83					$(".video-box").addClass("quanping");
84					$(".video-fullscreen").find("i").removeClass("i-quanping").addClass("i-suoxiao");
85				}
86			}, 0)
87		}
88		function checkFull() {
89			var explorer = window.navigator.userAgent.toLowerCase();
90			console.log(window.screen.width, window.outerWidth, window.screen.height, window.outerHeight)
91			if(explorer.indexOf('chrome') > 0) { //chrome
92				if((window.screen.width - window.outerWidth <= 17) && (window.screen.height - window.outerHeight <= 17)) {
93					return true;
94				} else {
95					return false;
96				}
97			} else { //IE 9+  fireFox
98				if(window.outerWidth == screen.width) {
99					return true;
100				} else {
101					return false;
102				}
103			}
104		}
105
106		function quanpin(elem) {
107			if(IsPC()) {
108				var elem = document.documentElement;
109			} else {
110				if(elem.paused && elem.networkState <= elem.HAVE_METADATA) {
111					elem.play();
112					setTimeout(function() {
113						elem.pause();
114						elem.webkitEnterFullScreen();
115						return;
116					}, 0);
117				} else {
118					elem.webkitEnterFullScreen();
119					return;
120				}
121			}
122			if(elem.requestFullscreen) {
123				//"W3C";
124				elem.requestFullscreen();
125			} else if(elem.mozRequestFullScreen) {
126				//FireFox
127				elem.mozRequestFullScreen();
128
129			} else if(elem.webkitRequestFullScreen) {
130				//Chrome等
131				elem.webkitRequestFullScreen();
132
133			} else if(elem.msRequestFullscreen) {
134				//IE11
135				console.log(11);
136				elem.msRequestFullscreen();
137			}
138		}
139
140		function exitquanping() {
141			if(document.exitFullscreen) {
142
143				document.exitFullscreen();
144
145			} else if(document.mozCancelFullScreen) {
146
147				document.mozCancelFullScreen();
148
149			} else if(document.webkitCancelFullScreen) {
150
151				document.webkitCancelFullScreen();
152
153			} else if(document.msExitFullscreen) {
154
155				document.msExitFullscreen();
156
157			}
158		}
159		var menuarr;
160		var menustr="";
161		if($(this).attr("data-menu")){
162			menuarr=$(this).attr("data-menu").split(" ");
163			$(menuarr).each(function(k){
164				menustr+="<li class='video-menu-item video-menu-item-"+k+" "+(k==0?"video-active":"")+"'  >"+this+"</li>";
165			})
166		}
167
168		var datasrc = $(this).attr("data-src"),src='';
169		var  dangqian="";
170		if(src.indexOf("mp4")<0&&$(this).attr("data-menu")){
171			dangqian=menuarr[0];
172			src = datasrc+dangqian+".mp4";
173		}else{
174			src = datasrc;
175		}
176		if(!src) {
177			alert("未添加视频链接");
178		}
179		console.log(src);
180		var menu=["<div class='video-definition video-tooltip '>",
181			"<button class='video-button video-tooltip-toggle video-definition-button'>",
182			"<span>"+dangqian+"</span>",
183			"</button>",
184			"<div class='video-tooltip-content'>",
185			"<ul class='video-menu'>",
186				menustr,
187			"</ul>",
188			"</div>",
189			"</div>"];
190		if(!$(this).attr("data-menu")){
191			menu=[]
192		}
193		var vClass = $(this).attr("data-heibian") ? "heibian" : "";
194		var videoid = "my" + _charecter() + _charecter();
195		var iteme = null;
196		var str = ["<div class='video-box " + vClass + "' id='" + videoid + "box'>",
197			"<div class='video-bg'></div>",
198			"<div class='video-loading-pulse'></div>",
199			"<div class='video-close'></div>",
200			"<div class='video-container f-czspjuzhong'>",
201			"<div class='video-div'>",
202			"<div class='video-video'>",
203			"<video id=" + videoid + "  x-webkit-airplay='' playsinline='' webkit-playsinline='' ",
204			"src='" + src + "'",
205			">",
206			"</video>",
207			"</div>",
208			"<div class='video-bofang f-czspjuzhong '> <i class='i i-bofang '></i></div>",
209			"<div class='video-loading yihuanchun f-czspjuzhong'> <i class='i i-loading '></i></div>",
210			"<div class='video-ui'>",
211			"<div class='video-progress'>",
212			"<div class='video-tooltip video-tinytip video-tooltip-time'>",
213			"<button class='video-tooltip-toggle'>",
214			"<span class='video-tooltip-value'></span>",
215			"</button>",
216			"<div class='video-tooltip-content'>",
217			"<div class='video-tinytip-content'>",
218			"<span class='video-text'></span>",
219			"</div>",
220			"</div>",
221			"</div>",
222			"<div class='video-progress-padding'></div>",
223			"<div class='video-progress-list'>",
224			"<div class='video-progress-buffer'></div>",
225			"<div class='video-progress-hover'></div>",
226			"<div class='video-progress-play'><span class='video-progress-handle'></span></div>",
227			"</div>",
228			"</div>",
229			"<div class='video-controls-buttons'>",
230			"<button class='video-bofang video-button'> <i class='i i-bofang f-czspjuzhong'></i></button>",
231			"<span class='video-time-panel'>",
232			"<span class='video-time-panel-current'>00:00</span>",
233			"<span class='video-time-panel-split'>&nbsp&nbsp/&nbsp&nbsp</span>",
234			"<span class='video-time-panel-total'>00:00</span>",
235			"</span>",
236			"<div class='video-fullscreen'>",
237			"<button class='video-button video-tooltip-toggle video-fullscreen-default' type='button'>",
238			"<i class='i i-quanping f-czspjuzhong'></i>",
239			"</button>",
240			"</div>",
241			menu.join(""),
242			"<div class='video-volume video-popup'>",
243			"<button class='video-button video-btn-volume' data-state='volume'>",
244			"<i class='i i-voice-on f-czspjuzhong'></i>",
245			"</button>",
246			"<div class='video-volume-slider video-popup-content'>",
247			"<div class='video-volume-range'>",
248			"<div class='video-volume-range-current' style='height: 50%;'>",
249			"<div class='video-volume-handle'></div>",
250			"</div>",
251			"</div>",
252			"<div class='video-tinytip-tiao'></div>",
253			"</div>",
254			"</div>",
255			"</div>",
256			"</div>",
257			"</div>",
258			"</div>",
259			"</div>"
260		]
261		$("body").append(str.join(""));
262		var meido = document.getElementById(videoid);
263		meido.volume = .5;
264		var videobox = $("#" + videoid + "box");
265
266		/*视频缓存成功可以获取长度和播放*/
267		eventTester("waiting", meido, function() {
268			console.log(" 等待数据,并非错误");
269			$(".video-loading").removeClass("yihuanchun");
270		});
271		eventTester("playing", meido, function() {
272			console.log("播放了");
273			videobox.addClass("video-playing").removeClass("video-pause");
274			$(".video-loading").addClass("yihuanchun");
275		});
276		eventTester("stalled", meido, function() {
277			console.log("/网速失速");
278		});
279		eventTester("ended", meido, function() {
280			//console.log("播放结束");
281//			$(".video-close").click();
282		});
283		eventTester("canplay", meido, function() {
284			//console.log("可以播放");
285			$(".video-container",videobox).addClass("video-ready");
286			meido.canplay=true;
287			meido.play();
288			$(".video-bofang").find("i").removeClass("i-bofang").addClass("i-zhanting").css("transition","none");
289		});
290		eventTester("loadedmetadata", meido, function() {
291			//console.log("成功获取时长")
292			$(".video-time-panel-total").html(addzero(parseInt(meido.duration / 60)) + ":" + addzero(parseInt(meido.duration % 60)));
293		});
294		eventTester("suspend",meido,function(){
295//			$(".video-loading").removeClass("yihuanchun");
296			console.log("延迟下载")
297		})
298		eventTester("loadstart",meido,function(){
299			console.log("客户端开始请求数据")
300			$(".video-loading").removeClass("yihuanchun");
301		})
302		eventTester("progress",meido,function(){
303			$(".video-container",videobox).addClass("video-ready");
304			console.log("客户端正在请求数据")
305		})
306		/*进度相关*/
307		eventTester("timeupdate", meido, function() {
308			//console.log("播放时间改变");
309			if(meido.canplay){
310				var currentTime = meido.currentTime;
311				var buffered = meido.buffered.end(0);
312				var duration = meido.duration;
313				for(var i = 0; i < meido.buffered.length; i++) {
314					if(currentTime < meido.buffered.end(i)) {
315						buffered = meido.buffered.end(i);
316						break;
317					}
318				}
319				var buff_pro = parseInt((buffered / duration) * 100);
320				$(".video-time-panel-current").html(addzero(parseInt(currentTime / 60)) + ":" + addzero(parseInt(currentTime % 60)));
321				$(".video-progress-play").css("width", currentTime / duration * 100 + "%");
322				$(".video-progress-buffer").css("width", buff_pro + "%");
323			}
324		});
325		var mx = 0;
326		$(document).on("mousemove", function(e) {
327			mx = e.screenX;
328		})
329		eventTester("play", meido, function(e) {
330			videobox.addClass("video-playing").removeClass("video-pause");
331			$(".video-bofang.f-czspjuzhong").addClass("video-hide");
332			//var ny=e.cy
333			var px = mx;
334			clearTimeout(iteme);
335			iteme = setTimeout(function() {
336				if(px == mx) {
337					$(".video-div").addClass("video-hide-ui");
338				}
339			}, 5000);
340		});
341		eventTester("pause", meido, function() {
342			videobox.addClass("video-pause").removeClass("video-playing");
343			$(".video-bofang.f-czspjuzhong").removeClass("video-hide");
344		});
345		eventTester("ended", meido, function() {
346			videobox.removeClass("video-pause video-playing");
347			$(".video-bofang").find("i").removeClass("i-zhanting").addClass("i-bofang");
348//			$(".video-bofang.f-czspjuzhong").removeClass("video-hide");
349		});
350		/*
351		 * 播放暂停切换
352		 * 
353		 * */
354		$(".video-bofang,.video-video").on("click", function(e) {
355			if(IsPC() || e.currentTarget.classList[0] == "video-bofang" || e.target.classList[0] == "video-bofang") {
356				clearTimeout(iteme);
357				iteme = setTimeout(function() {
358					//do function在此处写单击事件要执行的代码
359					if($(".video-bofang").find("i").hasClass("i-bofang")) {
360						meido.play();
361						$(".video-bofang").find("i").removeClass("i-bofang").addClass("i-zhanting");
362					} else {
363						meido.pause();
364						$(".video-bofang").find("i").removeClass("i-zhanting").addClass("i-bofang");
365					}
366				},100);
367			} else {
368				if(videobox.hasClass("hideui")) {
369					videobox.removeClass("hideui");
370				} else {
371					videobox.addClass("hideui");
372				}
373			}
374		});
375		/*
376		 * 双击全屏
377		 * 
378		 * */
379		$(".video-video").on("dblclick", function() {
380			if(IsPC()) {
381				clearTimeout(iteme);
382				if(videobox.hasClass("quanping")) {
383					exitquanping();
384				} else {
385					quanpin();
386				}
387			}
388		});
389		/*
390		 *
391		 *  鼠标移入隐藏UI
392		 * 
393		 * */
394		$(".video-ui").on("mouseleave", function() {
395			clearTimeout(iteme);
396			iteme = setTimeout(function() {
397				//do function在此处写单击事件要执行的代码
398				$(".video-div").addClass("video-hide-ui");
399			}, 5000);
400
401		});
402		$(".video-ui").on("mouseenter", function() {
403			$(".video-div").removeClass("video-hide-ui");
404		});
405		/*
406		 *
407		 *  关闭video
408		 * 
409		 * */
410		$(".video-close").on("click touchstart", function() {
411			videobox.remove();
412		});
413		//进度条面板相对浏览器的左边的距离
414		var parent_left = 0;
415		//鼠标位置相对浏览器的左边的距离
416		var e_left = 0;
417		/*
418		 *  进度条
419		 */
420		$(".video-progress", videobox).on("mousemove touchmove", function(e) {
421			var event;
422			if(e.offsetX) {
423				event = e;
424			} else if(e.originalEvent.changedTouches[0].clientX) {
425				event = e.originalEvent.changedTouches[0];
426			}
427			parent_left = $(this).offset().left;
428			//鼠标位置相对浏览器的左边的距离
429			e_left = event.pageX;
430			var width = e_left - parent_left;
431			var wb = (width / $(this).width());
432			var tt = wb * meido.duration;
433			$(".video-tooltip", $(this)).css({
434				"left": (wb * 100) + "%"
435			});
436			$(".video-progress-hover", videobox).css({
437				"width": (wb * 100) + "%"
438			});
439			$(".video-text", videobox).html(addzero(parseInt(tt / 60)) + ":" + addzero(parseInt(tt % 60)));
440		});
441		$(".video-progress", videobox).on("click touchstart touchend", function(e) {
442			videobox.removeClass("video-playing");
443			var percent = ($(".video-progress-hover", videobox).width() / $(this).width());
444			console.log(percent);
445			meido.currentTime = (percent * meido.duration);
446		});
447		/*
448		 *  音量
449		 */
450		var canMove = false;
451		$(".video-tinytip-tiao", videobox).on("mousedown", function(e) {
452			canMove = true;
453			console.log(canMove);
454			var zi = $(".video-volume-range-current", videobox);
455			if(canMove) {
456				volumeh = 1 - e.offsetY / $(this).height();
457				console.log(volumeh);
458				zi.css("height", volumeh * 100 + "%")
459			} else {
460				return;
461			}
462		});
463		$(document).on("mouseup", function(e) {
464			canMove = false;
465		});
466		var volumeh = 0;
467		$(".video-tinytip-tiao", videobox).on("mousemove ", function(e) {
468			var zi = $(".video-volume-range-current", videobox);
469			var hh = $(".video-volume-range", videobox);
470			if(canMove) {
471				console.log(e);
472				volumeh = 1 - (e.offsetY - 16) / hh.height();
473				console.log(volumeh);
474				if(volumeh <= 0) {
475					$(".video-btn-volume i").removeClass("i-voice-on").addClass("i-voice-off");
476				} else if(volumeh > 1) {
477					volumeh = 1;
478				} else {
479					$(".video-btn-volume i").removeClass("i-voice-off").addClass("i-voice-on");
480				}
481				zi.css("height", volumeh * 100 + "%")
482				meido.volume = volumeh;
483			} else {
484				return;
485			}
486		});
487		$(".video-btn-volume", videobox).on("click", function() {
488			if($(this).find("i").hasClass("i-voice-on")) {
489				meido.volume = false;
490				volumeh = $(".video-volume-range-current", videobox).height() / $(".video-volume-range", videobox).height();
491				console.log(volumeh);
492				$(".video-volume-range-current", videobox).css("height", 0 + "%");
493				$(".video-btn-volume i").removeClass("i-voice-on").addClass("i-voice-off");
494			} else {
495				meido.volume = true;
496				$(".video-volume-range-current", videobox).css("height", volumeh * 100 + "%");
497				$(".video-btn-volume i").removeClass("i-voice-off").addClass("i-voice-on");
498			}
499		})
500		/*
501		 *  音量  结尾
502		 */
503		/*
504		 *  全屏
505		 */
506		$(".video-fullscreen", videobox).on("click", function() {
507			if($(this).find("i").hasClass("i-quanping")) {
508				quanpin(meido);
509			} else {
510				console.log("退出全屏");
511				exitquanping();
512			}
513		})
514		/*
515		 *  全屏结尾
516		 */
517		
518		/*
519		 *  切换清晰度
520		 */
521		$(".video-menu-item").on("click",function(){
522			if($(this).hasClass("video-active")){
523				return ;
524			}
525			$(this).addClass("video-active").siblings().removeClass("video-active");
526			$(".video-definition-button span").html($(this).html());
527			var duration=meido.currentTime;
528			meido.canplay=false;
529			meido.pause();
530			meido.src=datasrc+$(this).html()+".mp4";
531			meido.currentTime=duration;
532		});
533	});
534})

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.