vue中使用vue-video-player,播放m3u8格式

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)

3,頁面使用插件


<video-player

? ? ? ? ? ref="videoPlayer"

? ? ? ? ? class="video-player vjs-custom-skin"

? ? ? ? ? :playsinline="true"

? ? ? ? ? :options="playerOptions"

? ? ? ? />

4,data配置


playerOptions: {

? ? ? ? autoplay: false, // 如果true,瀏覽器準備好時開始回放。

? ? ? ? muted: false, // 默認情況下將會消除任何音頻。

? ? ? ? loop: false, // 導致視頻一結束就重新開始。

? ? ? ? preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應該開始下載視頻數據。auto瀏覽器選擇最佳行為,立即開始加載視頻(如果瀏覽器支持)

? ? ? ? language: 'zh-CN',

? ? ? ? aspectRatio: '4:3', // 將播放器置于流暢模式,并在計算播放器的動態大小時使用該值。值應該代表一個比例 - 用冒號分隔的兩個數字(例如"16:9"或"4:3")

? ? ? ? fluid: true, // 當true時,Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應其容器。

? ? ? ? sources: [{

? ? ? ? ? type: 'application/x-mpegURL', // 這里的種類支持很多種:基本視頻格式、直播、流媒體等,具體可以參看git網址項目

? ? ? ? ? src: " xxxxx" // 視頻url地址?

? ? ? ? }],

? ? ? ? poster: require('xxxxx'), // 你的封面地址

? ? ? ? // width: document.documentElement.clientWidth, //播放器寬度

? ? ? ? notSupportedMessage: '此視頻暫無法播放,請稍后再試', // 允許覆蓋Video.js無法播放媒體源時顯示的默認信息。

? ? ? ? controlBar: {

? ? ? ? ? timeDivider: true,

? ? ? ? ? durationDisplay: true,

? ? ? ? ? remainingTimeDisplay: false,

? ? ? ? ? fullscreenToggle: true // 全屏按鈕

? ? ? ? }

? ? ? }

我在項目中實時視頻用的是m3u8數據流,以上的操作正常視頻格式已經可以使用,還不可以直接使用m3u8數據流格式,以下是兼容.m3u8格式的視頻操作

1,需要安裝插件videojs-contrib-hls

命令:npm install --save videojs-contrib-hls

2,在main.js里面

const hls =require("videojs-contrib-hls")

Vue.use(hls)



完成,現在就可以播放m3u8數據流實時視頻了。

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容