import Polyv from"../../common/player/polyv";Component({properties:{videoOption:{type:Object,observer(t){if(0===Object.keys(t).length)return;const{mode:e,vodVid:a,vodsrc:i}=t;t.liveMode=t.liveMode>=0?t.liveMode:1,this.setData(t),i&&this.setData({vodsrc:i}),"vod"===e&&this.changeVid(a)}},vodSeek:{type:Number,value:0,observer(t){t>-1&&this.seek(t)}},skin:{type:String,value:"black",observer(t){"black"!==t&&"white"!==t&&this.setData({skin:"black"})}},danmuText:{type:String,value:"",observer(t){if("live"==this.data.mode)this.selectComponent("#plvLivePlayerComp").sendDanmu(t);else{if(!this.data.danmuEnabled||!this.data.allowDanmu)return;this.vodContext.sendDanmu({text:t})}}},usePlayerSkin:{type:Boolean,value:!0},menuType:{type:String,value:""},isSwitched:{type:Boolean,value:!1},allowDanmu:{type:Boolean,value:!0},skinAlwaysShow:{type:Boolean,value:!1},objectFit:{type:String,value:"contain"}},data:{uid:"",cid:"",mode:"",statistics:{},vodsrc:"",vodVid:"",vodSrc:"",isCamClosed:!1,settingShow:!1,showSettingBtn:!0,currentRate:1,danmuEnabled:!0,danmuList:[]},lifetimes:{attached(){this.vodContext=wx.createVideoContext("plvVodPlayer",this),this.hideSettingBtn()},detached(){}},methods:{changeVid(t){const{statistics:e}=this.data;this.vodPlayer&&this.vodPlayer.destroy&&this.vodPlayer.destroy(),this.vodPlayer=Polyv.getVideo({vid:t,params:{param1:e.param1||"",param2:e.param2||"",param4:e.param4||"",param5:e.param5||""},sid:e.param1||"",callback:t=>{const{type:e,src:a}=t;"error"===e?(console.log("error",t),this.triggerEvent("onError",t)):(console.log("###",a),this.setData({vodSrc:a[0]}))}})},seek(t){if("live"===this.data.mode){this.selectComponent("#plvLivePlayerComp").liveVodVideoContext.seek(t)}else this.vodContext.seek(t)},resumeStats(t){const{mode:e}=this.data;if("live"===e){this.selectComponent("#plvLivePlayerComp").resumeStats(t)}},onVodTimeUpdate(t){const e=t.detail.currentTime;this.triggerEvent("onVodProgress",{currentTime:e}),this.vodPlayer&&this.vodPlayer.timeUpdate&&this.vodPlayer.timeUpdate(t)},onVodPlay(){},onVodPause(){},onVodWaiting(){},onVodEnded(){this.triggerEvent("onVodEnd",{curVodVid:this.data.vodVid})},onVodError(){},onLiveVodEnd(){this.triggerEvent("onLiveVodEnd",{curVodVid:this.data.vodsrc})},onLiveStorageProgress(t){this.triggerEvent("onLiveStorageProgress",t.detail)},onLiveStatusChange(t){this.triggerEvent("onLiveStatusChange",t.detail)},onRefreshStatus(t){this.triggerEvent("refreshStatus",t.detail)},hideSettingContent(){this.setData({settingShow:!1})},setting(){const{settingShow:t}=this.data;this.setData({settingShow:!t})},changeRate(t){const{index:e}=t.currentTarget.dataset,a=[.5,1,1.25,1.5,2][e];this.setData({currentRate:e}),this.vodContext.playbackRate(a)},showSetControl(){this.setData({showSettingBtn:!0}),this.hideSettingBtn()},hideSettingBtn(){this.data.setTimer&&clearTimeout(this.data.setTimer),this.data.setTimer=setTimeout((()=>{this.setData({showSettingBtn:!1})}),3e3)},danmuSwitch(){this.setData({danmuEnabled:!this.data.danmuEnabled})}}});