一、安裝
npm install vue-video-player --save
二、在組件中引用
import { videoPlayer } from 'vue-video-player'
import 'video.js/dist/video-js.css'
export default {
components: {
videoPlayer
}
}
三、HTML代碼
<template>
<div class="container">
<video-player class="video-player vjs-custom-skin"
ref="videoPlayer"
:playsinline="true"
:options="playerOptions">
</video-player>
</div>
</template>
四、JS代碼
<script>
import { videoPlayer } from 'vue-video-player'
import 'video.js/dist/video-js.css'
export default {
name: "DriveVideo",
components: {
videoPlayer
},
data() {
return {
playerOptions: {
playbackRates: [0, 5, 1.0, 1.5, 2.0],
// 如果爲true,瀏覽器準備好時開始回放。
autoplay: false,
// 默認情況下將會消除任何音頻。
muted: false,
// 是否視頻一結束就重新開始。
loop: false,
// 建議瀏覽器在<video>加載元素後是否應該開始下載視頻數據。auto瀏覽器選擇最佳行爲,立即開始加載視頻(如果瀏覽器支持)
preload: 'auto',
language: 'zh-CN',
// 將播放器置於流暢模式,並在計算播放器的動態大小時使用該值。值應該代表一個比例 - 用冒號分隔的兩個數字(例如"16:9"或"4:3")
aspectRatio: '16:9',
// 當true時,Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應其容器。
fluid: true,
sources: [{
// type: "video/mp4", // 類型
src: 'https://video.pearvideo.com/mp4/short/20200209/cont-1650197-14888002-hd.mp4' // url地址
}],
// 封面地址
poster: '',
// 允許覆蓋Video.js無法播放媒體源時顯示的默認信息。
notSupportedMessage: '此視頻暫無法播放,請稍後再試',
controlBar: {
timeDivider: true, // 當前時間和持續時間的分隔符
durationDisplay: true, // 顯示持續時間
remainingTimeDisplay: false, // 是否顯示剩餘時間功能
fullscreenToggle: true // 是否顯示全屏按鈕
}
}
}
}
}
</script>
具體學習可以看Github:
https://github.com/surmon-china/vue-video-player