官網地址:https://www.npmjs.com/package/vue-video-player
1.輸入命令:
npm install vue-video-player --save
npm install --save videojs-contrib-hls
2.全局引入--main.js:
import VideoPlayer from 'vue-video-player'
import 'video.js/dist/video-js.css'
Vue.use(VideoPlayer)
3.頁面對應的template文件:
(想要引入的css有效,class名不能變)
<video-player class="video-player vjs-custom-skin" ref="videoPlayer" :playsinline="true"
@play="androidPlay($event)" //暫停視頻事件
:options="playerOptions" ></video-player>
4.頁面對應的script文件:
import "video.js/dist/video-js.css";
import "vue-video-player/src/custom-theme.css";
import "videojs-contrib-hls";
playerOptions: {
playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
autoplay: false, //如果true,瀏覽器准備好時開始回放。
controls: true, //控制條
preload: "auto", //視頻預加載
muted: false, //默認情況下將會消除任何音頻。
loop: false, //導致視頻一結束就重新開始。
language: "zh-CN",
aspectRatio: "16:9", // 將播放器置於流暢模式,並在計算播放器的動態大小時使用該值。值應該代表一個比例 - 用冒號分隔的兩個數字(例如"16:9"或"4:3")
fluid: true, // 當true時,Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應其容器。
sources: [
{
type: "video/mp4",
src: "http://vjs.zencdn.net/v/oceans.mp4"
}
],
poster:
"http://static.smartisanos.cn/pr/img/video/video_03_cc87ce5bdb.jpg", //你的封面地址
width: document.documentElement.clientWidth,
notSupportedMessage: "此視頻暫無法播放,請稍后再試", //允許覆蓋Video.js無法播放媒體源時顯示的默認信息。
controlBar: {
timeDivider: true,
durationDisplay: true,
remainingTimeDisplay: false,
fullscreenToggle: false //全屏按鈕是否顯示
}
},
5.暫停視頻事件(如果無關,可以略過)
androidPlay(player) {
this.currentPlay = player.el_.children[0];
},
在想要暫停視頻的方法中
if (this.currentPlay) {
this.currentPlay.pause();
}