收藏
回答

微信小程序ios无法播放视频,安卓可以,视频格式为mp4?

视频路径为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 个回答

登录 后发表内容
问题标签