wangguoyu 7 miesięcy temu
rodzic
commit
597e6c0d36
4 zmienionych plików z 123 dodań i 323 usunięć
  1. 1 1
      api/shipin.js
  2. 122 57
      pages/study/lookShipin.vue
  3. 0 115
      pages/study/lookShipin2.vue
  4. 0 150
      pages/study/lookShipin3.vue

+ 1 - 1
api/shipin.js

@@ -1,4 +1,4 @@
-import request from '@/utils/request'
+import request from '../utils/request.js'
 export function videoPolicy(data = {}) {
   return request({
     'url': '/admin/video/policy',

+ 122 - 57
pages/study/lookShipin.vue

@@ -1,97 +1,128 @@
 <template>
-	<view id="player-con"></view>
+	<view ref="videoContent" id="wgy-player-test" :playAuth="playAuth" :change:playAuth="renderScript.receiveMsg">
+	</view>
 </template>
-<script module="aa" lang="renderjs">
-		//#ifdef H5
-		import {
-			videoPolicy,
-			getVideoAuth,
-			getVideoRefresh
-		} from "@/api/shipin.js"
-		//#endif	
-		//#ifdef APP-PLUS
-	const {	videoPolicy,getVideoAuth,getVideoRefresh} = require("../../api/shipin.js")
-		//#endif
- 
-	const loadWebPlayerSDK = async () => {
-		return new Promise((resolve, reject) => {
-			const s_tag = document.createElement('script'); // 引入播放器js
-			s_tag.type = 'text/javascript';
-			s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
-			s_tag.charset = 'utf-8';
-			s_tag.onload = () => {
-				resolve();
-			}
-			document.body.appendChild(s_tag);
-			const l_tag = document.createElement('link'); // 引入播放器css
-			l_tag.rel = 'stylesheet';
-			l_tag.href = 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
-			document.body.appendChild(l_tag);
-		});
-	}
 
+<script>
+	import {
+		onLoad,
+		onReady
+	} from '@dcloudio/uni-app';
+	import {
+		videoPolicy,
+		getVideoAuth,
+		getVideoRefresh
+	} from "@/api/shipin.js"
 	export default {
 		data() {
 			return {
-				pageData: {
-					playauth: ''
-				}
-			};
-		},
-		mounted() {
-			console.log(111111)
-			loadWebPlayerSDK().then(() => {
-				//	this.getPlayAuth()
-				this.playAli()
-			}).catch((e) => {
-				console.log("加载播放器SDK失败", e);
-			});
+				options: {}, //上个页面获取的视频参数(视频id)
+				playAuth: "", //播放凭证
+				videoId: "", //阿里云视频id
+				videoData: {
+					playauth: '',
+					videoId: 'b997f16cb9cb474cb93526cff77d8801',
+				}, //阿里云视频其他参数
+			}
 		},
 		methods: {
-			getPlayAuth() {
+			getLive() {
 				let req = {
-					videoId: 'b997f16cb9cb474cb93526cff77d8801'
+					videoId: this.videoData.videoId
 				}
 				getVideoAuth(req).then(res => {
-					this.pageData.playauth = res.data
-					this.playAli()
+					this.playAuth = res.data
+					//	console.log(this.videoData)
+					//this.playAli()
 				})
 			},
+
+		},
+		created() {
+			console.log("getLive")
+			this.getLive(); //获取播放凭证
+
+		},
+
+	}
+</script>
+
+
+
+<script module="renderScript" lang="renderjs">
+	export default {
+		mounted() {
+			console.log("renderScript1")
+			// 在适合的生命周期,通过script和link标签引入播放器sdk、css
+			this.loadWebPlayerSDK()
+		},
+		data() {
+			return {
+				player: null,
+				playAuth: '',
+
+			}
+		},
+		methods: {
+			receiveMsg(newValue, oldValue, ownerInstance, instance) {
+				console.log('service层中的options发生变化')
+				console.log('新值', newValue)
+				console.log('旧值', oldValue)
+				// ownerInstance和this.$ownerInstance一样,可用来向service层通信
+				// instance和ownerInstance的区别是:
+				// instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
+				// instance的作用目前尚不明确,官方没有给出用法
+				if (newValue) {
+					this.playAuth = newValue
+					this.playAli()
+				}
+			},
 			playAli() {
-				let configData = {
-					"id": "player-con",
+				//配置播放器
+				var player = new Aliplayer({
+					id: "wgy-player-test",
 					"vid": 'b997f16cb9cb474cb93526cff77d8801',
-					"playauth": this.pageData.playauth,
+					"playauth": this.playAuth,
+					"encryptType": 1,
+					// "playConfig": {
+					// 	"EncryptType": 'AliyunVoDEncryption'
+					// },
 					"qualitySort": "asc",
 					"format": "m3u8",
 					"mediaType": "video",
 					"encryptType": 1,
-					"width": '100%',
-					progressMarkers: [{
+					"progressMarkers": [{
 						offset: 30,
 						isCustomized: true,
 						coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/9A3F562E595E4764AD1DD546FA52C6E5-6-2.png',
 						title: 'test title',
 						describe: 'test string',
 					}, {
-						offset: 50,
+						offset: 150,
 						isCustomized: true,
 						coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/1E7F402241CD4C0F94AD2BBB5CCC3EC7-6-2.png',
 						title: 'test title',
 						describe: 'test string',
 					}, {
-						offset: 150,
+						offset: 250,
 						isCustomized: true,
 						coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
 						title: 'test title',
 						describe: 'test string',
 					}, {
-						offset: 120,
+						offset: 550,
+						isCustomized: true,
+						coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
+						title: 'test title',
+						describe: 'test string',
+					}, {
+						offset: 320,
 						isCustomized: true,
 						coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
 						title: 'test title',
 						describe: 'test string',
 					}],
+					"width": '100%',
 					"height": '500px',
 					"autoplay": false,
 					"isLive": false,
@@ -100,11 +131,45 @@
 					"preload": false,
 					"controlBarVisibility": "hover",
 					"useH5Prism": true
+
+				}, function(player) {});
+				this.player = player;
+				player.one('canplay', function() {
+					console.log('canplay', this.player.tag);
+					player.tag.play();
+
+				});
+			},
+			//监听获取播放凭证的方法
+			checkValue() {
+				console.log(this.videoId, this.authId, "1111888888")
+				if (!this.videoData.playAuth) {
+					setTimeout(() => {
+						this.checkValue();
+					}, 1000);
+				} else {
+					this.getLive();
 				}
-				var player = new Aliplayer(configData, function(player) {
-					console.log('The player is created.')
+			},
+
+			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/de/prismplayer/2.9.6/aliplayer-min.js';
+					s_tag.charset = 'utf-8';
+					s_tag.onload = () => {
+						//	this.checkValue();
+						resolve();
+					}
+					document.body.appendChild(s_tag);
+					const l_tag = document.createElement('link'); // 引入播放器css
+					l_tag.rel = 'stylesheet';
+					l_tag.href =
+						'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
+					document.body.appendChild(l_tag);
 				});
-			}
+			},
 		}
 	}
 </script>

+ 0 - 115
pages/study/lookShipin2.vue

@@ -1,115 +0,0 @@
-<template>
-  <view class="video-container">
-    <video
-      id="myVideo"
-      :src="videoUrl"
-      controls
-      @timeupdate="updateCurrentTime"
-      @seeked="onVideoSeeked"
-      ref="videoPlayer"
-    ></video>
-    <cover-view class="markers-container" @click="onMarkerClick">
-      <block v-for="(marker, index) in markers" :key="index">
-        <cover-view
-          class="marker"
-          :style="{ left: marker.position + 'px' }"
-          :data-time="marker.time"
-        >
-          <!-- 标记点的内容,可以是时间、图标等 -->
-          {{ marker.time.toFixed(2) }}s
-        </cover-view>
-      </block>
-    </cover-view>
-	
-	
-	
-	
-  </view>
-</template>
-
-
-<script>
-	export default {
-		data() {
-			return {
-					videoUrl: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4', // 替换为你的视频URL
-			      currentTime: 0,
-			      markers: [
-			        // 初始标记点,可以根据需要动态添加
-			        // { time: 10, position: 0 }, // 示例标记点,时间单位为秒,位置根据视频宽度和视频时长计算
-			      ],
-			}
-		},
-		onReady: function (res) {
-			this.videoContext = uni.createVideoContext('myVideo')
-			this.addMarker(10);
-		},
-		methods: {
-			updateCurrentTime(event) {
-			  this.currentTime = event.detail.currentTime;
-			  // 这里可以添加逻辑来更新标记点的位置(如果标记点位置是动态计算的话)
-			},
-			onVideoSeeked(event) {
-			  // 视频跳转后的处理(如果需要的话)
-			},
-			addMarker(time) {
-			  // 计算标记点的位置
-			  const videoElement = this.$refs.videoPlayer;
-			  const videoDuration = videoElement.duration;
-			  const videoWidth = videoElement.$el.offsetWidth; // 获取视频元素的实际宽度
-			  const markerPosition = (time / videoDuration) * videoWidth;
-			
-			  // 添加标记点到数组中
-			  this.markers.push({
-			    time,
-			    position: markerPosition,
-			  });
-			
-			  // 如果需要,可以对markers数组进行排序
-			},
-			onMarkerClick(event) {
-			  // 获取点击的标记点的时间
-			  const target = event.target;
-			  const markerTime = parseFloat(target.dataset.time);
-			
-			  // 跳转到对应的视频时间
-			  const videoElement = this.$refs.videoPlayer;
-			  console.log(videoElement)
-			  console.log(this.videoContext)
-			  this.videoContext.seek(markerTime);
-			},
-		}
-	}
-
-</script>
-
-<style>
-.video-container {
-  position: relative;
-  width: 100%; /* 或者你想要的视频宽度 */
-}
-
-.markers-container {
-  position: absolute;
-  top: 0;
-  left: 0;
-  width: 100%;
-  height: 100%;
-  pointer-events: none; /* 防止标记容器干扰视频操作,但我们需要点击事件,所以稍后会在marker上设置pointer-events:auto */
-  display: flex;
-  align-items: center; /* 使标记点垂直居中 */
-}
-
-.marker {
-  position: absolute;
-  top: 10px; /* 或者你想要的标记点距视频顶部的距离 */
-  background-color: rgba(255, 0, 0, 0.5);
-  color: white;
-  padding: 2px 5px;
-  border-radius: 3px;
-  font-size: 12px;
-  white-space: nowrap;
-  pointer-events: auto; /* 允许点击事件 */
-  cursor: pointer; /* 鼠标悬停时显示手型光标 */
-}
-</style>

+ 0 - 150
pages/study/lookShipin3.vue

@@ -1,150 +0,0 @@
-<template>
-	<view id="player-con"></view>
-</template>
-
-<script setup module="openlayers" lang="renderjs"  >
-	import {
-		videoPolicy,
-		getVideoAuth,
-		getVideoRefresh
-	} from "@/api/shipin.js"
-	import {
-		ref,
-		onMounted,
-		reactive
-	} from "vue"
-	const loadWebPlayerSDK = async () => {
-		return new Promise((resolve, reject) => {
-			const s_tag = document.createElement('script'); // 引入播放器js
-			s_tag.type = 'text/javascript';
-			s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
-			s_tag.charset = 'utf-8';
-			s_tag.onload = () => {
-				resolve();
-			}
-			document.body.appendChild(s_tag);
-			const l_tag = document.createElement('link'); // 引入播放器css
-			l_tag.rel = 'stylesheet';
-			l_tag.href = 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
-			document.body.appendChild(l_tag);
-		});
-	}
-	let videoUrl = 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4'
-	let pageData = reactive({
-		type: '',
-		partUrl: '',
-		downloadUrl: '',
-		videoId: '',
-		uploadAddress: '',
-		uploadAuth: '',
-		signature: '',
-		playauth: '',
-	})
-	
-	
-	onMounted(()=>{
-		
-		
-		console.log(111)
-	    loadWebPlayerSDK().then(() => {
-	        // 如果需要使用自定义组件,打开以下注释
-	        // this.loadComponent().then(() => {
-	        let player = new Aliplayer({
-	          id: "url-player-test",
-	          source: "//player.alicdn.com/video/aliyunmedia.mp4",
-	          width: "100%",
-	          height: "100%",
-	        }, function (player) {
-	        });
-	        player.one('canplay', function () {
-	          console.log('canplay', player.tag);
-	          player.tag.play();
-	        });
-	        // }).catch((e) => { console.log("加载组件失败", e) })
-	      }).catch((e) => {
-	        console.log("加载播放器SDK失败", e);
-	      });
-	    
-	
-	})
-
-	
-	
-	
-	// 	onMounted(() => {
-	// 		loadWebPlayerSDK().then(() => {
-	// 		getPlayAuth()
-	// 		}).catch((e) => {
-	// 			console.log("加载播放器SDK失败", e);
-	// 		});
-	// 	})
-	// function getVideoId(){
-	// 	let req  ={
-	// 		fileName:videoUrl,
-	// 		title:"测试视频"
-	// 	}
-	// 	videoPolicy(req).then(res=>{
-	// 		pageData.videoId = res.data.videoId
-	// 		getPlayAuth()
-	// 	})
-	// }
-
-	function getPlayAuth() {
-		let req = {
-			videoId: 'b997f16cb9cb474cb93526cff77d8801'
-		}
-		getVideoAuth(req).then(res => {
-			pageData.playauth = res.data
-			playAli()
-		})
-	}
-
-	function playAli() {
-		let configData = {
-			"id": "player-con",
-			"vid": 'b997f16cb9cb474cb93526cff77d8801',
-			"playauth": pageData.playauth,
-			"qualitySort": "asc",
-			"format": "m3u8",
-			"mediaType": "video",
-			"encryptType": 1,
-			"width": '100%',
-			progressMarkers: [{
-				offset: 30,
-				isCustomized: true,
-				coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/9A3F562E595E4764AD1DD546FA52C6E5-6-2.png',
-				title: 'test title',
-				describe: 'test string',
-			}, {
-				offset: 50,
-				isCustomized: true,
-				coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/1E7F402241CD4C0F94AD2BBB5CCC3EC7-6-2.png',
-				title: 'test title',
-				describe: 'test string',
-			}, {
-				offset: 150,
-				isCustomized: true,
-				coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
-				title: 'test title',
-				describe: 'test string',
-			}, {
-				offset: 120,
-				isCustomized: true,
-				coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
-				title: 'test title',
-				describe: 'test string',
-			}],
-			"height": '500px',
-			"autoplay": false,
-			"isLive": false,
-			"rePlay": false,
-			"playsinline": true,
-			"preload": false,
-			"controlBarVisibility": "hover",
-			"useH5Prism": true
-		}
-		var player = new Aliplayer(configData, function(player) {
-			console.log('The player is created.')
-		});
-	}
-</script>