Skip to content
uniapp点击屏幕播放视频默认静音播放兼容微信浏览器
js
<template>
	<view class="container w-screen h-screen relative">
		<video id="myVideo" class="w-full h-686 absolute top-280" src="http://192.168.1.92:5500/白色.mp4" controls playsinline
			webkit-playsinline autoplay muted loop>
		</video>
	</view>
</template>
<script setup>
import { onMounted } from 'vue';

	onMounted(() => {
		// // 监听触摸移动事件
		window.addEventListener('touchmove', function(event) {
			const videoContext = uni.createVideoContext('myVideo');
			videoContext.play();
		}, false);
		
		// // 监听触摸开始
		window.addEventListener('touchstart', function(event) {
			const videoContext = uni.createVideoContext('myVideo');
			videoContext.play();
		}, false);
		
		// // 监听屏幕点击
		window.addEventListener('click', function(event) {
			const videoContext = uni.createVideoContext('myVideo');
			videoContext.play();
		}, false);
	})
</script>
<style lang="scss">
</style>