微信小程序ios无法播放视频,安卓可以,视频格式为mp4?
发布于 7 年前 作者 yinmin 9596 次浏览 来自 问答

视频路径为https://yhp.pg024.com/Upload/video/3974E3A4021644F9234C2B04F911D3C9.mp4

<template>
	<view>
		<video class="videoPart" :src="src" controls loop :show-fullscreen-btn="false" 
			:id="`video_${src}`" ref="`video_${src}`" @timeupdate="timeupdate">
		</video>
	</view>
</template>

<script>
	export defaultprops:{
			src:{
				type:String,
				default:''
			},
			play:{
				type:Boolean,
				default:false
			},
			initialTime:{
				type:Number,
				default:0
			},
		},
		data(){
			return{
				time:0,
				duration:0,
				playFirst:true
			}
		},
		mounted() {
			this.videoCtx = uni.createVideoContext(`video_${this.src}`,this)
		},
		methods:{
			timeupdate(event){
				this.duration = event.detail.duration
				if(!this.play) return
				if(this.time>=this.duration) this.time=0
				this.time = event.detail.currentTime
			},
			videoPlay(){
				if(this.play){
					this.videoCtx.play();
					if(this.playFirst){
						this.videoCtx.seek(this.startTime)
						this.playFirst = false
					} 
				}else{
					this.videoCtx.pause();
					this.$emit('pause',this.time)
				}
			},
		},
		watch:{
			play(newVal,oldVal){
				this.videoPlay()
			},
			startTime:{
				immediate: true,
				handler(newVal,oldVal){
					this.time = newVal
				}
			},
		},
		computed:{
			startTime(){
				return this.initialTime
			}
		}
	}
</script>

<style scoped>
	.videoPart{width: 100%;height: auto;max-height: 100%;position: static;}
</style>
1 回复

你好,建议加上binderror排查下是否有报错信息提示

回到顶部