1,安裝vue-video-player
npm install vue-video-player --save
2,在main.js里面引入
import VideoPlayer from 'vue-video-player'
require('vue-video-player/node_modules/video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.use(VideoPlayer)
html配置
<video-player class="video-player vjs-custom-skin" ref="videoPlayer" :playsinline="true" :options="playerOptions"></video-player>
data配置
playerOptions: { // playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度 autoplay: true, // 如果true,瀏覽器准備好時開始回放。 muted: false, // 默認情況下將會消除任何音頻。 loop: false, // 導致視頻一結束就重新開始。 preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應該開始下載視頻數據。auto瀏覽器選擇最佳行為,立即開始加載視頻(如果瀏覽器支持) language: 'zh-CN', aspectRatio: '15:10', // 將播放器置於流暢模式,並在計算播放器的動態大小時使用該值。值應該代表一個比例 - 用冒號分隔的兩個數字(例如"16:9"或"4:3") fluid: false, // 當true時,Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應其容器。 sources: [ { type: 'application/x-mpegURL', // 這里的種類支持很多種:基本視頻格式、直播、流媒體等,具體可以參看git網址項目 src: '123.MP4' } ], controls: true, hls: true, poster: '', // 你的封面地址 width: 200, // 播放器寬度 height: 200, notSupportedMessage: '連接中斷', // 允許覆蓋Video.js無法播放媒體源時顯示的默認信息。 controlBar: { timeDivider: false, durationDisplay: false, remainingTimeDisplay: false, fullscreenToggle: true // 全屏按鈕 } }
動態設置改變視頻地址
this.playerOptions['sources'][0]['src'] = src
詳細請看官網