Giter Site home page Giter Site logo

xdlumia / vue3-video-play Goto Github PK

View Code? Open in Web Editor NEW
578.0 578.0 96.0 5.66 MB

适用于 Vue3 的 hls.js 播放器组件,配置丰富,界面还算好看

Home Page: https://codelife.cc/vue3-video-play/

HTML 0.65% Vue 68.17% JavaScript 9.64% Less 10.28% TypeScript 8.83% Shell 1.27% CSS 1.14%
video video-player vue3

vue3-video-play's Introduction

Version Downloads GitHub stars GitHub issues GitHub forks GitHub last commit license

NPM

必须使用 [email protected]及以上版本

Vue3-video-play

适用于 Vue3 的 hls.js 播放器组件 | 并且支持 MP4/WebM/Ogg 格式 配置强大,UI 还算好看

功能一览

  1. 支持快捷键操作
  2. 支持倍速播放设置
  3. 支持镜像画面设置
  4. 支持关灯模式设置
  5. 支持画中画模式播放
  6. 支持全屏/网页全屏播放
  7. 支持从固定时间开始播放
  8. 支持移动端,移动端会自动调用自带视频播放器
  9. 支持 hls 视频流播放,支持直播
  10. hls 播放支持清晰度切换

主页示例

https://codelife.cc/vue3-video-play/

近期更新 v1.3.3 🎉

  • 修复: 右键事件错误

使用指南

安装

npm 安装:

npm i vue3-video-play --save

yarn 安装:

yarn add vue3-video-play --save

开始使用

全局使用

import { createApp } from "vue";
import App from "./App.vue";
let app = createApp(App);

import vue3videoPlay from "vue3-video-play"; // 引入组件
import "vue3-video-play/dist/style.css"; // 引入css
app.use(vue3videoPlay);

app.mount("#app");

组件内使用

// require style
import "vue3-video-play/dist/style.css";
import { videoPlay } from "vue3-video-play";
export default {
  components: {
    videoPlay,
  },
};

基本示例

提供了丰富了配置功能 :::demo 自定义配置 比如自定义 poster。

<template>
  <div>
    <vue3VideoPlay
      v-bind="options"
      poster="https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/ironMan.jpg"
    />
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";
const options = reactive({
  width: "800px", //播放器宽度
  height: "450px", //播放器高度
  color: "#409eff", //主题色
  title: "", //视频名称
  src: "https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/IronMan.mp4", //视频源
  muted: false, //静音
  webFullScreen: false,
  speedRate: ["0.75", "1.0", "1.25", "1.5", "2.0"], //播放倍速
  autoPlay: false, //自动播放
  loop: false, //循环播放
  mirror: false, //镜像画面
  ligthOff: false, //关灯模式
  volume: 0.3, //默认音量大小
  control: true, //是否显示控制
  controlBtns: [
    "audioTrack",
    "quality",
    "speedRate",
    "volume",
    "setting",
    "pip",
    "pageFullScreen",
    "fullScreen",
  ], //显示所有按钮,
});
</script>

<style scoped></style>

:::

可以通过propsspeed开启或关闭进度条功能, 并且通过 currentTime属性控制从 60 秒开始播放

:::demo 通过speed关闭进度条拖动功能。 并且通过 currentTime属性控制从 60 秒开始播放

<template>
  <div>
    <vue3VideoPlay
      v-bind="options"
      poster="https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/ironMan.jpg"
    />
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";

const options = reactive({
  width: "500px", //播放器高度
  height: "260px", //播放器高度
  color: "#409eff", //主题色
  currentTime: 60,
  speed: false, //关闭进度条拖动
  title: "", //视频名称
  src: "https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/IronMan.mp4", //视频源
});
</script>

<style scoped></style>

:::

还可以通过propscontrol属性 来控制是否显示控制器 :::demo 通过control 来控制是否显示控制器

<template>
  <div>
    <vue3VideoPlay
      v-bind="options"
      poster="https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/ironMan.jpg"
    />
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";

const options = reactive({
  width: "500px", //播放器高度
  height: "260px", //播放器高度
  color: "#409eff", //主题色
  control: false, //是否显示控制器
  title: "", //视频名称
  src: "https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/IronMan.mp4", //视频源
});
</script>

<style scoped></style>

:::

事件示例

:::demo vue3-video-play 支持原生video所有事件。

<template>
  <div>
    <vue3VideoPlay
      width="800px"
      title="钢铁侠"
      :src="options.src"
      :poster="options.poster"
      @play="onPlay"
      @pause="onPause"
      @timeupdate="onTimeupdate"
      @canplay="onCanplay"
    />
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";

const options = reactive({
  src: "https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/IronMan.mp4", //视频源
  poster: "", //封面
});
const onPlay = (ev) => {
  console.log("播放");
};
const onPause = (ev) => {
  console.log(ev, "暂停");
};

const onTimeupdate = (ev) => {
  console.log(ev, "时间更新");
};
const onCanplay = (ev) => {
  console.log(ev, "可以播放");
};
</script>

<style scoped></style>

:::

Hls m3u8 视频/直播

:::demo vue3-video-play 支持 m3u8(hls)播放

<template>
  <div>
    <vue3VideoPlay
      width="800px"
      title="冰河世纪"
      :src="options.src"
      :type="options.type"
      :autoPlay="false"
    />
  </div>
</template>
<script setup lang="ts">
import { reactive } from "vue";
const options = reactive({
  src: "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8", //视频源
  type: "m3u8", //视频类型
});
</script>

<style scoped></style>

:::

Props

vue3-video-play 支持 video 原生所有 Attributes video 原生属性 使用方式和 props 属性使用一致

名称 说明 类型 可选值 默认值
width 播放器宽度 string - 800px
height 播放器高度 string - 450px
color 播放器主色调 string - #409eff
src 视频资源 string - -
title 视频名称 string - -
type 视频类型 string - video/mp4
poster 视频封面 string - 视频第一帧
webFullScreen 网页全屏 boolean - false
speed 是否支持快进快退 boolean - true
currentTime 跳转到固定播放时间(s) number - 0
playsinline ios 点击屏幕是否全屏 boolean - false
muted 静音 boolean - false
speedRate 倍速配置 array - ["2.0", "1.0", "1.5", "1.25", "0.75", "0.5"]
autoPlay 自动播放 boolean - false,为 true 时会自动静音
loop 循环播放 boolean - false
mirror 镜像画面 boolean - false
ligthOff 关灯模式 boolean - false
volume 默认音量 number 0-1 0.3
control 是否显示控制器 boolean - true
controlBtns 控制器显示的按钮 array ['audioTrack', 'quality', 'speedRate', 'volume', 'setting', 'pip', 'pageFullScreen', 'fullScreen'] ['audioTrack', 'quality', 'speedRate', 'volume', 'setting', 'pip', 'pageFullScreen', 'fullScreen']
preload 预加载 string meta/auto/none auto

props属性 controlBtns 按钮说明

名称 说明
audioTrack 音轨切换按钮
quality 视频质量切换按钮
speedRate 速率切换按钮
volume 音量
setting 设置
pip 画中画按钮
pageFullScreen 网页全屏按钮
fullScreen 全屏按钮

Events

vue3-video-play 支持 video 原生所有事件 video 默认事件

事件名称 说明 回调
mirrorChange 镜像翻转事件 val
loopChange 循环播放开关事件 val
lightOffChange 关灯模式事件 val
loadstart 客户端开始请求数据 event
progress 客户端正在请求数据 event
error 请求数据时遇到错误 event
stalled 网速失速 event
play 开始播放时触发 event
pause 暂停时触发 event
loadedmetadata 成功获取资源长度 event
loadeddata 缓冲中 event
waiting 等待数据,并非错误 event
playing 开始回放 event
canplay 暂停状态下可以播放 event
canplaythrough 可以持续播放 event
timeupdate 更新播放时间 event
ended 播放结束 event
ratechange 播放速率改变 event
durationchange 资源长度改变 event
volumechange 音量改变 event

快捷键说明

支持快捷键操作

键名 说明
Space 暂停/播放
方向右键 → 单次快进 10s,长按 5 倍速播放
方向左键 ← 快退 10s
方向上键 ↑ 音量+10%
方向下键 ↓ 音量-10%
Esc 退出全屏/退出网页全屏
F 全屏/退出全屏

Author

xdlumia

点个 start

vue3-video-play

vue3-video-play's People

Contributors

mmdjiji avatar sanjeever avatar xdlumia avatar zhangzhichaolove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue3-video-play's Issues

怎么切换视频

vue-video-player 可以用this.$refs.videoPlayer.player.src('newUrl')
这个直接改options.src=newUrl 没有作用

为什么一直报请求错误呢

<script lang="ts"> import { defineComponent, reactive } from 'vue' import 'vue3-video-play/dist/style.css' import { videoPlay } from 'vue3-video-play' export default defineComponent({ name: 'home', components: { videoPlay, }, setup() { const options = reactive({ width: '100%', // 播放器高度 height: '450px', // 播放器高度 color: '#409eff', // 主题色 muted: false, // 静音 webFullScreen: false, autoPlay: false, // 自动播放 loop: false, // 循环播放 mirror: false, // 镜像画面 ligthOff: false, // 关灯模式 volume: 0.3, // 默认音量大小 control: true, // 是否显示控制器 title: '', // 视频名称 src: './img/wendice.mp4', // 视频源 poster: '', // 封面 }) return { options, } }, })

关于一些优化建议

链接失效或者出错时可否添加文字提示比如:‘视频跑路了’,‘链接失效等’,目前是loading转圈,不知道是何错误。
image

怎么销毁组件或者中断请求流的方法,类似于dispose()

这个问题的优先级应该是高于其他的

video 里有一个 dispose() 方法可以销毁请求流

作者的组件里没有这个方法,导致了,切换路由时,请求流不会中断,即便把数据对象清空,依旧在一直发送请求

再次进入组件后,会进行累加前一次的请求流,进行多次重复的请求

请问视频支持哪些格式?

up主,我现在测试的视频格式只能是:mp4格式,请问现在支持多少格式?能否出一个列表:如

  • MP4
  • AVI
  • AV4
  • 等等

vue3.0 + vite使用打包报错了,请问有什么办法解决嘛

warning package.json: No license field
$ vue-tsc --noEmit && vite build
src/views/watch/index.vue(154,27): error TS7016: Could not find a declaration file for module 'vue3-video-play'. 'd:/Project/git/help-center-dlz/node_modules/vue3-video-play/dist/index.umd.js' implicitly has an 'any' type.
Try npm i --save-dev @types/vue3-video-play if it exists or add a new declaration (.d.ts) file containing declare module 'vue3-video-play';
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

播放M3u8格式文件的时候,loading状态一直没变

播放M3u8格式文件的时候,loading状态一直没变,在DOM里吧loading删除视频已经加载出来了,不知道是不是视频过大导致,本视频 有 一小时四十四分钟 ,其他一小时的同格式视频可以正常播放,麻烦看一下呢,谢谢

vue3引入报错不能使用

使用默认引入后,使用后出现错误Uncaught (in promise) TypeError: Cannot read properties of null (reading 'setupContext')

自动播放没有声音

自动播放没有声音,需求需要自动播放可以控制播放声音,可以实现吗

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.