$(function() { //ç”¨æž„é€ å‡½æ•°æ–¹æ³•å†™ function playBox() { this.win_w = null; this.win_h = null; this.btn = null; this.videomask = null; this.close = null; this.jWUrl = null; }; function isIE891011() { var ie = /msie ([6-9]|10)/i.test(navigator.userAgent); if (!ie) { ie = /Trident|rv:11/i.test(navigator.userAgent); } return ie; } //支持preload,定为chrome function supportPreload() { var userAge = navigator.userAgent; var isChrome = userAge.match(/Chrome\s*\/\s*(\d+\D\d+(\D\d+)?)/i); var Opera = userAge.match(/Opera\s*\/?\s*(\d+(\D\d+)?(\D\d+)?)/i) || userAge.match(/OPR\s*\/?\s*(\d+(\D\d+)?(\D\d+)?)/i) var OperaMini = userAge.match(/Opera\sMini\s*\/?\s*(\d+(\D\d+)?(\D\d+)?)/i) var OperaCoast = userAge.match(/Coast\s*\/?\s*(\d+(\D\d+)?(\D\d+)?)/i) return isChrome && !Opera && !OperaMini && !OperaCoast; } //初始化参数 playBox.prototype.init = function(opts) { this.opts = opts; //750px,以上的需要content中播放 if (this.opts.content && $(this.opts.content).length && ($(window).width() > this.opts.wrapSize || this.opts.wapNoDialog)) { this.opts.playInContent = true; } if (playBox.prototype.preVideo) { playBox.prototype.preVideo.closeVideo() } playBox.prototype.preVideo = this; this.aNiMate(); }; //更新参数 playBox.prototype.reset = function() { if (this.opts.playInContent) { this.win_w = this.videomask.width(); this.win_h = this.videomask.height(); } else { this.win_w = $(window).width(); this.win_h = $(window).height(); } var size = this.getVideoSize(); $('.jWVideoFrame').css({ 'position': 'absolute', 'width': size.w, 'height': size.h, 'top': size.y, 'left': size.x }); // this.player.resize(size.w, size.h) }; //执行参数 playBox.prototype.aNiMate = function() { this.btn = $(this.opts.btn); var $isStatus = this.btn.find(".J-play-status").length && this.btn.find(".J-play-status") var $isCon = this.btn.find(".videocon-btn").length && this.btn.find(".videocon-btn") this.statusBtn = $isStatus || $isCon || this.btn; this.jWUrl = this.opts.jWUrl; //创建区域 if (this.opts.playInContent) { if (this.opts.btn.parent().find(this.opts.content).length) { this.videomask = this.opts.btn.parent().find(this.opts.content) } else { $(this.opts.content).html(""); this.videomask = $(this.opts.content); } this.win_w = this.videomask.width(); this.win_h = this.videomask.height(); this.opts.full = true; if (this.videomask[0] != this.btn[0]) { this.videomask.data("remark-btn", this.btn); } if (this.videomask.data("init-status-btn")) { this.statusBtn = this.videomask.data("init-status-btn"); this.videomask.data("init-status-btn", null); } //创建弹框 } else { //å¦‚æžœä¹‹å‰æœ‰å¼¹æ¡†ï¼Œå…ˆåˆ é™¤ä¹‹å‰çš„å¼¹æ¡† $('.videomask').remove(); this.win_w = $(window).width(); this.win_h = $(window).height(); this.createPopUp(); this.opts.full = false; } //创建视频 this.createVideo(); //如果是弹窗方式且有分享功能 if (!this.opts.playInContent && (this.opts.shareFunc || this.opts.downloadPath)) { this.initShare(); } this.bindEvent(); }; //视频弹框 playBox.prototype.createPopUp = function() { var This = this; //创建弹框 var div = "
"; //把弹窗插入到body最下面 $('body').append(div); //从新获取弹框对象 this.videomask = $('.videomask'); //弹框透明度200S动画显示 this.videomask.fadeIn(200); }; /*获取视频大小*/ playBox.prototype.getVideoSize = function() { var videoWidth, videoHeight, videoTop, videoleft; if (this.win_w > 980) { videoWidth = this.opts.full ? this.win_w : 980; videoHeight = videoWidth * 9 / 16; videoTop = (this.win_h - videoHeight) / 2; videoleft = (this.win_w - videoWidth) / 2; } else if (980 > this.win_w && this.win_w > 480) { videoWidth = this.opts.full ? this.win_w : this.win_w * 0.8; videoHeight = videoWidth * 9 / 16; videoTop = (this.win_h - videoHeight) / 2; videoleft = (this.win_w - videoWidth) / 2; } else { videoWidth = this.win_w; videoHeight = videoWidth * 9 / 16; videoTop = (this.win_h - videoHeight) / 2; videoleft = (this.win_w - videoWidth) / 2; } return { x: videoleft, y: videoTop, w: videoWidth, h: videoHeight } } playBox.prototype.createVideo = function() { $(".jWVideoFrame").remove(); var playerid = "jWVideoFrameId"; var This = this, pcdiv = "", wapdiv = "", oVideo = ""; if (this.opts.playInContent) { pcdiv = ''; wapdiv = ''; } if (navigator.userAgent.match(/mobile/i)) { oVideo = "
" + wapdiv + "
"; } else { oVideo = "
" + pcdiv + "
"; } var size = this.getVideoSize(); this.videomask.append(oVideo).addClass("playing").data("url", This.jWUrl); this.btn.addClass("playing"); var remarkBtn = this.videomask.data("remark-btn"); if (remarkBtn) { remarkBtn.addClass("playing"); } $('.jWVideoFrame').css({ 'position': 'absolute', 'width': size.w, 'height': size.h, 'top': size.y, 'left': size.x }); //从新获取弹框关闭按钮 this.close = $('.videomask .icon-close'); window["videojsLanguage"] = $("html").hasClass("LANG-cn") ? "zh-CN" : "en"; //调用关闭按钮事件 this.bindClose(); $('.jWVideoFrame').click(function(e) { var e = e || window.event; e.stopPropagation(); }); var This = this; var player_options = { controls: true, autoplay: true, preload: 'none', playbackRates: [0.5, 1, 1.5, 2], "fluid": true, sources: [{ "src": This.jWUrl, "type": "video/mp4", "label": "default" }], aspectRatio: "16:9", muted: false, plugins: {}, "language": window["videojsLanguage"], "loop": false }; if (isIE891011()) { player_options.plugins["videoJsResolutionSwitcher"] = { "default": 'low', // Default resolution [{Number}, 'low', 'high'], dynamicLabel: true }; //player_options["techOrder"] = ["flash", "html5"]; } if (videojs.getPlugin && videojs.getPlugin("vjsdownload")) { player_options.plugins["vjsdownload"] = { beforeElement: 'playbackRateMenuButton', textControl: 'Download video', name: 'downloadButton', downloadURL: This.opts.downloadPath }; } var player = videojs.getPlayers()[playerid]; if (player) player.dispose(); //调用接口 var player = videojs(playerid, player_options); console.log(player); // aspectRatio: "16:9" // autoplay: true // controls: true // fluid: true // language: "zh-CN" // loop: false // muted: false // plugins: {vjsdownload: {…}} // poster: "../images/homeVideoBg.jpg" // preload: "none" // sources: [{…}] if (videojs.getComponent('QualitySelector')) { player.controlBar.addChild('QualitySelector', { text: 'Quality', }); } if (player.ga) player.ga(); player.on('play', function(e) { This.pausePlayVideo(true); This.videomask.trigger("play"); $(".vjs-big-play-button").hide() }); player.on('pause', function(e) { This.pauseVideo(true); This.videomask.trigger("pause"); $(".vjs-big-play-button").show() }); player.on('canplaythrough', function(e) { This.videomask.trigger("readyPlay"); //隐藏下载按钮 $(".vjs-vjsdownload.vjs-control.vjs-button").hide(); }); player.on('ended', function(e) { This.pauseVideo(true); This.videomask.trigger("complete"); $(".vjs-big-play-button").show() }); player.on('volumechange', function(e) { This.videomask.trigger("volumeChange") }); // 定时器,计算当前播放时间,如果播放时间到了指定的时间段,弹框显示。时间固定1/3播放位置。需求人:星成发 // clearInterval(playBox.timer) // playBox.timer = setInterval(function() { // if (parseInt(player.currentTime()) > player.duration() * 0.33 && This.opts.specifytimepopup == 1 && $('.jWVideoFrame').find(".specifytimepopup").length == 0) { // alert("弹框") // } // }, 1000); this.player = player; }; //分享功能 playBox.prototype.initShare = function() { //含有分享 this.shareGroup = $("
") this.shareWrapBox = $("
") $('.jWVideoFrame').append(this.shareGroup); this.shareGroup.append(this.shareWrapBox) if (this.opts.downloadPath) { if (!this.opts.shareFunc) { this.shareWrapBox.append(""); } else { this.shareWrapBox.append(""); } } if (this.opts.shareFunc) { this.shareBox = $("
") this.shareWrapBox.append(this.shareBox); if (!this.shareBox.share) { alert("not find share function"); } else { this.shareBox.share({ sites: this.opts.shareFunc.split(","), url: this.opts.shareUrl, title: this.opts.shareTitle, description: this.opts.shareDescription, image: this.opts.shareImg }) } } } playBox.prototype.bindClose = function() { var This = this; This.close.off("click.video").on('click.video', function(e) { var e = e || window.event; e.stopPropagation(); This.closeVideo(); }); This.videomask.off("click.video").on('click.video', function(e) { var e = e || window.event; e.stopPropagation(); This.closeVideo(); }); }; playBox.prototype.bindEvent = function() { var This = this; This.statusBtn.off('click.video').on('click.video', function(e) { if (This.btn.hasClass("playing")) { This.pauseVideo(); return false; } else if (This.btn.hasClass("pause")) { This.pausePlayVideo(); return false; } }); }; /*关闭视频*/ playBox.prototype.closeVideo = function() { // ==S 清除当前播放时间的定时器 // clearInterval(playBox.timer) // ==E 清除当前播放时间的定时器 this.player && this.player.dispose(); this.player = null; if (this.opts.playInContent) { this.videomask.removeClass("playing"); } else { this.videomask.fadeOut(200); } this.videomask && this.videomask.off("click.video") this.close && this.close.off("click.video") this.statusBtn.off('click.video') this.btn && this.btn.removeClass("playing").removeClass("pause"); var remarkBtn = this.videomask.data("remark-btn"); if (remarkBtn) { remarkBtn.removeClass("playing"); } } /*暂停视频*/ playBox.prototype.pauseVideo = function(flag) { if (jWVideoFrameId && this.btn.hasClass("playing")) { if (!flag) { this.player.pause(); } this.videomask.removeClass("playing").addClass("pause"); this.btn.removeClass("playing").addClass("pause"); var remarkBtn = this.videomask.data("remark-btn"); if (remarkBtn) { remarkBtn.removeClass("playing").addClass("pause"); } } } /*暂停中恢复视频*/ playBox.prototype.pausePlayVideo = function(flag) { if (jWVideoFrameId && this.btn.hasClass("pause")) { if (!flag) { this.player.play(); } this.videomask.removeClass("pause").addClass("playing"); this.btn.removeClass("pause").addClass("playing"); var remarkBtn = this.videomask.data("remark-btn"); if (remarkBtn) { remarkBtn.removeClass("pause").addClass("playing"); } } } //窗口发生变化,执行函数 $(window).resize(function() { clearTimeout(playBox.prototype.timer); playBox.prototype.timer = setTimeout(function() { if (playBox.prototype.preVideo) { playBox.prototype.preVideo.reset() } }, 200); }); //默认参数,这些参数只是为了不报错 var defaluts = { 'videomask': '.videomask', 'close': '.videomask .icon-close', wrapSize: 750 }; function loadPlugin() { //åˆ†äº«æ ·å¼ if ($("#linkVideoShareStyle").length == 0) { if (supportPreload()) { $('').prependTo("head"); } else { $('').prependTo("head"); } } // //分享jquery.share.js // if (!$.fn.share) { // var script = document.createElement("script"); // $("body").append(script); // script.src = "/Assets/enp/v2/js/vendor/jquery.share.js" // } // //äºŒç»´ç  // if (!$.fn.qrcode) { // script = document.createElement("script"); // $("body").append(script); // script.src = "/Assets/enp/v2/js/vendor/jquery.qrcode-0.12.0.min.js" // } } jQuery.loadScript = function(url, options) { options = $.extend(options || {}, { dataType: "script", cache: true, url: url }); return jQuery.ajax(options); }; // ieåŠ è½½æ–¹å¼ function getVideoJs5() { $('').prependTo("head"); return jQuery.loadScript("//www.huawei.com/Assets/public/js/vendor/video-js-5.20.5/ie8/videojs-ie8.min.js") .then(function(d) { return jQuery.loadScript("//www.huawei.com/Assets/public/js/vendor/video-js-5.20.5/video.min.js"); }) .then(function(d) { videojs.options.flash.swf = "//www.huawei.com/Assets/public/js/vendor/video-js-5.20.5/video-js.swf"; jQuery.loadScript("//cdnjs.cloudflare.com/ajax/libs/videojs-ga/0.4.2/videojs.ga.min.js"); return jQuery.loadScript("//www.huawei.com/Assets/public/js/vendor/video-js-5.20.5/videojs-resolution-switcher.min.js"); }); } function getVideoJs7() { if (supportPreload()) { $('').prependTo("head"); } else { $('').prependTo("head"); } return jQuery.loadScript("//www.huawei.com/Assets/public/js/vendor/video-js-7.5.4/video.min.js") .then(function(d) { jQuery.loadScript("//cdnjs.cloudflare.com/ajax/libs/videojs-ga/0.4.2/videojs.ga.min.js"); jQuery.loadScript("//unpkg.com/videojs-vjsdownload@1.0.4/dist/videojs-vjsdownload.min.js"); return jQuery.loadScript("//www.huawei.com/Assets/public/js/vendor/video-js-7.5.4/silvermine-videojs-quality-selector.min.js"); }); } function loadVideoJs() { var videoFn = isIE891011() ? getVideoJs5 : getVideoJs7; videoFn().done(function(d) { bindClickPlay(); $("body").trigger("videojsReady") }); } var loadResource = false; if ($(".vedioplay,.J-videoPlay,.js_video_player").length) { loadPlugin() loadVideoJs(); loadResource = true; } else { $("body").off("click.play", '.vedioplay,.J-videoPlay,.js_video_player').on("click.play", '.vedioplay,.J-videoPlay,.js_video_player', function () { var $this = $(this) if (!loadResource) { loadPlugin(); loadVideoJs(); $("body").on("videojsReady.ready", function() { $this.trigger("click.play") $("body").off("videojsReady.ready") $this = null }) return; } }) } function bindClickPlay() { //点击需要播放的视频按钮,执行事件 $("body").off("click.play", '.vedioplay,.J-videoPlay,.js_video_player').on("click.play", '.vedioplay,.J-videoPlay,.js_video_player', function () { //不用弹框的开关 if ($(this).attr("data-play-nopop")) { return } var data = $(this).data(); data.url = $.trim(data.url) if (data.url) { // å·²//开头的链接 if (data.url.indexOf("//") == 0) { data.url = location.protocol + data.url } } else { return; } data.downloadPath = $.trim(data.downloadPath) var opts = $.extend({}, defaluts, { 'jWUrl': data.url, "downloadPath": $.trim(data.downloadPath), "shareFunc": $.trim(data.shareFunc), "shareUrl": $.trim(data.shareUrl), "shareTitle": data.shareTitle, "shareDescription": data.shareDescription, "shareImg": $.trim(data.shareImg), "content": data.content, "wapNoDialog": $.trim(data.wapnodialog), btn: $(this), "specifytimepopup": data.specifytimepopup // æŒ‡å®šäº‹ä»¶å¼¹æ¡†ï¼Œéœ€è¦ä»Žç»“æž„ä¸Šä¼ é€’ä¸€ä¸ªå‚æ•°ï¼Œå¦‚æžœè®¾ç½®ä¸º1就需要弹框,不设置或者设置为0就不弹框。默认不设置 }); opts.wrapSize = $(this).data("wrapsize") || $("body").data("wrapsize") || defaluts.wrapSize if (!$(this).data("lockplay") && !$(this).hasClass("playing")) { //newå‡ºæž„é€ å‡½æ•° new playBox().init(opts); } else { $(this).data("lockplay", false); } if (data.utag == "1") { $.ajax({ url: $("#hidUtagServiceUrl").val(), data: { pagetype: "video-detail-page", itemid: $("#hidVideoId").val(), lang: $("#gLanguageCurrent").val() }, async: false, success: function(utagdata) { var dwData = { tealium_event: "video_play", product_tag: utagdata.product_tag, solution_tag: utagdata.solution_tag, industry_tag: utagdata.industry_tag, c_email: utagdata.email, language: utagdata.language, content_id: utagdata.video_id, content_name: utagdata.video_name }; utag.link(dwData); } }); } return false; }) } });