前排提示:这个是基于vue的
添加依赖
- 找到项目的
package.json
文件在dependencies
中加入依赖
"vue-video": "^0.1.7",
"vue-video-player": "^5.0.2",
"video.js": "^7.10.2",
"videojs-contrib-hls": "^5.15.0",
- 效果如下:
"dependencies": {
"axios": "0.18.0",
"echarts": "^4.1.0",
"element-ui": "^2.14.1",
"js-cookie": "2.2.0",
"normalize.css": "7.0.0",
"nprogress": "0.2.0",
"video.js": "^7.10.2",
"videojs-contrib-hls": "^5.15.0",
"vue": "2.5.17",
"vue-router": "3.0.1",
"vue-video": "^0.1.7",
"vue-video-player": "^5.0.2",
"vuex": "3.0.1",
"vuex-persistedstate": "^4.0.0-beta.1"
},
- 然后
npm install
安装依赖
启用VideoPlayer
- 在项目的
main.js
文件中加入代码启用
import Vue from 'vue'
...
import VideoPlayer from 'vue-video-player'
...
Vue.use(VideoPlayer);
- 效果示例
import Vue from 'vue'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n
import '@/styles/index.scss' // global css
import App from './App'
import router from './router'
import store from './store'
// eslint-disable-next-line no-unused-vars
import VideoPlayer from 'vue-video-player'
import '@/icons' // icon
import '@/permission' // permission control
Vue.use(ElementUI, { locale })
Vue.use(VideoPlayer);
Vue.config.productionTip = false
new Vue({
el: '#app',
router,
store,
render: h => h(App)
})
引入Video
- 在页面中引入重点代码即可
<template>
<div class="app-container">
<div class="player-container">
<video-player class="vjs-custom-skin" :options="playerOptions"></video-player>
</div>
...
<el-form label-width="120px">
</el-form>
</div>
</template>
<script>
// 引入video样式
import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'
export default {
inject:['reload'],
data() {
return {
playerOptions: {
playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
autoplay: true, //如果true,浏览器准备好时开始回放。
controls: false, //控制条
preload: 'auto', //视频预加载
muted:'muted' , //默认情况下将会消除任何音频。
loop: true, //导致视频一结束就重新开始。
language: 'zh-CN',
aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
sources: [{
type: 'video/mp4',
// src:'vide'
src: '/static/lol.mp4',//你所放置的视频的地址,最好是放在服务器上
}],
poster: "", //你的封面地址(覆盖在视频上面的图片)
width: document.documentElement.clientWidth,
notSupportedMessage: '此视频暂无法播放,请稍后再试' //允许覆盖Video.js无法播放媒体源时显示的默认信息。
}
}
},
created() {
},
methods:{
}
}
</script>
<style scoped>
.vjs-custom-skin{
position: fixed; right:0px; bottom: 0px; left: 0px;
min-width: 100%; min-height: 100%;
width: auto; height: auto;
}
</style>