filesbox/web/dist/design/designstatic/chatroom/video/playerreview.js
2024-07-26 14:10:54 +08:00

2 lines
12 KiB
JavaScript

var player,isLive=!1,autoplay=!1,videoPlayer,showControls=!1,speed=[.75,1,1.25,1.5],playerList=[],flvplayerList=[],createList=[],createing=!1,onlineCameraIndex=0,onlineIndex=0,playHistory=[],onlineTime,camTime,isSettingSwf=!1,refreshCount=0,isFull=!1,isAddLise=!1,audioId,playseek=0,isSetSeeked=!1,seekId,needSeek=!1,errorCount=0,intervalId=null,RECONNECT_TIME=4e3,onlineStatus="",onlineCameraStatus="",isShowAutoTip=!1;function createPlayer(t,e,n,r,a,l,i,s){if(t==null||t==null||t==""){console.log("\u64AD\u653E\u5668Id\u4E0D\u80FD\u4E3A\u7A7A");return}var c=$("#"+t),o=null;return c.length==0&&(o=document.createElement("VIDEO"),o.id=t),o}var flashChecker=function(){var t=/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent);if(t)return window.localStorage.setItem("isFlashPlayerError",1),{f:0,v:0};var e=0,n=0;if(document.all){var r=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");r&&(e=1,VSwf=r.GetVariable("$version"),n=parseInt(VSwf.split(" ")[1].split(",")[0]))}else if(navigator.plugins&&navigator.plugins.length>0){var r=navigator.plugins["Shockwave Flash"];if(r){e=1;for(var a=r.description.split(" "),l=0;l<a.length;++l)isNaN(parseInt(a[l]))||(n=parseInt(a[l]))}}return{f:e,v:n}},errorcallback;function init(t,e,n){var r={id:"",url:"",lang:"zh-cn",volume:.8,isLive:!1,playsinline:!0,whitelist:[""],autoplay:!0,fluid:!0,"x5-video-player-type":"h5","x5-video-player-fullscreen":"true","x5-video-orientation":"landscape",screenShot:!1,closeVideoClick:!0,closeVideoDblclick:!0,closeVideoTouch:!0,closePlayerBlur:!0,playbackRate:[.5,.75,1,1.5,2],defaultPlaybackRate:1,controls:!0,poster:""};r=extend(r,t,!0);var a=r.id;if(this["player"+a]=n?new FlvJsPlayer(r):new HlsJsPlayer(r),playerList.push(this["player"+a]),a==="online"){this["player"+a].on("ended",function(i){liveObj.cameraBackState(0,!1)}),this["player"+a].on("playbackrateChange",function(i){reviewWhiteSynCamera(a,"ratechange",i.to)}),this["player"+a].on("error",function(i){liveObj.cameraBackState(0,!0)}),this["player"+a].on("play",function(i){reviewWhiteSynCamera(a,"play")}),this["player"+a].on("stop",function(i){});var l=0;this["player"+a].on("timeupdate",function(i){try{var s=$("#online video")[0].currentTime;Math.abs(s-l)>1&&reviewWhiteSynCamera(a,"timeupdate"),l=s}catch(c){}}),this["player"+a].on("pause",function(i){reviewWhiteSynCamera(a,"pause")}),this["player"+a].on("playing",function(i){}),this["player"+a].on("waiting",function(i){})}this["player"+a].once("ready",()=>{e&&e()})}function reviewWhiteSynCamera(t,e,n){try{var r=window.location.href;if(r.indexOf("review.html")===-1)return;var a=getxgPlayer("onlineCamera");if(!a)return;switch(e){case"play":{a.play();break}case"pause":{a.pause();break}case"timeupdate":{$("#onlineCamera video")[0].currentTime=$("#online video")[0].currentTime;break}case"ratechange":{$("#onlineCamera video")[0].playbackRate=n;break}default:break}}catch(l){console.log("\u56DE\u770B\u540C\u6B65\u64CD\u4F5C\u5931\u8D25:",l)}}function changeMedia(){window.localStorage.setItem("isFlashPlayerError",1),location.reload()}function removeCreateListById(t){for(var e=0;e<createList.length;e++)createList[e].id===t&&createList.splice(e,1);createList.length>0&&init(createList[0].id,createList[0].playerType,createList[0].url,createList[0].isLive,createList[0].autoplay,createList[0].showControls,createList[0].thumbUrl,createList[0].callback)}var settingList=[],issettingURL=!1;function _setVideoUrl(t,e){issettingURL=!0;var n=e.split("?"),r=n[0];appU=r.split("/");var a=appU[appU.length-1],l=a.split("."),i="rtmp/flv";switch(l[l.length-1]){case"m3u8":i="application/x-mpegURL";break;case"flv":isLive=!0,i="rtmp/flv";break;case"mp4":i="video/mp4";break}getPlayer(t).src({src:e,type:i})}var volumeNumber=1,flashIsAdd=!1,flashErrorCount=0;function callJS(t,e){if(flashIsAdd=!0,t.search("online")>-1||t.search("interaction")>-1)switch(e){case"NetConnection.Connect.Success":break;case"NetConnection.Connect.Failed":t.search("onlineCamera")>-1?liveObj.cameraBackState(1,!0):t.search("interaction")>-1?getPlayer("online").hasOwnProperty("_type")&&getPlayer("online")._type==="FlvPlayer"?getPlayer("online").muted=!1:getPlayer("online").techCall_("setMuted",!1):(errorCount++,$(".full_screen").length>0&&$(".full_screen").attr("isPlay","0"),$(".setting_btn").length>0&&$(".setting_btn").attr("isPlay","0"),$(".size_btn").length>0&&$(".size_btn").attr("isPlay","0"),$("#sizePanel").length>0&&$(".size_btn").attr("isPlay","0"),$("#noSreamMessage").length>0&&($("#noSreamMessage")[0].style.display=""),liveObj&&errorCount>10&&liveObj.cameraBackState(0,!0),currentSize=1,$("#sizeText").val(Math.round(currentSize*100)),changeOnlieSize(300,300));break;case"NetConnection.Connect.Closed":t.search("onlineCamera")>-1?liveObj.cameraBackState(1,!0):t.search("interaction")>-1?getPlayer("online").techCall_("setMuted",!1):(errorCount++,intervalId==null&&(intervalId=window.setInterval(function(){errorCount>50&&($("#dnsError").show(),window.clearInterval(intervalId),intervalId=0)},1e4)),$(".full_screen").length>0&&$(".full_screen").attr("isPlay","0"),$(".setting_btn").length>0&&$(".setting_btn").attr("isPlay","0"),$(".size_btn").length>0&&$(".size_btn").attr("isPlay","0"),$("#sizePanel").length>0&&$(".size_btn").attr("isPlay","0"),$("#noSreamMessage").length>0&&($("#noSreamMessage")[0].style.display=""),currentSize=1,liveObj&&errorCount>10&&liveObj.cameraBackState(0,!0),$("#sizeText").val(Math.round(currentSize*100)),changeOnlieSize(300,300));break;case"NetConnection.Connect.Rejected":break;case"NetStream.Play.Stop":break;case"NetStream.Play.StreamNotFound":break;case"NetStream.Play.Start":break;case"NetStream.Buffer.Full":t.search("onlineCamera")>-1?liveObj.cameraBackState(1,!1):t.search("interaction")>-1?getPlayer("online")&&(getPlayer("online").hasOwnProperty("_type")&&getPlayer("online")._type==="FlvPlayer"?getPlayer("online").muted=!0:getPlayer("online").techCall_("setMuted",!0)):(errorCount=0,intervalId!=null&&window.clearInterval(intervalId),intervalId=null,$("#dnsError").hide(),$(".full_screen").length>0&&$(".full_screen").attr("isPlay","1"),$(".setting_btn").length>0&&$(".setting_btn").attr("isPlay","1"),$(".size_btn").length>0&&$(".size_btn").attr("isPlay","1"),$("#noSreamMessage").length>0&&($("#noSreamMessage")[0].style.display="none"),liveObj&&liveObj.cameraBackState(0,!1));break;case"NetStream.Buffer.Flush":break;case"NetStream.Video.DimensionChange":break;case"NetStream.Buffer.Empty":t.search("onlineCamera")>-1?liveObj.cameraBackState(1,!0):liveObj.cameraBackState(0,!0),t.search("interaction")>-1&&getPlayer("online").techCall_("setMuted",!1);break}}var currentSize=1,fristWidth=0,fristHeight=0;function changeSize(t,e){t.search("online")<0||t.search("onlineCamera")>-1||t.search("interaction")>-1||t.search("floatCamera")>-1||(currentSize=1,$("#sizeText").val(Math.round(currentSize*100)),fristWidth=e.height,fristHeight=e.width,fristWidth>0&&fristHeight>0&&(liveObj.getPlayerLoade?liveObj.getPlayerLoade(fristWidth,fristHeight):changeOnlieSize(fristWidth,fristHeight,function(){var n=window.location.href;n.indexOf("assistantlive.html")>-1&&$("#whiteboard_box").css({height:$("#studio_play_content").height(),width:$("#studio_play_content").width()})})))}function changeAssVideoSize(t){fristWidth=fristWidth===0?$("#whiteboard_box").width():fristWidth,fristHeight=fristHeight===0?$("#whiteboard_box").height():fristHeight;var e=currentSize;t?(currentSize+=.05,currentSize>2&&(currentSize=2),changeAssOnlieSize(Math.round(fristWidth*currentSize),Math.round(fristHeight*currentSize))):(currentSize-=.05,currentSize<.5&&(currentSize=.5),changeAssOnlieSize(Math.round(fristWidth*currentSize),Math.round(fristHeight*currentSize))),$("#sizeText").val(Math.round(currentSize*100))}function changeAssOnlieSize(t,e,n){var r,a,l,i;r=t,a=e,l=($("#studio_play_content").width()-t)/2<0?0:($("#studio_play_content").width()-t)/2,i=($("#studio_play_content").height()-e)/2<0?0:($("#studio_play_content").height()-e)/2,$(".video-wrap").css("width",r),$(".video-wrap").css("height",a),$(".video-wrap").css("left",l),$(".video-wrap").css("top",i),n&&n()}function changeVideoSize(t){var e=currentSize;t?(currentSize+=.05,currentSize>2&&(currentSize=2),changeOnlieSize(Math.round(fristWidth*currentSize),Math.round(fristHeight*currentSize))):(currentSize-=.05,currentSize<.5&&(currentSize=.5),changeOnlieSize(Math.round(fristWidth*currentSize),Math.round(fristHeight*currentSize))),$("#sizeText").val(Math.round(currentSize*100))}function changeOnlieSize(t,e,n){var r,a,l,i;r=t,a=e,l=($("#live_content").width()-e)/2<0?0:($("#live_content").width()-e)/2,i=($("#live_content").height()-t)/2<0?0:($("#live_content").height()-t)/2,$(".video-wrap").css("height",r),$(".video-wrap").css("width",a),$(".video-wrap").css("left",l),$(".video-wrap").css("top",i),n&&n()}function settingSound(t,e){if(volumeNumber=t,e){var n=$("#setting_video");n.remove(),liveObj.addPlay.settingDialog=null}getPlayer("online")&&getPlayer("online").volume(t),getPlayer("onlineCamera")&&getPlayer("onlineCamera").volume(t)}function checkSettingUrl(){if(issettingURL=!1,settingList.length>0){var t=settingList[0].id,e=settingList[0].url;settingList.splice(0,1),_setVideoUrl(t,e)}}function getVideoType(t){var t=t||"",e=t.split("?"),n=e[0];appU=n.split("/");var r=appU[appU.length-1],a=r.split(".");return a[a.length-1]}function removePlayerById(t){for(var e=0;e<playHistory.length;e++)playHistory[e].id===t&&playHistory.splice(e,1);for(var e=0;e<playerList.length;e++)(playerList[e].id_===t||playerList[e].player_==null)&&(playerList[e].player_!=null&&playerList[e].dispose(),playerList.splice(e,1));for(var e=0;e<flvplayerList.length;e++)flvplayerList[e]._mediaElement.id===t&&(flvplayerList[e].pause(),flvplayerList[e].unload(),flvplayerList[e].detachMediaElement(),flvplayerList[e].destroy(),flvplayerList[e]=null,flvplayerList.splice(e,1))}function getPlayer(t){for(var e=0;e<playerList.length;e++)if(playerList[e].id_===t)return playerList[e];for(var e=0;e<flvplayerList.length;e++)if(flvplayerList[e]._mediaElement.id===t)return flvplayerList[e];return null}function getxgPlayer(t){for(var e=0;e<playerList.length;e++){var n=playerList[e].config||{};if(n.id===t)return playerList[e]}for(var e=0;e<flvplayerList.length;e++)if(flvplayerList[e]._mediaElement.id===t)return flvplayerList[e];return null}function play(){}function pause(){}function volume(){}function videoFullScreen(t){}function sacle(){}function rtmpStop(t){getPlayer(t).pause()}function setSeek(t,e,n){console.log(e),!isSetSeeked&&(needSeek=!0,n?(getPlayer(t).pause(),$("#seekDiv")[0].style.display="",$("#seekLabel").text(SecondToDate(e)),playseek=e,seekId=t):getxgPlayer(t).currentTime=e)}function goSeek(t){isSetSeeked=!0,$("#seekDiv")[0].style.display="none",getxgPlayer(seekId).currentTime=playseek,getxgPlayer(seekId).play()}function clearSeek(t){isSetSeeked=!0,$("#seekDiv")[0].style.display="none",getxgPlayer(seekId).play()}function SecondToDate(t){var e=t;return e!=null&&e!=""&&(e>60&&e<60*60?e=parseInt(e/60)+"\u5206"+parseInt((parseFloat(e/60)-parseInt(e/60))*60)+"\u79D2":e>=60*60&&e<60*60*24?e=parseInt(e/3600)+"\u5C0F\u65F6"+parseInt((parseFloat(e/3600)-parseInt(e/3600))*60)+"\u5206"+parseInt((parseFloat((parseFloat(e/3600)-parseInt(e/3600))*60)-parseInt((parseFloat(e/3600)-parseInt(e/3600))*60))*60)+"\u79D2":e>=60*60*24?e=parseInt(e/3600/24)+"\u5929"+parseInt((parseFloat(e/3600/24)-parseInt(e/3600/24))*24)+"\u5C0F\u65F6"+parseInt((parseFloat(e/3600)-parseInt(e/3600))*60)+"\u5206"+parseInt((parseFloat((parseFloat(e/3600)-parseInt(e/3600))*60)-parseInt((parseFloat(e/3600)-parseInt(e/3600))*60))*60)+"\u79D2":e=parseInt(e)+"\u79D2"),e}function rotationFun(t,e){getPlayer(t).zoomrotate({rotate:e})}function zoomFun(t,e){getPlayer(t).zoomrotate({zoom:e})}function extend(t,e,n){for(var r in e)e.hasOwnProperty(r)&&(!t.hasOwnProperty(r)||n)&&(t[r]=e[r]);return t}