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>
相关推荐
红衣信几秒前
电影项目开发中的编程要点与用户体验优化
前端·javascript·github
LeeAt5 分钟前
npm:详细解释前端项目开发前奏!!
前端·node.js·html
山有木兮木有枝_7 分钟前
JavaScript对象深度解析:从创建到类型判断 (上)
前端
crary,记忆15 分钟前
MFE(微前端) Module Federation:Webpack.config.js文件中每个属性的含义解释
前端·学习·webpack
清风~徐~来17 分钟前
【Qt】控件 QWidget
前端·数据库·qt
前端小白从0开始18 分钟前
关于前端常用的部分公共方法(二)
前端·vue.js·正则表达式·typescript·html5·公共方法
真的很上进24 分钟前
2025最全TS手写题之partial/Omit/Pick/Exclude/Readonly/Required
java·前端·vue.js·python·算法·react·html5
用户69452955217027 分钟前
国内开源版“Manus”——AiPy实测:让你的工作生活走上“智动”化
前端·后端
帅夫帅夫30 分钟前
一文手撕call、apply、bind
前端·javascript·面试
J船长32 分钟前
APK战争 diffoscope
前端