<template>
	<view class="container" style="background-color: #000; position: relative">
		<view style="width: 100%; height: 400rpx">
			<view v-if="showCountDown" class="showCountDownd" style="">
				<view class="">
					<text class="nextText">{{secondCountDown}} 秒后播放下一个视频</text><br />
					<view>
						<text class="cancelNext" @click="hideNextVideo">取消下一个</text>
					</view>
					<!-- <view class="cancelNext" @click="hideNextVideo">重新播放</view> -->
				</view>
			</view>
			<view v-if="show"
				style="height: 100%;display: flex;align-items:center;justify-content:center;color: #fff;font-size: 38rpx;text-align: center;">
				{{errorTxt}}
			</view>
			<div class="" v-else style="background-color: #000" ref="videoContent" @tap="renderScript.handleClick"
				id="url-player-test" :videoData="videoData" :winWidth="winWidth" :winHeight="winHeight"
				:currentVideoList="currentVideoList" :firstTime="firstTime" :isfresh="isfresh" :platform="platform"
				:isSetFirstTime="isSetFirstTime" :isChange="isChange" :change:videoData="renderScript.receiveMsg"
				:replayVideoFlag="replayVideoFlag" :change:winWidth="renderScript.receiveWinWidth"
				:change:winHeight="renderScript.receiveWinHeight" :change:firstTime="renderScript.receiveFirstTime"
				:change:replayVideoFlag="renderScript.receiveReplayVideoFlag"
				:change:isSetFirstTime="renderScript.receiveisSetFirstTime"
				:change:isfresh="renderScript.receiveIsfresh" :change:platform="renderScript.receiveplatform"
				:change:isChange="renderScript.receiveIsChange"
				:change:currentVideoList="renderScript.receiveVideoList">
			</div>
			<div @tap="renderScript.emitData" ref="videoContent1" v-show="false" class="videoContent1">
				直接调用renderjs中的emitData的方法,传递当前播放时长
			</div>

			<div @tap="renderScript.endEmitData" ref="videoContent2" v-show="false" class="videoContent2">
				监听结束方法，记录播放时长
			</div>

			<div @tap="renderScript.changeVideoData" ref="videoContent3" v-show="false" class="videoContent3">
				监听切换视频方法
			</div>
			<div @tap="renderScript.emitSetData" ref="videoContent4" v-show="false" class="videoContent4">
				监听切换视频方法
			</div>
			<div @tap="renderScript.emitopenShow" ref="videoContent5" v-show="false" class="videoContent5">
				打开视频提示
			</div>
			<div @tap="renderScript.emitLoadNextVideo" ref="videoContent6" v-show="false" class="videoContent6">
				播放下一条
			</div>
			<div @tap="renderScript.emitHideNextVideo" ref="videoContent7" v-show="false" class="videoContent7">
				隐藏播放下一条界面
			</div>
			<div @tap="renderScript.emitReplayVideoFlagFalse" ref="videoContent8" v-show="false" class="videoContent8">
				隐藏播放下一条界面
			</div>
			<div @tap="renderScript.emitUnlockChangeVideo" ref="videoContent9" v-show="false" class="videoContent9">
				释放切换键锁
			</div>
			<div class="fullScreenButton-container">
				<div :class="`prism-fullscreen-btn ${isFullScreen ? 'fullscreen' : ''}`"
					@tap="renderScript.changeVideoScreen"></div>
			</div>
		</view>
	</view>
</template>
<script>
	import {
		mapState,
	} from "vuex";

	export default {
		props: ["currentVideo", "currentVideoList", "videoTitle", 'secondCountDown', 'http'],
		data() {
			return {
				reaquestFlag: false,
				show: false,
				platform: null,
				//当前是否是全屏模式
				isFullScreen: false,
				isfresh: false,
				isChange: false,
				isControl: true,
				timer: null,
				replayVideoFlag: false,
				// secondCountDown: 5,
				showCountDown: false,
				playEndBlank: false,
				// videoTitle: "",
				videoList: [],
				replayVideoLock: false, // 重播操作锁
				firstTime: 0,
				options: {},
				playAuth: "",
				currentTime: "",
				videoId: "",
				videoData: {},
				isSetFirstTime: false,
				screenType: null,
				videoUrl: null,
				errorTxt: '此设备暂不支持观看当前视频请移步到安卓手机进行学习！'
			};
		},
		computed: {
			...mapState(["videoOssList"]),
		},

		watch: {
			currentVideo: {
				immediate: true,
				handler(newVal) {
					console.log('currentVideoList', this.currentVideoList)
				},
			},
			timer(newValue) {
				this.$emit("child-event", newValue);
			},
		},

		// //页面显示
		mounted() {},
		beforeDestroy() {
			this.handleEnd();
			console.log("是否走啦习销毁");
			// 销毁重置方向
			// clearInterval(this.$store.state.videoTimer);			
			plus.screen.lockOrientation("portrait-primary");
		},
		async onUnload() {
			// uni.navigateTo({
			// 	url: "/pages/curriculum/order/curriculum/back",
			// });
			// #ifdef APP-PLUS
			plus.screen.lockOrientation("portrait-primary"); //锁死屏幕方向为竖屏			
			// #endif
			await this.setVideoTime();
		},

		//第一次加载
		onLoad(options) {

		},

		methods: {
			replayVideo() {
				if (!this.replayVideoFlag) {
					this.getLive(true, this.currentVideo)
					console.log('this.currentVideo', this.currentVideo.id);
					this.hideNextVideo()
					this.replayVideoFlag = true
				}
			},
			replayVideoFlagFalse() {
				console.log('复原replayVideoFlag', this.replayVideoFlag);
				this.replayVideoFlag = false
			},
			UnlockChangeVideo() {
				this.$emit('unlockChangeVideo')
			},
			hideNextVideo() {
				this.showCountDown = false
				this.playEndBlank = false
				this.$emit('hideNextVideo')
			},
			loadNextVideo() {
				this.playEndBlank = true
				var _list = [...this.currentVideoList]
				_list = _list.map(item => {
					return item.id
				})

				var thisIndex = _list.findIndex(item => {
					return item == this.currentVideo.id
				})
				console.log('播放列表', _list, this.currentVideo.id, thisIndex);
				if (thisIndex < this.currentVideoList.length - 1) {
					this.showCountDown = true
					this.$emit('startNextVideoCountDown')
				}

			},

			openShow(data) {
				data.msg ? this.errorTxt = data.msg : '此设备暂不支持观看当前视频请移步到安卓手机进行学习'
				this.show = true;
			},
			start() {
				this.$refs.playerView.start();
			},
			pause() {
				// var playerView = ;
				this.$refs.playerView.pause();
			},
			changeVideoData() {
				this.show = false;
				this.isChange = false;
			},
			async changeVideo(data) {
				console.log('changeVideo+++++++++', data);
				this.currentTime = "";
				this.firstTime = 0;
				this.isSetFirstTime = false;
				this.isChange = false;
				this.getLive(true, data)
				// await this.init(data, true);
			},
			screenChange(data) {
				console.log(
					"status at line 这是当前的状态158:",
					data.status,
					data.primary
				);
				this.isFullScreen = !data.status;
				this.$emit("changeScreen", this.isFullScreen);
			},
			// 控制器的显示隐藏
			controlChange(e) {
				this.isControl = e.detail.show;
			},
			quitScreen() {
				// 退出全屏
				const ctx = this.$refs.myVideo;
				ctx.exitFullScreen();
			},
			// 播放器初始化
			async init(data, isChange) {
				this.show = false;
				this.platform = this.$platform;
				this.isfresh = true;
				console.log("at line 59:", "是否先走init这里", this.platform);
				if (uni.getStorageSync("videoOssList")) {
					this.videoList = JSON.parse(uni.getStorageSync("videoOssList"));
				}
				this.options = data.currentVideo;

				this.videoId = this.options.video;
				console.log("这是苹果视屏id", this.videoId);
				await this.getLive(isChange, this.options);
			},
			// 配置播放项
			async getData(data, isChange) {
				var that = this;
				if (!this.isSetFirstTime) {
					var netWork = data.userCourseVideoPositionEntity ?
						data.userCourseVideoPositionEntity.position :
						0;
					var list = [];
					if (uni.getStorageSync("videoOssList")) {
						list = JSON.parse(uni.getStorageSync("videoOssList"));

						var index = list.findIndex((e) => e.id == data.id);
						console.log('data.id', data.id);
						if (netWork) {
							if (index >= 0) {
								this.firstTime =
									list[index].time > netWork ? list[index].time : netWork;
							} else {
								this.firstTime = netWork ? netWork : 0;
							}
						} else {
							if (index >= 0) {
								this.firstTime = list[index].time ? list[index].time : 0;
							} else {
								this.firstTime = 0;
							}
						}
					} else {
						this.firstTime = 0;
					}

					this.videoData = {
						...data,
						firstTime: this.firstTime
					};
					this.isChange = isChange ? isChange : false;
					console.log(this.firstTime, "这是第一次播放时长222");
					uni.setStorageSync("videoOssList", JSON.stringify(list));
					console.log(this.firstTime, "这是第一次播放时长");
				}
				this.isSetFirstTime = true;
			},
			// 存储本地播放时间
			recordTime(data) {
				// console.log('recordTime', data.time);
				this.currentTime = data.time;

				var list = [];
				if (uni.getStorageSync("videoOssList")) {
					list = JSON.parse(uni.getStorageSync("videoOssList"));
				}
				var index = list.findIndex((e) => e.id == this.videoData.id);

				if (list.length > 0 && index >= 0) {
					list[index] = {
						...this.videoData,
						time: data.time,
					};
				} else {
					list.push({
						...this.videoData,
						time: data.time,
					});
				}
				uni.setStorageSync("videoOssList", JSON.stringify(list));
			},
			// 获取播放凭证
			async getLive(isChange, newVideoData) {
				if (this.reaquestFlag) {
					uni.showToast({
						title: '操作太快了,歇一下吧',
						icon: 'none'
					})
				}
				this.reaquestFlag = true
				var that = this;
				this.isfresh = false;
				var data = {
					...this.options,
				};
				if (isChange && newVideoData) {
					data = {
						...newVideoData,
					};
				}
        console.log('1111111111', newVideoData, isChange, data)
				await this.http
					.request({
						url: `sociology/course/checkVideo`,
						method: "Post", // POST、GET、PUT、DELETE，具体说明查看官方文档
						data,
						header: {
							//默认 无 说明：请求头
							"Content-Type": "application/json",
						},
					})
					.then(async (res) => {
						console.log('获取播放凭证666',JSON.stringify(res));
						this.reaquestFlag = false
						if (this.$platform == 'ios') {
							if (res.video.type == 1 && (res.video.m3u8Url == null || res.video.m3u8Url == '')) {
								// 只存在私有加密
								this.show = true
								this.http.request({
									url: "medical/course/addErrorCourse",
									method: "POST", // POST、GET、PUT、DELETE，具体说明查看官方文档
									data: {
										// "courseId": this.videoData.courseId,
										// "catalogueId": this.videoData.catalogueId,
										"chapterId": res.video.chapterId,
										"videoId": res.video.id,
										"sort": res.video.sort 
									},
									header: { //默认 无 说明：请求头
										'Content-Type': 'application/json'
									},
								}).then(() => {
									console.log('记录IOS不能看的视频成功', res.video)
								}).catch(() => { console.log('数据报错') })
								this.UnlockChangeVideo() // 解锁按钮
								uni.showModal({
									content: '抱歉，苹果手机不支持此加密视频格式，您可以在安卓端观看本视频',
									confirmText: '知道了',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {
											// uni.navigateBack({delta: 2})
										}
									}
								})
								return
							}
						}
						var data = {
							...res.video,
						};
						if (this.currentVideo.type == 1) {
							var playAuth = res.video.playAuth.replace(/=/g, "");
							// console.log("这是接口获取的视屏凭证111", playAuth);
							data = {
								...data,
								videoId: res.video.video,
								playAuth: playAuth,
							};
							this.playAuth = playAuth;

							await that.getData(data, isChange);
						} else {
							console.log("这是接口获取的视屏凭证222", res.video, data);
							data = {
								...data,
								playAuth: new Date().getTime(),
							};
							await that.getData(data, isChange);
						}
						console.log("是否获取到初始播放值", data);

						that.$forceUpdate();
					}).catch(e => {
						this.reaquestFlag = false
						uni.showToast({
							'title': '获取播放地址失败',
							icon: 'none'
						})
					});
			},

			async handleEnd() {
				var list = JSON.parse(uni.getStorageSync("videoOssList"));
				var data = list.find((e) => e.id == this.videoData.id);
				this.currentTime = data.time;
				console.log(
					"this.currentTime at line 这是结束的时候掉的存储视频:",
					this.currentTime
				);
				await this.setVideoTime();
				// clearInterval(this.$store.state.videoTimer);
				// this.timer = null;
			},
			// 存储时长到线上
			setVideoTime(time) {
				var data = {};
				console.log("是否走了存储视屏," + this.videoData.id, time, this.currentTime);
				let _time = null
				time ? _time = time : _time = this.currentTime
				var data = {
					videoId: this.videoData.id,
					position: _time, //秒数
					// loadAnimate: 'none',
				};

				this.http
					.request({
						url: `sociology/course/saveCoursePosition`,
						method: "Post", // POST、GET、PUT、DELETE，具体说明查看官方文档
						data,
						header: {
							//默认 无 说明：请求头
							"Content-Type": "application/json",
						},
					})
					.then((res) => {
						console.log("存储视屏时长接口返回信息", res);
						this.$forceUpdate();
					}).catch(e => {
						console.log("存储进度报错", e);
					});
			},
			goBack() {
				uni.navigateBack({
					delta: 1,
				});
			},
			// 设置初始播放时间 并开启定时器
			async setVideoFirtsetTime(data) {
				this.currentTime = this.firstTime;
				await this.setVideoTime(data.time);
			},
		},

		created() {},
	};
</script>

<script module="renderScript" lang="renderjs">
	var videoData = null
	var _seconds = 0
	var ReplayVideoFlag = false
	var curStatus = null
	var diff = 0
	var pauseTime = 0
	var myplayer = undefined
	var seekBtnHideTimer = null
	var seekBtnEls = []
	var seekBtnsEnabled = true
	var isEndedState = false
	function setEndedCore() {
		if (isEndedState) {
			return false;
		}
		isEndedState = true;
		$('.videoContent2').click()
		$('.videoContent6').click()
		seekBtnsEnabled = false;
		if (seekBtnHideTimer) {
			clearTimeout(seekBtnHideTimer);
			seekBtnHideTimer = null;
		}
		if (seekBtnEls && seekBtnEls.length) {
			seekBtnEls.forEach(function(btn) {
				btn.style.display = 'none';
			});
		}
		return true;
	}
	function applyBigPlayBtnEndedStyle() {
		var $bigBtn = $('#url-player-test .prism-big-play-btn');
		if ($bigBtn && $bigBtn.length) {
			$bigBtn.css({
				left: '30px',
				bottom: '80px',
				right: 'auto',
				top: 'auto',
				transform: 'none'
			});
		}
	}
	function applyEndedState() {
		setEndedCore();
		applyBigPlayBtnEndedStyle();
	}
	import $ from 'jquery'
	import { throttle } from '../../utils'
	export default {
		components: {
			// MyComponent
		},
		mounted() {
			// 在适合的生命周期，通过script和link标签引入播放器sdk、css
			console.log(JSON.stringify(this.currentVideoList), '这是monted')
			this.loadWebPlayerSDK()
		},
		data() {
			return {
				player: null,
				videoTimer: null,
				// curTime: null,
				// firstTime: null,
				// curStatus: null,
				// currentTime:null,
			}
		},
		watch: {
			// curTime(val) {
			// 	if (this.curTime !== null && this.curStatus !== null) {
			// 		this.$refs.videoContent1.click()
			// 	}
			// }
		},
		methods: {
			handleClick(event, ownerInstance) {
				console.log('是否了走了点击video事件', event)
			},
			emitData(event, ownerInstance) {
				var that = this;
				ownerInstance.callMethod('recordTime', {
					time: _seconds,
					status: curStatus
				})

			},
			receiveReplayVideoFlag(newValue, oldValue, ownerVm, vm) {
				console.log('newValue重新播放', newValue, myplayer);
				ReplayVideoFlag = newValue
				if (newValue) {
					isEndedState = false
					$('.videoContent8').click()
					// ReplayVideoFlag = newValue
					// 	// myplayer.replay()
					// 	$('.videoContent7').click()
					// 	 myplayer.seek(0)
					// myplayer.play()
				}

			},
			emitReplayVideoFlagFalse(event, ownerInstance) {
				ownerInstance.callMethod('replayVideoFlagFalse')
			},
			emitUnlockChangeVideo(event, ownerInstance) {
				ownerInstance.callMethod('UnlockChangeVideo')
			},
			async receiveFirstTime(newValue, oldValue, ownerVm, vm) {

			},
			async receiveisSetFirstTime(newValue, oldValue, ownerVm, vm) {
				console.log('是否刚开始设置播放时间', newValue, this.firstTime, myplayer);
			},
			emitSetData(event, ownerInstance) {
				// var that = this;				
				ownerInstance.callMethod('setVideoFirtsetTime', {
					time: _seconds,
				})
			},
			emitHideNextVideo(event, ownerInstance) {
				ownerInstance.callMethod('hideNextVideo')
			},
			emitLoadNextVideo(event, ownerInstance) {
				ownerInstance.callMethod('loadNextVideo')
			},
			emitopenShow(event, ownerInstance) {
				ownerInstance.callMethod('openShow', {
					msg: '播放出错啦！'
				})
			},
			// 全屏切换事件
			changeVideoScreen(event, ownerInstance) {
				var that = this;
				// this.$emit('changeScreenLoading',true)
				var status = myplayer.fullscreenService.getIsFullScreen();
				console.log('this.$platform--------', this.platform);
				if (this.platform != 'ios') { // 改变按钮形态				
					ownerInstance.callMethod('screenChange', {
						status: status,
						primary: status ? 'portrait' : 'landscape'
					})
				}
				if (status) {
					if (this.platform != 'ios') {
						console.log('恢复竖版');
						setTimeout(() => {
							plus.screen.lockOrientation("portrait-primary"); //锁死屏幕方向为竖屏
							myplayer.fullscreenService.cancelFullScreen();
						}, 100);
					}
				} else {
					myplayer.fullscreenService.requestFullScreen();
					if (this.platform != 'ios') {
						setTimeout(() => {
							plus.screen.lockOrientation("landscape-primary");
						}, 100);
					} else {
						console.log('不要旋转, 使用原生全屏');
					}

				}
			},
			changeVideoData(event, ownerInstance) {
				var that = this;
				ownerInstance.callMethod('changeVideoData', )
			},
			endEmitData(event, ownerInstance) {
				var that = this;
				ownerInstance.callMethod('handleEnd', )
			},
			// renderjs阿里云播放器引入与配置
			getLive() {
				console.log('阿里云播放器引入与配置:', this.firstTime, videoData)

				$('#url-player-test').empty();

				pauseTime = 0
				isEndedState = false
				var fullScreenButtonComponent = Aliplayer.Component({
					/**
					 * 初始函数，在new对象时调用
					 *
					 * @param {string} adAddress - 广告视频地址
					 * @param {string} toAddress - 广告链接地址
					 */
					init: function(status, toAddress) {

						this.fullScreenStatus = status
						this.$html = $('.fullScreenButton-container');
						// this.$html.hide();
					},

					/**
					 * 创建广告Dom元素
					 */
					createEl: function(el) {
						this.$html.find('.ad').attr('src', this.adAddress);
						var $adWrapper = this.$html.find('.ad-wrapper');
						$adWrapper.attr('href', this.toAddress);
						$adWrapper.click(function() {

						});
						$(el).find('.prism-time-display').after(this.$html);
					},
					/**
					 * 隐藏广告
					 */
					playing: function(player, e) {
						this.$html.show();
						// this.$html.hide();
					},

				});
				var backBtnComponent = Aliplayer.Component({
					init: function(status, toAddress) {
						this.fullScreenStatus = status
						this.$html = $('#url-player-test');
					},
					createEl: function(el) {
						seekBtnsEnabled = true;

						var container = $('#url-player-test');
						container.find('.custom-seek-back').remove();
						container.find('.custom-seek-forward').remove();

						seekBtnEls = [];

						function createSeekBtn(className, label, position) {
							var btn = document.createElement('button');
							btn.className = 'custom-seek-btn ' + className;
							btn.innerText = label;
							btn.style.position = 'absolute';
							btn.style.top = '40%';
							btn.style.transform = 'translateY(-50%)';
							btn.style.width = '40px';
							btn.style.height = '40px';
							btn.style.borderRadius = '50%';
							btn.style.border = 'none';
							btn.style.background = 'rgba(255,255,255,0.6)';
							btn.style.color = '#000';
							btn.style.fontSize = '14px';
							btn.style.display = 'flex';
							btn.style.alignItems = 'center';
							btn.style.justifyContent = 'center';
							btn.style.padding = '0';
							btn.style.display = 'none';
							btn.style.zIndex = '1';
							if (position === 'left') {
								btn.style.left = '30px';
							} else if (position === 'right') {
								btn.style.right = '30px';
							}
							return btn;
						}

						var backBtn = createSeekBtn('custom-seek-back', '-15s', 'left');
						var forwardBtn = createSeekBtn('custom-seek-forward', '+15s', 'right');

						seekBtnEls = [backBtn, forwardBtn];

						var showSeekBtns = function() {
							if (!seekBtnsEnabled) return;
							if (!seekBtnEls || !seekBtnEls.length) return;
							seekBtnEls.forEach(function(btn) {
								btn.style.display = 'flex';
							});
							if (seekBtnHideTimer) {
								clearTimeout(seekBtnHideTimer);
							}
							seekBtnHideTimer = setTimeout(function() {
								if (!seekBtnEls || !seekBtnEls.length) return;
								seekBtnEls.forEach(function(btn) {
									btn.style.display = 'none';
								});
							}, 3000);
						};

						backBtn.onclick = throttle(function(e) {
							if (e && e.stopPropagation) {
								e.stopPropagation();
							}
							showSeekBtns();
							if (myplayer && myplayer.getCurrentTime) {
								var current = myplayer.getCurrentTime();
								var target = current - 15;
								if (target < 0) {
									target = 0;
								}
								myplayer.seek(target);
							}
						}, 500);

						forwardBtn.onclick = throttle(function(e) {
							if (e && e.stopPropagation) {
								e.stopPropagation();
							}
							showSeekBtns();
							if (myplayer && myplayer.getCurrentTime && myplayer.getDuration) {
								var current = myplayer.getCurrentTime();
								var duration = myplayer.getDuration();
								var target = current + 15;
								if (target > duration) {
									target = duration;
								}
								myplayer.seek(target);
								if (duration && target >= duration) {
									setEndedCore();
								}
							}
						}, 500);

						var containerDom = document.getElementById('url-player-test');
						if (containerDom) {
							containerDom.addEventListener('click', function() {
								showSeekBtns();
							});
						}

						container.append(backBtn);
						container.append(forwardBtn);
					},
					playing: function(player, e) {},
				});
				// console.log('这是查看是否获取到hlstoken', this.videoData)
				var playerOptions = {
					id: "url-player-test",
					width: '100%', //容器的大小
					height: '100%', //容器的大小
					"qualitySort": "asc",
					"cover": "",
					"autoplay": true,
					"isLive": false,
					"rePlay": false,
					"playsinline": true,
					"controlBarVisibility": "hover",
					"useH5Prism": true,
					components: [{
							name: 'fullScreenComponent',
							type: fullScreenButtonComponent
						},
						{
							name: 'backBtnComponent',
							type: backBtnComponent
						},
						{
							name: 'RateComponent',
							type: AliPlayerComponent.RateComponent
						},

					],

					skinLayout: [{
							name: "bigPlayButton",
							align: "cc",
						},
						{
							name: "H5Loading",
							align: "cc"
						},
						{
							name: "errorDisplay",
							align: "tlabs",
							x: 0,
							y: 0
						},
						{
							name: "infoDisplay"
						},
						{
							name: "tooltip",
							align: "blabs",
							x: 0,
							y: 56
						},
						{
							name: "thumbnail"
						},
						{
							name: "backBtnComponent",
							align: "blabs",
							x: 15,
							y:70
						},
						{
							name: "controlBar",
							align: "blabs",
							x: 0,
							y: 0,
							children: [{
									name: "progress",
									align: "blabs",
									x: 0,
									y: 44
								},
								{
									name: "playButton",
									align: "tl",
									x: 15,
									y: 12
								},
								{
									name: "timeDisplay",
									align: "tl",
									x: 10,
									y: 7
								},
								{
									name: "prism-speed-selector",
									align: "tr",
									x: 15,
									y: 12
								},
								{
									name: "volume",
									align: "tr",
									x: 5,
									y: 10
								}
							]
						}
					]

				}

				if (videoData.type == 1) {
					if (videoData.m3u8Url == null || videoData.m3u8Url == '') {
						console.log('这是私有加密的视频');
						if (this.$platform == 'ios') {
							this.$refs.videoContent5.click()
						} else {
							playerOptions = {
								...playerOptions,
								"vid": videoData.videoId, // 必选参数，可以通过点播控制台（路径：媒资库>音/视频）查询。示例：1e067a2831b641db90d570b6480f****。

								"playauth": videoData.playAuth, // 必选参数，参数值可通过调用GetVideoPlayAuth接口获取。
								"encryptType": 1, // 必选参数，当播放私有加密流时需要设置本参数值为1。其它情况无需设置。
								"playConfig": {
									"EncryptType": 'AliyunVoDEncryption'
								}
							}
							console.log('这是私有加密的视频');
						}
					} else if (videoData.m3u8Url != null || videoData.m3u8Url != '') {
						playerOptions = {
							...playerOptions,
							source: videoData.m3u8Url,
							// "playConfig": {"EncryptType": "HLSEncryption"}
						}
						console.log('这是标准加密的视频', videoData.id, videoData.m3u8Url);
					}

				} else {
					playerOptions = {
						...playerOptions,
						source: videoData.videoUrl
					}
					console.log('这是没有加密的视频');
				}

				var player = new Aliplayer(playerOptions, function(player) {});
				this.player = player;
				myplayer = player;
				// console.log('myplayer------------',myplayer.loadByUrl('https://www.w3schools.com/html/movie.mp4'));
				// console.log('是否拿到第一次初始值呢', this.platform, typeof this.firstTime, this.firstTime)

				player.on('ready', function() {
					console.log('播放器准备就绪，开始播放');
					player.play()
					$('.videoContent9').click()
				})
				player.on('play', function() {
					var videoDurationTimes = parseInt(player.getDuration())
					console.log('开始播放------',videoDurationTimes,pauseTime);
					$('.videoContent7').click()
					
					isEndedState = false;
					seekBtnsEnabled = true;
					if (seekBtnHideTimer) {
						clearTimeout(seekBtnHideTimer);
						seekBtnHideTimer = null;
					}

					if (pauseTime > 0) {
						if(pauseTime==videoDurationTimes){
							return
						}else{
							player.seek(pauseTime);
						}
					}
				})
				player.one('canplay', function() {
					// console.log('这是ios数据缓冲初次设置播放位置判断！！！！', videoData)
					// player.seek(20);
					// if(ReplayVideoFlag){
					// 	player.seek(0);
					// }else{
					var videoDurationTimes = parseInt(player.getDuration())
					// var firstTime = parseInt(player.getCurrentTime())
					console.log('视频总长度', parseInt(player.getDuration()), parseInt(player.getCurrentTime()));
					if (videoData.firstTime < videoDurationTimes) {
						player.seek(videoData.firstTime);
					} else {
						player.seek(0);
					}
					//}
				})
				myplayer.on('playing', function() {
					console.log('正在播放...')

				})

				myplayer.on('timeupdate', function() {
					let that = this
					var _time = parseInt(player.getCurrentTime())
					curStatus = player.getStatus()
					if (_seconds != _time) {
						_seconds = _time
						diff++
						if (diff % 60 === 0) {
							console.log('符合---------');
							$('.videoContent4').click()
							diff = 0
						}
						$('.videoContent1').click()
						var duration = player.getDuration && player.getDuration()
						if (duration) {
							var total = parseInt(duration)
							if (_seconds >= total && (curStatus === 'paused' || curStatus === 'ended')) {
								setEndedCore();
							}
						}
					}
				})
				myplayer.on('ended', function() {
					console.log('播放完毕');
					applyEndedState();
				})
				player.on('pause', function() {
					pauseTime = parseInt(player.getCurrentTime())
					player.pause(true)
					console.log('触发暂停', pauseTime)

					if (player.getStatus && player.getStatus() === 'ended') {
						applyEndedState();
						return;
					}

					if (isEndedState) {
						applyBigPlayBtnEndedStyle();
						return;
					}

					var $bigBtn = $('#url-player-test .prism-big-play-btn');
					if ($bigBtn && $bigBtn.length) {
						$bigBtn.css({
							left: '50%',
							top: '50%',
							right: 'auto',
							bottom: 'auto',
							transform: 'translate(-50%, -50%)'
						});
					}
				})

				myplayer.on('error', function() {
					console.log('播放出错')
					$('.videoContent5').click()
				})
			},
			showPreview(e) {
				// console.log('e at line 56:', e)
				let conimg = e.target.dataset.nodes;
				let imgs = conimg.match(/<img[^>]+>/g); //选择节点中的img
				console.log('imgs at line 59:', imgs)
				let imgList = [];
				//遍历img标签的src里面的内容放在定义的数组imgList中
				for (var j = 0; j < imgs.length; j++) {
					imgs[j].replace(/<img[^>]*src=['"]([^'"]+)[^>]*>/gi, function(match, capture) {
						imgList.push(capture)

					})
				}
				console.log('imgList.push at line 64:', imgList)

				uni.previewImage({
					urls: imgList,
					longPressActions: {
						itemList: ['很抱歉，暂不支持保存图片到本地'],
						success: function(res) {
							// console.log(res,'+++++')
						}
					}
				});

			},
			receiveScreenType(newValue) {},
			async receiveIsfresh(newValue) {

				console.log('是否走了刷新销毁方法:', myplayer)
				if (myplayer) {
					// clearInterval(this.$store.state.videoTimer)
					// await this.setVideoTime();
					myplayer.dispose();
				}
			},
			async receiveplatform(newValue) {

			},
			async receiveIsChange(newValue) {
				if (this.isChange) {
					this.checkValue()
				}
			},

			receiveVideoList(newValue, oldValue, ownerVm, vm) {
				// //数据变化
				console.log('currentVideoListcurrentVideoListcurrentVideoList', JSON.stringify(newValue))
			},
			// 监听视频参数变化，并赋值给常量
			receiveMsg(newValue, oldValue, ownerVm, vm) {
				//数据变化	
				videoData = newValue			
				
			},
			receiveWinWidth(newValue, oldValue, ownerVm, vm) {
				//数据变化
				console.log('newValue', newValue)
			},
			receiveWinHeight(newValue, oldValue, ownerVm, vm) {
				//数据变化
				console.log('newValue', newValue)
			},
			// 检测是否传入播放参数
			checkValue() {
				// console.log(this.videoId, this.authId, videoData, "1111888888")
				if ((!videoData.playAuth || !this.currentVideoList)) {
					setTimeout(() => {
						this.checkValue();
					}, 1000);
				} else {
					// console.log('这是这只只是594:', this.firstTime, this.videoData)
					this.getLive();
				}
			},
			loadWebPlayerSDK() {
				return new Promise((resolve, reject) => {
					const s_tag = document.createElement('script'); // 引入播放器js
					s_tag.type = 'text/javascript';
					s_tag.src = 'https://g.alicdn.com/apsara-media-box/imp-web-player/2.20.3/aliplayer-min.js';
					s_tag.charset = 'utf-8';
					s_tag.onload = () => {
						const s_tag1 = document.createElement('script'); // 引入播放器js
						s_tag1.type = 'text/javascript';
						s_tag1.src =
							'https://player.alicdn.com/aliplayer/presentation/js/aliplayercomponents.min.js';
						s_tag1.charset = 'utf-8';
						s_tag1.onload = () => {
							this.checkValue();
							resolve();
						}
						document.body.appendChild(s_tag1);
					}
					document.body.appendChild(s_tag);
					const l_tag = document.createElement('link'); // 引入播放器css
					l_tag.rel = 'stylesheet';
					l_tag.href =
						'https://g.alicdn.com/apsara-media-box/imp-web-player/2.20.3/skins/default/aliplayer-min.css';
					document.body.appendChild(l_tag);
				});
			},

		}
	}
</script>
<style>
	.cancelNext {
		display: inline-block;
		margin-right: 20rpx;
		border-radius: 10rpx;
		margin-top: 10rpx;
		padding: 10rpx 20rpx !important;
		background-color: #fff !important;
		color: #000;
		text-align: center;
		line-height: 50rpx;
	}

	/* .cancelNext:last-child{margin-left: 10rpx;} */
	.nextText {}

	.showCountDownd {
		box-sizing: border-box;
		height: 100%;
		width: 100%;
		background-color: rgba(0, 0, 0, 0.6);

		display: flex;
		align-items: center;
		justify-content: flex-end;
		color: #fff;
		font-size: 38rpx;
		text-align: center;
		position: absolute;
		top: 0;
		right: 10rpx;
		z-index: 4;

		text {}

	}

	.container {
		width: 100vw;
		height: auto;

		/deep/.pause {
			width: 60rpx !important;
			height: 60rpx !important;
		}
	}

	.fds {
		background-color: blue;
		height: 600rpx;
		position: fixed;
		top: 60rpx;
	}

	.returnBack {
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		height: 88rpx;
		padding-left: 20rpx;
	}

	.txt {
		color: #fff;
	}

	.right_title {
		background: #000;
		height: 96rpx;
		justify-content: space-between;
		flex-direction: row;
		align-items: center;
		margin-left: auto;
	}

	.return {
		flex-direction: row;
		align-items: center;
		color: #fff;
	}

	.right_handle {
		width: 200rpx;
		flex-direction: row;
		justify-content: flex-end;
		padding-right: 20rpx;
	}

	cover-view {
		display: block;
		line-height: 1.2;
		overflow: hidden;
		white-space: nowrap;
		pointer-events: auto;
	}

	cover-view {
		visibility: visible !important;
	}

	cover-image {
		visibility: visible !important;
	}

	.fullScreenButton-container {
		color: #fff;
		float: right;
		height: 35px;
		margin-top: 6px;
		margin-right: 5px;
		display: flex;
		align-items: center;
		position: relative;

		i {
			color: #fff;
			display: inline-block;
			font-size: 22px;
			display: block;
			margin-top: 7px;
			cursor: pointer;

			&+i {
				margin-left: 3px;
			}

			@media (min-width: 768px) {
				&:hover+.player-tooltip {
					display: block;
				}
			}
		}

		.player-tooltip {
			&.prev {
				left: -10px;
			}

			&.list {
				left: 5px;
			}

			&.next {
				right: -12px;
			}
		}
	}

	.playlist-content {
		position: absolute;
		right: 0;
		width: 0px;
		padding-bottom: 48px;
		box-sizing: border-box;
		height: 100%;
		transition: all 0.38s ease-in-out;
		overflow: hidden;

		.list {
			background-color: #000;
			background-color: rgba(0, 0, 0, 0.3);
			height: 100%;
			overflow: auto;

			.video-item {
				color: #fff;
				padding: 0px 10px;
				line-height: 35px;
				font-size: 14px;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				cursor: pointer;

				&.active {
					background-color: #000;
					color: #00ddff;
				}

				@media (min-width: 768px) {
					&:hover {
						background-color: #000;
						color: #00ddff;
					}
				}
			}
		}
	}

	.player-tooltip {
		position: absolute;
		display: none;
		font-size: 12px;
		color: #fff;
		line-height: 28px;
		letter-spacing: 0;
		text-align: center;
		background: #3c3c3c;
		box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.1);
		height: 28px;
		top: -48px;
		padding: 0 5px;
		white-space: nowrap;
	}

	.playlist-skip-tip {
		padding: 5px 15px;
		position: absolute;
		top: 50%;
		left: 50%;
		z-index: 30;
		line-height: 30px;
		font-size: 14px;
		border-radius: 4px;
		background: rgba(255, 255, 255, 0.8);
		color: #000;
		text-align: center;
		transform: translate(-50%, -50%);
	}

	#rotating-div {
		width: 100vw;
		height: 100vh;
		background-color: #3498db;
		transform: rotate(90deg);
		/* 旋转90度 */
		transform-origin: center center;
		/* 设置旋转中心点在div中心 */
		position: fixed;
		/* 固定定位，全屏显示 */
		left: 0;
		top: 0;
		bottom: 0;
		right: 0;
	}
	#url-player-test {
		position: relative;
	}
	#url-player-test .custom-seek-btn {
		width: 48px;
		height: 48px;
		border-radius: 50%;
		border: none;
		background: rgba(0, 0, 0, 0.5);
		color: #fff;
		font-size: 14px;
		outline: none;
		cursor: pointer;
		pointer-events: auto;
		position: absolute;
		top: 50%;
		left: 30px;
	}
	
	#url-player-test .custom-seek-btn:active {
		background: rgba(255, 255, 255, 0.25);
	}
</style>
