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

vue3+ts实时播放视频,视频分屏

使用vue3以及播放视频组件Jessibuca
Jessibuca地址
使用循环个数来实现分屏

效果图,四屏在这里插入图片描述
九屏
在这里插入图片描述

dom代码

<div class="icon">
	<div class="icon-box">
		<span class="text">分屏:</span>
		<el-icon class="iconsty" @click="oneVideo" style="margin-right: 24px;" title="单屏"><ele-FullScreen /></el-icon>
		<el-icon class="iconsty" @click="fourVideo" style="margin-right: 24px;" title="四屏"><ele-Menu /></el-icon>
		<el-icon class="iconsty" @click="nightVideo" title="九屏"><ele-Grid /></el-icon>
	</div>
	<div class="right-tetx" @click="allVedio" style="margin-right: 24px;" title="全屏">全屏</div>
</div>
<div class="videobox">
	<JessibucaDemo ref="JessibucaDemoRef" @click="videoBtn(index, item)" :style="liveStyle" v-for="(item, index) in state.spilt" :key="index" :class="state.videoIndex === index ? 'PlayVideo active' :'PlayVideo'" />
</div>

事件

import { reactive, ref } from 'vue';
const state = reactive({
	spilt: 1,
	videoIndex: 0
})
// 分频样式
const liveStyle = computed<any>(() => {
	let style = { width: '100%', height: '100%' }
	switch (state.spilt) {
		case 4:
			style = { width: '50%', height: '50%' }
			break
		case 9:
			style = { width: '33.33%', height: '33.333%' }
			break
	}
	return style
});

// 单频
const oneVideo = () => {
	state.videoIndex = 0
	state.spilt = 1
}
// 四频
const fourVideo = () => {
	state.videoIndex = 0
	state.spilt = 4
}
// 九频
const nightVideo = () => {
	state.videoIndex = 0
	state.spilt = 9
}

样式

.icon{
	display: flex;
	justify-content: space-between;
	z-index: 999;
	color: #000;
	.icon-box{
		display: flex;
		align-items: center;
		.text{
			font-size: 20px;
		}
		.iconsty{
			font-size: 20px;
			cursor: pointer;
		}
	}
	.right-tetx{
		font-size: 20px;
		cursor: pointer;
	}
}
.videobox{
	height: 70vh;
	display: flex;
	width: 100%;
	align-content: flex-start;
	justify-content: center;
	flex-wrap: wrap;
}
// 实时视频
.PlayVideo{
	position: relative;
	background-color: #000;
	.borderBox{
		z-index: 99999;
		position: absolute;
		width: 100% !important;
		top: 0;
		left: 0;
		height: 100% !important;
		border: 1px solid blue;
	}
}
.PlayVideo {
	border: 1px solid #505050;
}
::v-deep .is-active{
	background-color: rgba(20, 157, 251, 1);
	color: #fff;
}
.active{
	border: 2px solid blue !important;
}

全屏事件
下载依赖包
npm i screenfull@6.0.2

// 全屏
import screenfull from 'screenfull'
const allVedio = () => {
	//获取dom元素节点来实现指定元素全屏展示
    let el = document.querySelector('.videobox')
    //screenfull.isEnabled  此方法返回布尔值,判断当前能不能进入全屏
    if (!screenfull.isEnabled) {
        return false
    }
    //screenfull.toggle 此方法是执行全屏化操作。如果已是全屏状态,则退出全屏
    screenfull.toggle(el)
}

http://www.kler.cn/a/369450.html

相关文章:

  • HardLockUp
  • Redis 线程控制 问题
  • Ubuntu22.04环境搭建MQTT服务器
  • 温湿传感器(学习笔记下)
  • 力扣 167. 两数之和 II - 输入有序数组
  • 智能工厂的软件设计 专有名词(juncture/relation/selection):意识形态及认知计算机科学的架构、系统和运用
  • 【学术会议论文投稿】JavaScript在数据可视化领域的探索与实践
  • 若依框架前后端结构
  • 前端构建工具vite的优势
  • Java虚拟机JVM的简要工作原理
  • 从零学习大模型(三)-----GPT3(下)
  • 轻松拿捏!windows系统上安装Mamba
  • HarmonyOS 模块化设计
  • 机器人学习仿真框架
  • linux下xdg-open打开文件
  • 大厂面试真题-说说DDD中的领域驱动事件
  • CSS 常见选择器
  • 图像处理 -- 图像对比度的数学解析
  • 【python Arrow库】一个处理日期和时间的Python库
  • 【iOS】SDWebImage的使用
  • Linux 进程优先级 进程切换
  • 春秋云镜——SQL注入漏洞复现——CVE-2022-4230
  • Maven 空 JAR 的一个案例
  • 【Qt】使用正则表达式,从输入字符串中提取所有符合特定始、末符号的字符串。
  • Python基础之正则表达式
  • 微服务网关之Gateway