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

vue3使用vue3-video-play播放m3u8视频

1.安装vue3-video-play

 npm install vue3-video-play --save

2.在组件中使用

import 'vue3-video-play/dist/style.css';
import VideoPlay from 'vue3-video-play';// 视频配置项
const options = reactive({src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8', //视频源muted: false, //静音webFullScreen: false,speedRate: ['0.75', '1.0', '1.25', '1.5', '2.0'], //播放倍速autoPlay: true, //自动播放loop: false, //循环播放mirror: false, //镜像画面ligthOff: false, //关灯模式volume: 0.3, //默认音量大小control: true, //是否显示控制器poster: '',type: 'm3u8',
});

3.使用拖拽移动组件vue3-draggable-resizable,将视频放入这个盒子中,可以自由拖动位置,调节大小

npm install vue3-draggable-resizable

4.使用vue3-draggable-resizable

import Vue3DraggableResizable from 'vue3-draggable-resizable'
import 'vue3-draggable-resizable/dist/Vue3DraggableResizable.css'const x = ref(1000);
const y = ref(0);
const w = ref(100);
const h = ref(100);
const active = ref(false);
const disabledX = ref(false)
const print = (val) => {console.log(val)
}

5.结合使用vue3-draggable-resizable和vue3-video-play

<Vue3DraggableResizable v-if="cunzai" :lockAspectRatio="true":handles="['tl', 'tm', 'mr', 'ml', 'bl', 'bm', 'br']" :initW="320" :initH="180" :minW="320" :minH="180"v-model:x="x" v-model:y="y" v-model:w="w" v-model:h="h" v-model:active="active" :draggable="true":resizable="true" :parent="true" @activated="print('activated')" @deactivated="print('deactivated')"@drag-start="print('drag-start')" @resize-start="print('resize-start')" @dragging="print('dragging')"@resizing="print('resizing')" @drag-end="print('drag-end')" @resize-end="print('resize-end')"><div class="close" @click="close()"><Icon size="20" color="#1196db" type="md-close-circle" /></div><div><VideoPlay v-bind="options" width="100%" height="100%"/></div></Vue3DraggableResizable>

其中VideoPlay的宽度和高度都写为100%,这样视频的大小就可以跟随窗口的大小放大缩小

效果图:

放大一下:

 完美呈现。

完整代码:

<template><div><Vue3DraggableResizable v-if="cunzai" :lockAspectRatio="true":handles="['tl', 'tm', 'mr', 'ml', 'bl', 'bm', 'br']" :initW="320" :initH="180" :minW="320" :minH="180"v-model:x="x" v-model:y="y" v-model:w="w" v-model:h="h" v-model:active="active" :draggable="true":resizable="true" :parent="true" @activated="print('activated')" @deactivated="print('deactivated')"@drag-start="print('drag-start')" @resize-start="print('resize-start')" @dragging="print('dragging')"@resizing="print('resizing')" @drag-end="print('drag-end')" @resize-end="print('resize-end')"><div class="close" @click="close()"><Icon size="20" color="#1196db" type="md-close-circle" /></div><div><VideoPlay v-bind="options" width="100%" height="100%"/></div></Vue3DraggableResizable></div></template>
<script setup>import { ref, toRef, reactive } from 'vue';
import { onMounted, onUnmounted } from '@vue/runtime-core';
import { anchorEmits } from "element-plus";
const emit = defineEmits(['showEcharts']);
import { Message } from 'view-ui-plus';import Vue3DraggableResizable from 'vue3-draggable-resizable'
import 'vue3-draggable-resizable/dist/Vue3DraggableResizable.css'const x = ref(1000);
const y = ref(0);
const w = ref(100);
const h = ref(100);
const active = ref(false);
const disabledX = ref(false)
const print = (val) => {console.log(val)
}const cunzai = ref(false);
//关闭视频
function close() {cunzai.value = false
}
//打开视频
function dakai() {if (cunzai.value == true) {cunzai.value = false} else {cunzai.value = true}
}import 'vue3-video-play/dist/style.css';
import VideoPlay from 'vue3-video-play';// 视频配置项
const options = reactive({src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8', //视频源muted: false, //静音 webFullScreen: false,speedRate: ['0.75', '1.0', '1.25', '1.5', '2.0'], //播放倍速autoPlay: true, //自动播放loop: false, //循环播放mirror: false, //镜像画面ligthOff: false, //关灯模式volume: 0.3, //默认音量大小control: true, //是否显示控制器poster: '',type: 'm3u8',
});</script>

http://www.lryc.cn/news/518513.html

相关文章:

  • 使用API有效率地管理Dynadot域名,为文件夹中的域名统一设置电子邮件转发
  • Java虚拟机(Java Virtual Machine,JVM)
  • [免费]微信小程序(高校就业)招聘系统(Springboot后端+Vue管理端)【论文+源码+SQL脚本】
  • TCP Analysis Flags 之 TCP Retransmission
  • #Phi-4:微软 14B 参数开源模型,性能匹敌 OpenAI GPT-4o-mini,现已登陆 Ollama
  • JSON头文件调用
  • Swagger学习⑭——@Contact注解
  • 如何监听Vuex数据的变化?
  • Redis 优化秒杀(异步秒杀)
  • 前端中常用的单位度量(px,rpx,rem,em,vw,vh)+图片自适应
  • STM32之一种双通路CAN总线消息备份冗余处理方法(十三)
  • 从零开始:使用VSCode搭建Python数据科学开发环境
  • C#语言的字符串处理
  • 《安富莱嵌入式周报》第348期:开源低功耗测试仪,开源创意万用表,续航100-300小时,开源PCB电机,自制shell和网络协议栈,开源水培自动化系统
  • npm发布流程说明
  • 缓存-文章目录
  • LeetCode 3297.统计重新排列后包含另一个字符串的子字符串数目 I:滑动窗口
  • 如何在 Ubuntu 24.04 上安装 Memcached 服务器教程
  • 《深度学习模型在鸿蒙分布式框架下的跨设备高效之旅》
  • [python3]Excel解析库-xlutils
  • Springboot Bean创建流程、三种Bean注入方式(构造器注入、字段注入、setter注入)、循坏依赖问题
  • mybatisX插件的使用,以及打包成配置
  • 【初阶数据结构】线性表之单链表
  • CentOS7通过yum安装JDK
  • c# 常见的几种取整场景
  • 数据库回滚:大祸临头时
  • 【GoLang】两个字符串如何比较大小?以及字典顺序的比较规则
  • 5G学习笔记之SNPN系列之UE入网和远程配置
  • C#版OpenCv常用函数大全
  • Spring Boot教程之五十二:CrudRepository 和 JpaRepository 之间的区别