Browse Source

优化视频多个同时播放问题

LinWuTai 1 year ago
parent
commit
c08f87c6c0
3 changed files with 20 additions and 5 deletions
  1. 16 2
      pages/visitor/assetDetail/assetDetail.vue
  2. 1 1
      pages/visitor/index.vue
  3. 3 2
      utils/baseurl.js

+ 16 - 2
pages/visitor/assetDetail/assetDetail.vue

@@ -28,8 +28,8 @@
 		</view>
 		<view class="videoBox" v-if="videoList">
 			<view class="title">演示视频</view>
-			<view class="video" v-for="video in videoList" :key="video.id">
-				<video :src="playerURL(video.url)" controls :title="video.name" :type="video.type"></video>
+			<view class="video" v-for="(video, index) in videoList" :key="video.id">
+				<video :src="playerURL(video.url)" controls :id="video.id" :data-id="video.id" :title="video.name" @play="videoPlay" :type="video.type"></video>
 				<view class="info">{{video.name}}</view>
 			</view>
 		</view>
@@ -61,6 +61,20 @@
 			},
 			playerURL(url) {
 				return playerVideo(url)
+			},
+			videoPlay(e) {
+				// 获取当前视频id
+				let currentId = e.currentTarget.dataset.id;
+				// uni.createVideoContext获取视频上下文对象
+				this.videoContent = uni.createVideoContext(currentId);
+				// 获取json对象并遍历, 停止非当前视频
+				let videoList = this.videoList;
+				for (let i = 0; i < videoList.length; i++) {
+					let temp = videoList[i].id;
+					if (temp !== currentId) {
+						uni.createVideoContext(temp).pause();
+					}
+				}
 			}
 		},
 		onLoad(option) {

+ 1 - 1
pages/visitor/index.vue

@@ -141,7 +141,7 @@
 				text-align: center;
 				font-weight: bold;
 				font-size: $uni-title-font-size;
-				margin-bottom: 20rpx;
+				margin-bottom: 40rpx;
 			}
 			
 			.study {

+ 3 - 2
utils/baseurl.js

@@ -1,6 +1,7 @@
-let devUrl = 'https://sylwt.top/prod-api';
+//let devUrl = 'https://primeforcetech.cn:16061/prod-api';
+let devUrl = 'https://equipmgt.primeforcetech.cn/prod-api';
 // let devUrl = 'http://localhost:80/dev-api';
-let prodUrl = 'https://sylwt.top/prod-api';
+let prodUrl = 'https://equipmgt.primeforcetech.cn/prod-api';  //  443
 let baseUrl = process.env.NODE_ENV === 'development' ? devUrl : prodUrl;
 
 export default baseUrl;