下載vue-video-player
npm install vue-video-player --save
在main.js文件引入
import VideoPlayer from 'vue-video-player'require('video.js/dist/video-js.css')require('vue-video-player/src/custom-theme.css')Vue.use(VideoPlayer)在頁(yè)面中引入
<video-player ref="videoPlayer" class="video-player vjs-custom-skin" :playsinline="true" :options="playerOptions" @play="onPlayerPlay($event)"http://監(jiān)聽(tīng)開(kāi)始狀態(tài) @pause="onPlayerPause($event)"http://監(jiān)聽(tīng)暫停狀態(tài) />
在頁(yè)面中data中配置
playerOptions: { // playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度 autoplay: false, // 如果true,瀏覽器準(zhǔn)備好時(shí)開(kāi)始回放。 muted: false, // 默認(rèn)情況下將會(huì)消除任何音頻。 loop: false, // 導(dǎo)致視頻一結(jié)束就重新開(kāi)始。 preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應(yīng)該開(kāi)始下載視頻數(shù)據(jù)。auto瀏覽器選擇最佳行為,立即開(kāi)始加載視頻(如果瀏覽器支持) language: 'zh-CN', aspectRatio: '16:9', // 將播放器置于流暢模式,并在計(jì)算播放器的動(dòng)態(tài)大小時(shí)使用該值。值應(yīng)該代表一個(gè)比例 - 用冒號(hào)分隔的兩個(gè)數(shù)字(例如"16:9"或"4:3") fluid: true, // 當(dāng)true時(shí),Video.js player將擁有流體大小。換句話說(shuō),它將按比例縮放以適應(yīng)其容器。 sources: [ { type: 'video/mp4', // 這里的種類支持很多種:基本視頻格式、直播、流媒體等,具體可以參看git網(wǎng)址項(xiàng)目 src: 'https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm' // url地址 } ], hls: true, poster: 'http://pic33.nipic.com/20131007/13639685_123501617185_2.jpg', // 你的封面地址 width: document.documentElement.clientWidth, // 播放器寬度 notSupportedMessage: '此視頻暫無(wú)法播放,請(qǐng)稍后再試', // 允許覆蓋Video.js無(wú)法播放媒體源時(shí)顯示的默認(rèn)信息。 controlBar: { timeDivider: true, durationDisplay: true, remainingTimeDisplay: false, fullscreenToggle: true // 全屏按鈕 } },掛載視頻組件(非必須)不寫(xiě)這一步也可以實(shí)現(xiàn)播放,添加這個(gè)是為了自定義按鈕使用
computed: { player() { return this.$refs.videoPlayer.player//自定義播放 } },官方文檔
video.js:https://docs.videojs.com/docs/api/player.html
vue-video-player:https://github.com/surmon-china/vue-video-player
不需要兼容m3u8的,以上就可以實(shí)現(xiàn)能播放
兼容m3u8的需要下載
npm install --save videojs-contrib-hls
在文件中引入
import ‘videojs-contrib-hls'
我這么引入會(huì)出現(xiàn)找不到文件,我沒(méi)找到問(wèn)題所在,如果這么引入不行,可以改為
新聞熱點(diǎn)
疑難解答
圖片精選