当前位置: 首页 > article >正文

swiper和video实现抖音刷视频功能

实现抖音刷视频功能 

<!--swiper实现整屏划动播放视频-->
<swiper :vertical="true" class="swiperVideo" style="height: 100vh;" @change="changeplay"
			@touchstart="touchStart" @touchend="touchEnd">
	<swiper-item v-for="(item, index) in swiperList" :key="item.id">
		<view class="bg-video">
			<view class="video">
				<videoPlayer ref="player" :video="item" :index="index"></videoPlayer>
			</view>
		</view>
	</swiper-item>
</swiper>

//上下滑动触发事件
changeplay(res) {
	console.log('res', res);
	clearTimeout(time)
	this.page = res.detail.current
	time = setTimeout(() => {
		if (this.pageStatrY < this.pageEndY) {

			console.log('向上滑动')
			setTimeout(() => {
				this.$refs.player[this.page].player()
			}, 20)

			this.$refs.player[this.page + 1].pause()
			this.pageStatrY = 0
			this.pageEndY = 0
		} else {
			console.log('向下滑动')
			setTimeout(() => {
				this.$refs.player[this.page].player()
			}, 20)
			console.log('page', this.page - 1, this.$refs.player);
			this.$refs.player[this.page - 1].pause()
			this.pageStatrY = 0
			this.pageEndY = 0
		}
	}, 1)
},
//获取向下滑动的值
touchStart(res) {

	this.pageStatrY = res.changedTouches[0].pageY
	console.log('pageStatrY', this.pageStatrY)
},
//获取向上滑动的值
touchEnd(res) {
	this.pageEndY = res.changedTouches[0].pageY
	console.log('pageEndY', this.pageEndY)
},

videoPlayer 组件

<template>
	<view class="videoPlayer">
		<video id="myVideo" class="video" :controls="false" :src="video" :loop="false" :autoplay="autoplay"
			:show-center-play-btn="false" style="pointer-events:none;will-change: transform;" @click="click"></video>
		
	</view>
</template>

<script>
	var timer = null
	export default {
		props: ['video', 'index'],
		data() { 
			return {
				play: false,
				dblClick: false,
				autoplay: false,
			};
		},
		mounted() {  
			this.videoContext = uni.createVideoContext('myVideo', this)
			this.atuo() 
		},

		methods: {
			click() {
				clearTimeout(timer)
				this.dblClick = !this.dblClick
				timer = setTimeout(() => {
					if (this.dblClick) { //判断是单击 即为true
						//单击
						if (this.play === false) {
							this.playThis()
						} else {
							this.pause()
						}
					} else {
						//双击
						// this.$emit('changeClick') //向父组件传递一个事件
					}
					this.dblClick = false //点击后重置状态 重置为false
				}, 300)
			},
			player() {
				//从头播放视频
				if (this.play === false) {
					this.videoContext.seek(0)
					this.videoContext.play()
					this.play = true
				}
			},
			pause() {
				//暂停视频
				if (this.play === true) {
					this.videoContext.pause()
					this.play = false
				}
			},
			playThis() {
				//播放当前视频
				if (this.play === false) {
					this.videoContext.play()
					this.play = true
				}
			},
			//首个视频自动播放
			atuo() {
				//首个视频自动播放
				if (this.index === 0) {
					this.autoplay = true
				}
			}
		},
	}
</script>

<style>
	.videoPlayer {
		height: 100vh;
		width: 100%;
	}

	.video {
		height: 100vh;
		width: 100%;
	}
</style>

!!!!目前我这个小程序是可以用的,但是华为快应用不行(uniapp转华为快应用)


http://www.kler.cn/news/160727.html

相关文章:

  • P1005 [NOIP2007 提高组] 矩阵取数游戏
  • 内衣洗衣机哪个牌子好用?家用小型洗衣机推荐
  • 296_C++_一个dialog对话框在执行exec向系统发送一个延后销毁事件时,另一个对话框立刻接管了上一个对话框的销毁事件,导致死UI
  • 定时器的使用及实现
  • MySQL - 并发控制与事务的隔离级别
  • 微服务实战系列之Redis
  • 安卓发布小技巧
  • 一键AI智能改写,一键AI智能生成原创文章
  • 网络安全(一)--网络环境构成,系统的安全
  • 外包干了3个月,技术倒退2年。。。
  • 修改错误的代码和改正错误的人生一样重要
  • 智能成绩表 - 华为OD统一考试(C卷)
  • 台灯应该买什么样的才能护眼?学生护眼必备护眼台灯推荐
  • 【毕业设计】基于雷达与深度学习的摔倒检测——微多普勒效应
  • Linux虚假唤醒
  • Unity传送门特效: The Beautiful Portal/Level up/Teleport/Warp VFX
  • 网络安全缓冲区溢出实验
  • Linux C语言 37- 进程间通信IPC
  • Python读写txt文件数据
  • vue管理系统模版
  • 编织魔法世界——计算机科学的奇幻之旅
  • [C++] new和delete
  • 自定义插件vue-router简单实现hashRouter设计思路
  • linux常用快捷键
  • 学习mysql记录
  • 说说react的事件机制?
  • Isaac Sim教程08 独立代码编程
  • C# WPF上位机开发(会员管理软件)
  • 启用属性,索引和存储的用途是什么?
  • Elasticsearch:什么是大语言模型(LLM)?