1.安装插件
npm install vue-video-player@5.0.2
npm install video.js
2.在组件或在main.js中引入(这里以组件为例)
import 'video.js/dist/video-js.css'
import {videoPlayer} from 'vue-video-player'
export default {
name: "videoDetail",
components: {
videoPlayer
},
3.Vue使用
<div class='demo'>
<video-player class="video-player-box"
ref="videoPlayer"
:playsinline="true"
:options="playerOptions">
</video-player>
</div>
4.JS部分
data() {
return {
// id: this.$route.query.id,
// video: {},
playerOptions: {
playbackRates: [0.5, 1.0, 1.5, 2.0], // 可选的播放速度
autoplay: true, // 如果为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", // 类型
src: '' // url地址
}],
poster: '', // 封面地址
notSupportedMessage: '此视频暂无法播放,请稍后再试', // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
controlBar: {
timeDivider: true, // 当前时间和持续时间的分隔符
durationDisplay: true, // 显示持续时间
remainingTimeDisplay: true, // 是否显示剩余时间功能
fullscreenToggle: true // 是否显示全屏按钮
}
}
}
},
created() {
let id = this.$route.query.id
this.request.get("/file/detail/" + id).then(res => {
console.log(res.data)
// this.video = res.data
this.playerOptions.sources[0].src = res.data.url,
})
},
Vue集成视频播放组件
最新推荐文章于 2024-03-28 09:32:57 发布