在这里插入图片描述

video 在公众号自动播放事件
WeixinJSBridge.invoke(‘getNetworkType’, {}, e => {
audo.play();
uni.createVideoContext(‘myVideo’,this).seek(0);
uni.createVideoContext(‘myVideo’,this).play();
})

使用object-fit使内容填充不留黑边

object-fit

contain 当视频大小与 video 容器大小不一致时,视频的表现形式。
contain:包含,fill:填充,cover:覆盖

1、在template中添加

<template>
	<view>
		<video :autoplay="false" :src="node.attr.src" id="myVideo" :autoplay="true"
		:poster="node.attr.src+'?x-oss-process=video/snapshot,t_100,f_jpg'"
		@fullscreenchange="fullscreen" :object-fit="objectFit"></video>
	</view>
</template>

2、在script中添加方法

<script>
let audo = uni.createInnerAudioContext()
audo.loop = true
export default {
	data(){
		return{
			objectFit: 'cover',
		}
	},
	mounted() {
		// #ifdef H5
		WeixinJSBridge.invoke('getNetworkType', {}, e => {
			audo.play();
			uni.createVideoContext('myVideo',this).seek(0);
			uni.createVideoContext('myVideo',this).play();
		})
		// #endif
	},
	onHide(){
		// #ifdef H5
		uni.createVideoContext('myVideo',this).pause()
		audo.pause()
		// #endif
	},
	onUnload(){
		// #ifdef H5
		uni.createVideoContext('myVideo',this).pause()
		audo.pause()
		// #endif
	},
	methods:{
		fullscreen(event) {
			if(event.detail.fullScreen) this.objectFit='contain';
			else this.objectFit='cover';
		}
	}
};
</script>
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐