尾随前行
尾随前行
  • 发布:2021-02-28 13:15
  • 更新:2022-02-11 19:26
  • 阅读:2298

使用video组件时,动态更改视频地址src没有反应

分类:uni-app

现在有一个视频列表数据,我在页面写了一个video组件(页面一次只能显示一个video),在组件的ended回调中去更改video的src地址,想让他播放下一个视频,但是这样做了之后发现没用

还请问各位大佬,这种情况我需要怎么做呢?

2021-02-28 13:15 负责人:无 分享
已邀请:
samshum22

samshum22

...唉,難搞,不知道背後出了什麼問題,我寫了兩個程序,兩個都是在playend的時候改counter然後 :src = getMediaFun() 取回相應的值.
但一個可用,一個不可用,兩個都是差不多的結構

samshum22

samshum22

<template>  
	<view class="content">  
		<text>TEST</text>  
		<button @click="back">null</button>  
		<button @click="back">back</button>  
		<view v-if="waited">  
			<view v-for="(myObject,key,myIndex)  in playingDict">  
			<text>| myObject:{{myObject}} | key:{{key}} | myIndex:{{myIndex}}</text>  
			<text>{{Object.keys(myObject)}}{{Object.values(myObject)}}</text>  
				<video class="myVideo" :src="getMedia(key)" @ended="playEnd(key)" show-loading=false controls=false  
					autoplay loop :style='  
				"left:"+myObject.left+"px;"+  
				"top:"+myObject.top+"px;"+  
				"width:"+myObject.width+"px;"+  
				"height:"+myObject.height+"px;"  
				'></video>  
			</view>  
		</view>  
		<view>  
			{{waited}}  
		</view>  
	</view>  
</template>  
  
<script>  
	export default {  
		data() {  
			return {  
				screen: 1,  
				staticPath: "/storage/emulated/0/your_app/1-1-",  
				playingDict: {  
					"A":{  
						"src":[  
							"/storage/emulated/0/your_app/1-1-1/gg.mp4",  
							"/storage/emulated/0/your_app/1-1-1/ff.mp4"],  
						"counter":0,  
						'left':0,  
						'top':0,  
						'width':640,  
						'height':360,  
					},  
					"B":{  
						"src":[  
							"/storage/emulated/0/your_app/1-1-1/ff.mp4",  
							"/storage/emulated/0/your_app/1-1-1/gg.mp4"],  
						"counter":0,  
						'left':0,  
						'top':360,  
						'width':640,  
						'height':360,  
					}  
				},  
				machineInfo: {},  
				waited: true  
			}  
		},  
		onLoad() {  
		},  
		onReady() {  
			  
		},  
		methods: {  
			getMedia(obj){  
				let index = this.playingDict[obj]['counter'] % this.playingDict[obj]['src'].length  
				console.log('getMedia')  
				return this.playingDict[obj]['src'][index]  
			},  
			playEnd(obj){  
				this.playingDict[obj]['counter'] += 1  
			},  
			  
			back() {  
				uni.redirectTo({  
					url: '../index/index'  
				});  
			},  
  
		},
2***@qq.com

2***@qq.com

先用一个空的view替代vedio的位置,然后获取到vedio的src后再用空的view隐藏,vedio标签显示

该问题目前已经被锁定, 无法添加新回复