当前位置: 首页 > 工具软件 > video.js > 使用案例 >

在Vue3中使用Video.js

李光华
2023-12-01

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官网提供代码

链接

 类似资料: