function BcH5Player(){throw{msg:"Don't NEW a singleton."}}EventListener.apply(BcH5Player),function(e){function t(e,t){return"fplayer"+t+"-"+e}BcH5Player.init=function(i,l,n){if(this.chObj=i,null===this.chObj.getViewId())return;this.networkErrTime=3,this.isSettingCenter=!!n,this.h5playerWrapper=e(".h5_player_wrapper"),this.flashPlayerWrapper=e("#preview_plugin_container"),this.playbackUrlSet=[],this.timelineWalkTimer=null,this.jumpToEndBufferTimer=null,this.isloaded=!1;let a=!1;if(ControllerMain.isNvr){let e=i.getId();a=[6,4].includes(ControllerLogin.abilities.abilityChn[e].channelType.ver)||ControllerLogin.chkVersion("supportBinoStitch",1,e)}else a="FISHEYE"===ControllerMain.deviceInfo.exactType||"BELL"===ControllerMain.deviceInfo.type||ControllerLogin.chkVersion("supportBinoStitch",1,0);this.stretching=a?EnumFlvStretching.screen:EnumFlvStretching.exactfit,this.zeroSpeedCounts=0,this.stallWalkingCounts=0,this.seekTo=this.chObj.seekTo,this._streamType=void 0!==l?l:this.chObj.getStream(),this._initMode=this.chObj.getMode();let s=sessionStorage.getItem("volume");this._volume=s?parseInt(s,10)/100:0,this.infoElm={bshow:!1,elm:e("#bc-h5-watch"),elm_close:e("#bc-h5-watch-close"),elm_loader:e("#bc-h5-watch-loader"),elm_player:e("#bc-h5-watch-player"),elm_meta:e("#bc-h5-watch-meta"),elm_cursegidx:e("#bc-h5-watch-cursegidx"),elm_drops:e("#bc-h5-watch-drops"),elm_decode:e("#bc-h5-watch-decode"),elm_corrupt:e("#bc-h5-watch-corrupt"),elm_speed:e("#bc-h5-watch-speed"),elm_segcount:e("#bc-h5-watch-segcount"),elm_url:e("#bc-h5-watch-url"),elm_current:e("#bc-h5-watch-current"),elm_sbstart:e("#bc-h5-watch-sbstart"),elm_sbend:e("#bc-h5-watch-sbend"),elm_fixes:e("#bc-h5-watch-fixes"),elm_err:e("#bc-h5-watch-err")},this.h265NotSupport="Current device won't support video streaming in clear mode. Now it is streaming in other mode.";try{if(console.dbg("------ Run H5 player ------"),this.h5playerWrapper.removeClass("hide").removeClass("vis-hide"),this.flashPlayerWrapper.addClass("hide"),this._initMode===EnumCurState.PLAYBACK&&!ControllerMain.isNvr){var r=this.chObj.url?this.chObj.url.replace(/&encrypt=[^&]*/g,"").replace(/&flagO=[^&]*/g,"").replace(/&countIdO=[^&]*/g,"").replace(/&checkNumO=[^&]*/g,""):"",o=this.playUrl?this.playUrl.replace(/&encrypt=[^&]*/g,"").replace(/&flagO=[^&]*/g,"").replace(/&countIdO=[^&]*/g,"").replace(/&checkNumO=[^&]*/g,""):"";if(this.flv_player&&r===o)return this.$liveVideo[0].currentTime=this.chObj.seekTo,void this.$liveVideo[0].play()}var h;void 0!==this.flv_player&&null!==this.flv_player&&this.destroy(),e("#osd-player .h5_player_wrapper").remove(),e("#motion-player .h5_player_wrapper").remove(),e("#"+t(0,"PREVIEW")).remove(),e("#"+t(0,"PLAYBACK")).remove(),this.isSettingCenter?(e(n).append('
'),this.h5playerWrapper=e(n).find(".h5_player_wrapper"),h=this.h5playerWrapper):(this.h5playerWrapper.append('
'),e("#"+t(0,this._initMode)).css({position:"relative","z-index":"99",height:"1200px"}),h=e("#"+t(0,this._initMode)));let l=!1;if(ControllerMain.isNvr){let e=i.getId();l=[6,4].includes(ControllerLogin.abilities.abilityChn[e].channelType.ver)||ControllerLogin.chkVersion("supportBinoStitch",1,e)}else l="FISHEYE"===ControllerMain.deviceInfo.exactType||"BELL"===ControllerMain.deviceInfo.type||ControllerLogin.chkVersion("supportBinoStitch",1,0);h.append(`
`),h.append('\n
\n
\n \n
\n
\n '),ViewPtz3DLocation.refreshEventListener();var c=this,u=[{text:"Show Media Info",icon:"",alias:"1-1",action:function(){c.showInfo(!0)}},{type:"splitLine"},{text:"reolink player V1.0.0.1",icon:"",alias:"1-2",action:function(){}}];if(e(".bc-h5_player").contextmenu({width:350,items:u,onContextMenu:!0,onShow:!0,alias:"h5-context"}),this.statusImg=this.h5playerWrapper.find(".status-box"),this.disconnectImg=this.h5playerWrapper.find(".bc-h5_disconnect"),this.nofileImg=this.h5playerWrapper.find(".bc-h5_nofile"),this.loadingImg=this.h5playerWrapper.find(".bc-h5_loading"),this.$liveVideo=this.h5playerWrapper.find(".bc-h5_player"),this.$liveCanplay=this.h5playerWrapper.find(".bc-h5_canplay"),this._initMode===EnumCurState.PLAYBACK){this.showStatusImg(EnumFlvStatus.normal);var m=ControllerMain.isNvr?"flv":"mp4";if(this.mediaDataSource={type:m,isLive:!1,hasAudio:!0,hasVideo:!0},ViewReplaySearch.getUsingDay()&&this.chObj.playingDay!=ViewReplaySearch.getUsingDay().getUnixDateOnly()||this.chObj.playingStream!=ViewReplaySearch.getSelectedStream())return void this.destroy();var p=g_device.channels[this.chObj.getId()];if(0==p.playbackFiles.length||!p.playbackFiles[this.chObj.playingFile])return void this.nofile();ControllerMain.isNvr&&(this.mediaDataSource.duration=p.playbackFiles[this.chObj.playingFile].duration-1e3*this.chObj.seekTo),this.flv_load(),PlayerPlayback.updateState(EnumPBPlayState.PLAYING);var d=ControllerMain.isNvr?"play_next":"ended";this.$liveVideo.on(d,(function(){var e;if(c.getMode()!==EnumCurState.PLAYBACK||ViewReplaySearch.getUsingDay()&&c.chObj.playingDay!=ViewReplaySearch.getUsingDay().getUnixDateOnly()||c.chObj.playingStream!=ViewReplaySearch.getSelectedStream())c.destroy();else{var t=g_device.channels[c.chObj.getId()];t.playbackFiles.length>++c.chObj.playingFile?(e=t.playbackFiles[c.chObj.playingFile],ViewReplaySearch.seek(e.startTime)):c.nofile()}}))}else this.mediaDataSource={type:"flv",isLive:!0,hasAudio:!0,hasVideo:!0},this.flv_load()}catch(e){console.error(e)}},BcH5Player.getStream=function(){return this._streamType},BcH5Player.setStream=function(e){this._streamType=e},BcH5Player.getMode=function(){return this.chObj.getMode()},BcH5Player.getChannel=function(){return this.chObj.getId()},BcH5Player.getViewStatus=function(){return ViewManager.getViewObject(this.chObj.getViewId()).getStatus()},BcH5Player.show=function(){this.$liveVideo.show()},BcH5Player.setPosition=function(){try{var i=ViewManager.getViewObject(this.chObj.getViewId()).getClientArea();e("#"+t(0,this.getMode())).css({height:i.height,width:i.width,left:i.left,top:i.top}),ViewPtz3DLocation.updateLocationDrawArea(BcH5Player.isExactFit())}catch(e){return}},BcH5Player.isExactFit=function(){return this.stretching==EnumFlvStretching.exactfit},BcH5Player.setExactFit=function(e){e?(this.stretching=EnumFlvStretching.exactfit,this.$liveVideo.addClass("h5_video-fill")):(this.stretching=EnumFlvStretching.screen,this.$liveVideo.removeClass("h5_video-fill"))},BcH5Player.showStatusImg=function(e){try{switch(this.statusImg.hide(),e){case EnumFlvStatus.loading:this.loadingImg.show();break;case EnumFlvStatus.disconnect:this.disconnectImg.show();break;case EnumFlvStatus.nofile:PlayerPlayback.trigger("pauseAllStream"),this.nofileImg.show()}EnumFlvStatus.normal!==e?(-1!==ChannelManager.get3DLocationOnChId()&&ChannelManager.trigger("update3DLocationOnChId",[-1]),ChannelManager.trigger("playing",[-1])):ChannelManager.trigger("playing",[this.chObj.getId()])}catch(e){return}},BcH5Player.jumpToEndBuffer=function(){if(this.flv_player){var e=this.$liveVideo[0],t=e.buffered;if(t.length>0){var i,l=t.start(0),n=t.end(t.length-1),a=n-e.currentTime;if(this.getStream()===EnumStreamType.FLUENT||this.getStream()===EnumStreamType.CLIP){if(a<2.3)return;i=(l+n)/2>n-1.8?(l+n)/2:n-1.8}else{if(a<1.3)return;i=(l+n)/2>n-.8?(l+n)/2:n-.8}e.currentTime=i,e.play(),console.dbg("delay "+a+"s, reset currentTime: "+e.currentTime+" endTime: "+n)}}},BcH5Player.resetRetardation=function(){if(clearTimeout(this.jumpToEndBufferTimer),this.flv_player&&this.getMode()!==EnumCurState.PLAYBACK){var e=this;this.jumpToEndBufferTimer=setTimeout((function(){e.jumpToEndBuffer(),e.resetRetardation()}),3e4)}},BcH5Player.flv_init=function(){this.isloaded=!1,this.zeroSpeedCounts=0,this.stallWalkingCounts=0,clearTimeout(this.timelineWalkTimer),this.timelineWalkTimer=null,clearTimeout(this.jumpToEndBufferTimer),this.jumpToEndBufferTimer=null,this.showStatusImg(EnumFlvStatus.loading)},BcH5Player.flv_load=function(){this.show();if(this._initMode===EnumCurState.PLAYBACK){var e=g_device.channels[this.chObj.getId()];this.playUrl=ControllerMain.isNvr?this.chObj.url:PlayerPlayback.constructH5Url(this.chObj.getId(),e.playbackFiles[this.chObj.playingFile].fileName)}else this.playUrl=PlayerPreview.constructRTMPUrl(this.chObj.getId(),this._streamType);this.mediaDataSource.url=this.playUrl,this.flv_load_mse()},BcH5Player.flv_load_mse=function(){var e=this,t={};void 0!==this.flv_player&&null!=this.flv_player&&this.destroy(),this.mediaDataSource.isLive?t={enableWorker:!1,enableStashBuffer:!1,autoCleanupSourceBuffer:!0}:ControllerMain.isNvr&&(t={enableStashBuffer:!1}),this.flv_init(this.metadata),this.flv_player=flvjs.createPlayer(this.mediaDataSource,t),this.flv_player.attachMediaElement(this.$liveVideo[0]),this.mediaDataSource.isLive?(this.flv_player.on(flvjs.Events.ERROR,(function(t,i,l){e.updateErrinfo(i,l),e.zeroSpeedCounts=0,e.showStatusImg(EnumFlvStatus.disconnect),e.trigger("statechange",[e,EnumChannelStatus.CLOSED,EnumViewStatus.ERROR])})),this.flv_player.on(flvjs.Events.METADATA_ARRIVED,(function(t){12===t.videocodecid&&ControllerMain.isNvr?(bc_alert(e.h265NotSupport,"error"),setTimeout((function(){e.destroy();const t=ControllerLogin.abilities.abilityChn[e.chObj.getId()]&&2!==ControllerLogin.abilities.abilityChn[e.chObj.getId()].live.ver,i=e.chObj.getStream();if(i===EnumStreamType.FLUENT||i===EnumStreamType.TRACK_FLUENT)return e.showStatusImg(EnumFlvStatus.disconnect),void e.trigger("statechange",[e,EnumChannelStatus.CLOSED,EnumViewStatus.ERROR]);const l=i===EnumStreamType.TRACK_CLEAR?EnumStreamType.TRACK_FLUENT:t?EnumStreamType.BALANCED:EnumStreamType.FLUENT;PlayerPreview.trigger("playAllStream",[l])}),500)):e.isloaded?e.flv_load():(e.showStatusImg(EnumFlvStatus.normal),e.isloaded=!0)}))):(this.flv_player.on(flvjs.Events.ERROR,(function(t,i,l){e.updateErrinfo(i,l)})),ControllerMain.isNvr&&this.flv_player.on(flvjs.Events.METADATA_ARRIVED,(function(t){12===t.videocodecid&&(bc_alert(e.h265NotSupport,"error"),setTimeout((function(){e.destroy();const t=e.chObj.getStream();if(t===EnumStreamType.FLUENT||t===EnumStreamType.TRACK_FLUENT)return e.showStatusImg(EnumFlvStatus.disconnect),void e.trigger("statechange",[e,EnumChannelStatus.CLOSED,EnumViewStatus.ERROR]);const i=t===EnumStreamType.TRACK_CLEAR?EnumStreamType.TRACK_FLUENT:EnumStreamType.FLUENT;PlayerPlayback.trigger("playAllStream",[i])}),500))})),this.flv_player.on(flvjs.Events.LOADING_COMPLETE,(function(){console.dbg("[flv pb buffered completed]: "+e.flv_player.buffered),console.dbg("[flv pb duration]: "+e.flv_player.duration)}))),this.$liveVideo.one("canplay",(function(){isOldEdge()&&e.mediaDataSource.isLive&&(e.getStream()===EnumStreamType.FLUENT||e.getStream()===EnumStreamType.CLIP)?setTimeout((function(){e.flv_player.currentTime=0}),1e3):ControllerMain.isNvr||!isSafari()||e.mediaDataSource.isLive||(e.$liveVideo[0].currentTime=e.chObj.seekTo),e.$liveVideo.paused?e.$liveCanplay.show():e.play(),e.setVolume(e._volume)})),this.$liveCanplay.one("click",(function(){e.play()}));const i=2*this.networkErrTime;this.flv_player.on(flvjs.Events.STATISTICS_INFO,(function(t){e.updateStatinfo(t),0!==t.speed?(e.zeroSpeedCounts=0,e.showStatusImg(EnumFlvStatus.normal),e.isSettingCenter||e.getViewStatus()!=EnumViewStatus.PLAYING&&e.getViewStatus()!=EnumViewStatus.PAUSED&&e.trigger("statechange",[e,EnumChannelStatus.PLAYING,EnumViewStatus.PLAYING])):(++e.zeroSpeedCounts,e.zeroSpeedCounts>=i&&(e.showStatusImg(EnumFlvStatus.loading),e.isSettingCenter||e.getViewStatus()!=EnumViewStatus.BUFFERING&&e.getViewStatus()!=EnumViewStatus.PAUSED&&e.trigger("statechange",[e,EnumChannelStatus.PLAYING,EnumViewStatus.BUFFERING])))})),this.flv_player.on(flvjs.Events.MEDIA_INFO,(function(t){e.updateMediainfo(t)})),this.flv_player.load(),this.trigger("statechange",[this,EnumChannelStatus.PLAYING,EnumViewStatus.BUFFERING]),this.setPosition();let l=ControllerMain.isNvr?0:this.seekTo;this.flv_seekto(l),this.mediaDataSource.isLive||this.activeTimeline(),this.infoElm.elm_close.click((function(){e.showInfo(!1)}))},BcH5Player.handleMedia=function(e){},BcH5Player.play=function(e){void 0!==this.flv_player&&null!==this.flv_player||this.flv_load();let t=this.flv_player.play();if(void 0!==t){var i=this;t.then((function(){i.flv_player.play()}))}this.setVolume(this._volume),this.trigger("statechange",[this,EnumChannelStatus.PLAYING,EnumViewStatus.PLAYING]),this.$liveCanplay.remove(),this.resetRetardation()},BcH5Player.pause=function(e){this.getMode()===EnumCurState.PLAYBACK?(this.flv_player&&this.flv_player.pause(),this.trigger("statechange",[this,EnumChannelStatus.PLAYING,EnumViewStatus.PAUSED]),this.showStatusImg(EnumFlvStatus.pause)):this.stop()},BcH5Player.stop=function(e){this.destroy(),this.showStatusImg(EnumFlvStatus.stop)},BcH5Player.nofile=function(){this.destroy(),this.showStatusImg(EnumFlvStatus.nofile)},BcH5Player.destroy=function(e){this.flv_player&&(this.showInfo(!1),this.flv_player.pause(),this.flv_player.unload(),this.flv_player.detachMediaElement(),this.flv_player.destroy(),this.flv_player=null,clearTimeout(this.timelineWalkTimer),this.timelineWalkTimer=null,clearTimeout(this.jumpToEndBufferTimer),this.jumpToEndBufferTimer=null,this.trigger("statechange",[this,EnumChannelStatus.CLOSED,EnumViewStatus.CLOSED]))},BcH5Player.setVolume=function(e){"number"==typeof e&&(this._volume=e,this.flv_player&&(this.flv_player.volume=this._volume),0!==e&&(this.$liveVideo[0].muted=!1,this.$liveVideo.removeAttr("muted")))},BcH5Player.activeTimeline=function(){if(!this.flv_player||this.getMode()!==EnumCurState.PLAYBACK)return void clearTimeout(this.timelineWalkTimer);const e=2*this.networkErrTime;var t=this.$liveVideo[0].currentTime+this.seekTo,i=this;this.timelineWalkTimer&&clearTimeout(this.timelineWalkTimer),this.timelineWalkTimer=setTimeout((function(){var l=i.$liveVideo[0].currentTime+i.seekTo;i.trigger("walking",[i,l]),i.getViewStatus()!==EnumViewStatus.PAUSED&&parseInt(l)===parseInt(t)&&i.flv_player&&(isNaN(i.flv_player.duration)||i.flv_player.currentTime>=i.flv_player.duration-4)?(++i.stallWalkingCounts,i.stallWalkingCounts>e?i.$liveVideo.trigger("play_next"):i.activeTimeline()):(i.stallWalkingCounts=0,i.activeTimeline())}),500)},BcH5Player.flv_seekto=function(e){var t=e||0;this.$liveVideo[0].currentTime=parseFloat(t),ControllerMain.isNvr||(this.seekTo=0)},BcH5Player.isInfoshow=function(){return null!=this.infoElm&&null!=this.infoElm.elm&&this.infoElm.bshow},BcH5Player.showInfo=function(e){null!=this.infoElm&&null!=this.infoElm.elm?e?(this.infoElm.elm.show(),this.infoElm.bshow=!0):(this.infoElm.elm.hide(),this.infoElm.bshow=!1):console.dbg("null ptr")},BcH5Player.updateMediainfo=function(e){null!==this.infoElm&&null!==this.infoElm.elm&&this.infoElm.bshow&&null!=this.infoElm.elm_meta&&this.infoElm.elm_meta.text(JSON.stringify(e.metadata))},BcH5Player.updateStatinfo=function(e){null!==this.infoElm&&null!==this.infoElm.elm&&this.infoElm.bshow&&(null!=this.infoElm.elm_loader&&this.infoElm.elm_loader.text(e.loaderType),null!=this.infoElm.elm_player&&this.infoElm.elm_player.text(e.playerType),null!=this.infoElm.elm_cursegidx&&this.infoElm.elm_cursegidx.text(e.currentSegmentIndex),null!=this.infoElm.elm_drops&&this.infoElm.elm_drops.text(e.droppedFrames),null!=this.infoElm.elm_decode&&this.infoElm.elm_decode.text(e.decodedFrames),null!=this.infoElm.elm_corrupt&&this.infoElm.elm_corrupt.text(e.corruptedFrames),null!=this.infoElm.elm_speed&&this.infoElm.elm_speed.text(e.speed+"KBps"),null!=this.infoElm.elm_segcount&&this.infoElm.elm_segcount.text(e.totalSegmentCount),null!=this.infoElm.elm_current&&this.infoElm.elm_current.text(e.current),null!=this.infoElm.elm_sbstart&&this.infoElm.elm_sbstart.text(e.sbStart),null!=this.infoElm.elm_sbend&&this.infoElm.elm_sbend.text(e.sbEnd),null!=this.infoElm.elm_fixes&&this.infoElm.elm_fixes.text(e.fixes),null!=this.infoElm.elm_url&&this.infoElm.elm_url.text(e.url))},BcH5Player.updateErrinfo=function(e,t){console.dbg("errorDetail:",e),console.dbg("errorInfo:",t),null!==this.infoElm&&null!==this.infoElm.elm&&this.infoElm.bshow&&null!=this.infoElm.elm_err&&this.infoElm.elm_err.text(JSON.stringify(e)+JSON.stringify(t))}}(jQuery);