网页视频播放器
安装插件
npm install @easydarwin/easyplayer --save
npm install copy-webpack-plugin@5.1.2 --save-dev
cnpm install --save videojs-contrib-hls
cnpm install vue-video-player --save
video.vue
<template>
<!-- vue-video-player -->
<div class="videoBox">
<div class="videoBoxCenter">
<video-player
ref="videoPlayer"
:playsinline="true"
:options="playerOptions"
class="video-player vjs-custom-skin"
/>
</div>
<!-- 采用easyplayer.js -->
<div class="videoBoxCenter1">
<easy-player :video-url="videoUrl" :poster="videoImg" />
</div>
</div>
</template>
<script>
import EasyPlayer from '@easydarwin/easyplayer'
import 'videojs-contrib-hls'
export default {
components: {
// eslint-disable-next-line vue/no-unused-components
EasyPlayer
},
data() {
return {
videoUrl: require('@/assets/video/DPlayer.webm'),
videoImg: require('@/assets/avatar.jpg'),
playerOptions: {
playbackRates: [0.7, 1.0, 1.5, 2.0], // 播放速度
autoplay: false, // 如果true,浏览器准备好时开始回放。
muted: false, // 默认情况下将会消除任何音频。
loop: false, // 导致视频一结束就重新开始。
preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
language: 'zh-CN',
aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
sources: [
{
type: 'video/mp4', // 这里的种类支持很多种:基本视频格式、直播、流媒体等,具体可以参看git网址项目
// eslint-disable-next-line no-dupe-keys
type: 'video/webm',
// eslint-disable-next-line no-dupe-keys
type: 'application/x-mpegURL',
// src: require('@/assets/video/DPlayer.mp4')// url地址
src: 'https://cdn.letv-cdn.com/2018/12/05/JOCeEEUuoteFrjCg/playlist.m3u8'
}
],
poster: require('@/assets/avatar.jpg'), // 你的封面地址
// width: document.documentElement.clientWidth, //播放器宽度
// notSupportedMessage: '此视频暂无法播放,请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
controlBar: {
timeDivider: true,
durationDisplay: true,
remainingTimeDisplay: false,
fullscreenToggle: true // 全屏按钮
}
},
methods: {}
}
}
}
</script>
<style lang="scss" scoped >
.videoBox {
width: 100%;
height: 100%;
display: flex;
align-items: center; /*垂直居中*/
// justify-content: center; /*水平居中*/
}
.videoBoxCenter {
width: 800px;
margin-left: 1%;
}
.videoBoxCenter1 {
width: 800px;
margin-left: 3%;
}
.video-player {
width: 100%;
height: 100%;
}
</style>
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)
vue.config.js
const CopyWebpackPlugin = require('copy-webpack-plugin')
plugins: [
new CopyWebpackPlugin([{
from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer.swf',
to: './libs/EasyPlayer/'
},
{
from: 'node_modules/@easydarwin/easyplayer/dist/component/crossdomain.xml',
to: './libs/EasyPlayer/'
},
{
from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer-lib.min.js',
to: './libs/EasyPlayer/'
}
])
]
效果图