1、安装

npm install --save-dev video.js

2、代码

<script setup>
import { onMounted, onUnmounted, ref } from "vue"
import videojs from "video.js"
import "video.js/dist/video-js.css"

const videoPlayer = ref(null)

const myPlayer = ref(null)

onMounted(() => {
  myPlayer.value = videojs(videoPlayer.value, {
    poster: "//vjs.zencdn.net/v/oceans.png",
    controls: true,
    sources: [
      {
        src: "//vjs.zencdn.net/v/oceans.mp4",
        type: 'video/mp4',
      }
    ],
    controlBar: {
      remainingTimeDisplay: {
        displayNegative: false
      }
    },
    playbackRates: [0.5, 1, 1.5, 2]
  }, () => {
    myPlayer.value.log("play.....")
  })
})

onUnmounted(() => {
  if (myPlayer.value) {
    myPlayer.value.dispose()
  }
})


</script>

<template>
  <div>
    <video ref="videoPlayer" class="video-js" style="margin: auto auto"></video>
  </div>
</template>

3、Video.js官网提供代码

链接

Logo

前往低代码交流专区

更多推荐