使用vue-video-player完成h5项目的视频播放
1.引入video.js组件
npm install video.js
npm install vue-video-player
2.在页面中引入并注册组件
<script>
import { videoPlayer } from "vue-video-player";
import "video.js/dist/video-js.css";
export default {
name: "Home",
components: {
videoPlayer,
},
};
</script>
3.主体内容
<template>
<div class="home">
<!-- 视频 -->
<div class="vido">
<video-player
class="video-player-box"
:options="playerOptions"
:playsinline="true"
/>
</div>
</div>
</template>
4.在data中初始化数据
data() {
return {
// 视频播放器
playerOptions: {
// videojs options
muted: false,
autoplay: false,
loop: false,
preload: "auto",
language: "zh-CN",
fluid: true,
aspectRatio: "16:9",
playbackRates: [0.7, 1.0, 1.5, 2.0],
sources:
"https://vod.pipi.cn/fe5b84bcvodcq1251246104/7e3ad6f55285890797987579689/f0.mp4",
poster:
"https://obj.pipi.cn/friday/7d13ad1127f0297dce3362dc279e0fdf.jpg",
notSupportedMessage: "此视频暂无法播放,请稍后再试", //允许覆盖Video.js无法播放媒体源时显示的默认信息。
controlBar: {
timeDivider: true, //当前时间和持续时间的分隔符
durationDisplay: true, //显示持续时间
remainingTimeDisplay: true,
fullscreenToggle: true, // 全屏按钮
},
},
};
},
5.视频基本样式
<style lang="less" scoped>
.home {
width: 100vw;
height: 100vh;
.vido {
width: 340px;
height: 134px;
position: absolute;
right: 17px;
/deep/.vjs-big-play-button {
width: 50px;
height: 50px;
border-radius: 50%;
left: 150px;
top: 76px;
}
/deep/.video-player-box {
touch-action: none;
.video-js .vjs-time-control {
min-width: 0px;
padding-left: 1px;
padding-right: 1px;
display: block;
}
.video-js .vjs-remaining-time {
display: none;
}
}
}
}
</style>