var hstVideoAll = { init: function (domId, width, height, params, playerType) { var path = this.getPath(); this.playerPath = path + '../Content/play_media_stream.swf'; this.domId = domId; this.width = width; this.height = height; this.version = '11.0.0'; this.params = params; this.windownum = 4; if (playerType === 'flash' || playerType === 'h5') { this.playerType = playerType; } //if (this.isBrowseIE()) { // this.playerType = 'flash'; //} if (!this.playerType && localStorage.playerType && localStorage.playerType === 'flash') { this.playerType = 'flash'; } if (this.playerType === 'flash') { this.loadJs(path + "swfobject.js"); } else { this.loadCss(path + "../css/DPlayer.min.css"); this.loadCss(path + "../css/swfobject-h5.css"); this.loadJs(path + "flv.min.js"); this.loadJs(path + "DPlayer.min.js"); this.loadJs(path + "swfobject-h5.js"); this.loadJs(path + "md5.js"); this.loadJs(path + "HZRecorder.js"); this.loadJs(path + "HZPlayer.js"); } this.initTimer(); }, initTimer: function () { if (hstVideoAll.playerType == 'flash') { if (typeof swfobject == "undefined") { setTimeout(this.initTimer, 300) } else { swfobject.embedSWF(hstVideoAll.playerPath, hstVideoAll.domId, hstVideoAll.width, hstVideoAll.height, "11.0.0", null, null, hstVideoAll.params, null); playerobject = swfobject.getObjectById(hstVideoAll.domId); } } else { if (typeof HstH5Video == "undefined") { setTimeout(this.initTimer, 300) } else { var options = { domId: hstVideoAll.domId, width: hstVideoAll.width, height: hstVideoAll.height }; if (hstVideoAll.params.lang) { options.lang = hstVideoAll.params.lang } playerobject = new HstH5Video(options); } } }, setWindowCount: function (num) { if (!num) { return; } num = parseInt(num); hstVideoAll.windownum = num; this.setWindowNum(); }, setWindowNum: function(){ if (typeof playerobject == "undefined") { setTimeout(this.setWindowNum, 300) } else{ if (hstVideoAll.playerType == 'flash') { playerobject.ActionScriptSetWindowsCount(hstVideoAll.windownum); } else{ playerobject.setWindowNum(hstVideoAll.windownum); } } }, openVideo: function(server,port,devicechannel){ if (hstVideoAll.playerType == 'flash') { playerobject.ActionScriptPlayStream(server,port,devicechannel); } else{ playerobject.openVideo(server,port,devicechannel); } }, closeVideo: function(devicechannel){ if (hstVideoAll.playerType == 'flash') { playerobject.ActionScriptClosePlayStream(devicechannel); } else{ playerobject.closeVideo(devicechannel); } }, JsStartTalk: function(MediaServerName,MediaTCPPort, VoiceTCPPort,deviceId, channelId, MediaType,username,password){ if (hstVideoAll.playerType == 'flash') { playerobject.JsStartTalk(MediaServerName,MediaTCPPort, deviceId, channelId, MediaType); } else{ //playerobject.closeVideo(devicechannel); playerobject.StartTalk(MediaServerName,MediaTCPPort, VoiceTCPPort,deviceId, channelId, MediaType,username,password); } }, JsStartMonitor: function(MediaServerName,MediaTCPPort, VoiceTCPPort,deviceId, channelId, MediaType,username,password){ if (hstVideoAll.playerType == 'flash') { playerobject.JsStartMonitor(MediaServerName,MediaTCPPort, deviceId, channelId, MediaType); } else{ //playerobject.closeVideo(devicechannel); playerobject.StartMonitor(MediaServerName,MediaTCPPort, VoiceTCPPort,deviceId, channelId, MediaType,username,password); } }, JsStartBroadcast: function(MediaServerName,MediaTCPPort,VoiceTCPPort,type,username,password){ if (hstVideoAll.playerType == 'flash') { playerobject.JsStartBroadcast(MediaServerName,MediaTCPPort, type); } else{ //playerobject.closeVideo(devicechannel); playerobject.StartBroadcast(MediaServerName, VoiceTCPPort, type, username, password); } }, JsCloseTalk: function(deviceId, channelId){ if (hstVideoAll.playerType == 'flash') { playerobject.JsCloseTalk(deviceId, channelId); } else{ playerobject.CloseTalk(deviceId, channelId); } }, JsCloseMonitor: function(deviceId, channelId){ if (hstVideoAll.playerType == 'flash') { playerobject.JsCloseMonitor(deviceId, channelId); } else{ playerobject.CloseMonitor(deviceId, channelId); } }, JsCloseBroadcast: function(){ if (hstVideoAll.playerType == 'flash') { playerobject.JsCloseBroadcast(); } else{ playerobject.CloseBroadcast(); } }, StartRemotePlayback: function(server,port,devicechannel,starttime,endtime,callback){ if (hstVideoAll.playerType == 'flash') { playerobject.JavaScriptStartRemotePlayback(server,port,devicechannel,starttime,endtime,2); } else{ playerobject.StartRemotePlayback(server,port,devicechannel,starttime,endtime,callback); } }, CloseRemotePlayback: function(devicechannel){ if (hstVideoAll.playerType == 'flash') { playerobject.JavaScriptCloseRemotePlayback(devicechannel); } else{ playerobject.CloseRemotePlayback(devicechannel); } }, getPath: function () { var scripts = document.getElementsByTagName('script') for (let i = 0; i < scripts.length; i++) { var src = scripts[i].src; if (src.indexOf('swfobject-all.js') > -1) { return src.replace(/[^\/]+$/, ""); } } return ''; }, switchType: function (playerType) { if (this.isBrowseIE() && playerType != 'flash') { alert('ie浏览器只支持flash播放') return; } if (playerType !== 'flash' && playerType !== 'h5' && playerType !== 'auto') { return; } localStorage.playerType = playerType location.reload() }, isBrowseIE: function () { return (this.getBrowseVersion().indexOf("msie") != -1) ? true : false; }, getBrowseVersion: function () { var userAgent = navigator.userAgent.toLowerCase(); var browser = userAgent.match(/(firefox|chrome|safari|opera|msie)/); var browserId = "msie"; var browserVersion = ""; var isIE11 = (userAgent.toLowerCase().indexOf("trident") > -1 && userAgent.indexOf("rv") > -1); if (isIE11) { browserId = "msie"; browserVersion = "11.0"; } else { if (browser.length >= 2) { browserId = browser[1]; } else { browserId = "msie"; } browserVersion = (userAgent.match(new RegExp('.+(?:version)[\/: ]([\\d.]+)')) || userAgent.match(new RegExp('(?:' + browserId + ')[\/: ]([\\d.]+)')) || [0, '0'])[1]; } return browserId + browserVersion; }, loadCss: function (path) { if (!path || path.length === 0) { throw new Error('argument "path" is required !'); } var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.href = path; link.rel = 'stylesheet'; link.type = 'text/css'; head.appendChild(link); }, loadJs: function (path) { if (!path || path.length === 0) { throw new Error('argument "path" is required !'); } var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.src = path; script.type = 'text/javascript'; head.appendChild(script); } }