什么是Video.js
Video.js是一個(gè)有著HTML5背景的網(wǎng)絡(luò)視頻播放器碑宴。它同時(shí)支持HTM5和Flash視頻蛹含,簡(jiǎn)單來說就是HTMl5 和 Flash 視頻播放器
安裝
$ npm install video.js
main.js中引入
import Video from 'video.js'
import 'video.js/dist/video-js.css'
Vue.prototype.$video = Video
使用(代碼中有注釋說明)
<template>
<div class="test_two_box">
<video
id="myVideo"
class="video-js"
>
<source
src="http://vjs.zencdn.net/v/oceans.mp4"
type="video/mp4"
>
</video>
</div>
</template>
<script>
/* eslint-disable */
export default {
name: "TestTwo",
data() {
return {};
},
mounted() {
this.initVideo();
},
methods: {
initVideo() {
//初始化視頻方法
let myPlayer = this.$video(myVideo, {
//確定播放器是否具有用戶可以與之交互的控件按厘。沒有控件秃流,啟動(dòng)視頻播放的唯一方法是使用autoplay屬性或通過Player API围详。
controls: true,
//自動(dòng)播放屬性,muted:靜音播放
autoplay: "muted",
//建議瀏覽器是否應(yīng)在<video>加載元素后立即開始下載視頻數(shù)據(jù)硫痰。
preload: "auto",
//設(shè)置視頻播放器的顯示寬度(以像素為單位)
width: "800px",
//設(shè)置視頻播放器的顯示高度(以像素為單位)
height: "400px"
});
}
}
};
</script>
<style scoped>
</style>
實(shí)現(xiàn)效果截圖
進(jìn)入這個(gè)組件時(shí)衩婚,自動(dòng)默認(rèn)播放視頻
附上Video.js官網(wǎng)地址:Video.js