引入视频,vue-video-player的使用方法

文章讲述了在Vue项目中如何安装和使用vue-video-player组件,特别提醒避免同时安装video.js以防止冲突。详细步骤包括在main.js中引入组件和所需样式,设置播放器的选项如播放速度、自动播放等,并提供了相应的模板代码示例。
摘要由CSDN通过智能技术生成

直接安装npm install vue-video-player --save报错

指定版本:npm install vue-video-player@5.0.1 --save

vue-video-player 其实就是 video.js 集成到 vue 中,所以别再装 video.js,可能会出错
 

1.在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)

完整代码:

<template>
    <div>
        <video-player style="width: 80%;height: 100%;margin:0 auto;box-shadow:5px 5px 8px #888888"  class="video-player vjs-custom-skin"
                      ref="videoPlayer"
                      :playsinline="true"
                      :options="playerOptions"
        ></video-player>
    </div>
</template>
 
<script>
    export default {
        name: "demo7",
        data(){
            return {
                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",
                        src: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" //url地址
                    }],
                    poster: "", //你的封面地址
                    // width: document.documentElement.clientWidth,
                    notSupportedMessage: '此视频暂无法播放,请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
                    controlBar: {
                        timeDivider: true,
                        durationDisplay: true,
                        remainingTimeDisplay: false,
                        fullscreenToggle: true  //全屏按钮
                    }
                },
            }
        }
    }
</script>
 
<style scoped>
 
</style>

 

您可以使用以下代码引入vue-video-player插件并设置视频地址: 在main.js里面全局引用: ```javascript // 安装 vue-video-player npm install vue-video-player --save // 引入插件 import VueVideoPlayer from 'vue-video-player' import 'video.js/dist/video-js.css' // 引入视频样式文件 import 'vue-video-player/src/custom-theme.css' // 引入插件样式文件 // 在Vue实例中使用插件 Vue.use(VueVideoPlayer) // 在需要使用插件的组件内,设置视频地址 <template> <div> <video-player :options="videoOptions"></video-player> </div> </template> <script> export default { data() { return { videoOptions: { sources: [ { src: 'your-video-url.mp4', type: 'video/mp4' } ] } } } } </script> ``` 在组件内引用: ```javascript // 安装 vue-video-player npm install vue-video-player --save // 在需要的组件内引入插件 import { videoPlayer } from 'vue-video-player' import 'video.js/dist/video-js.css' // 引入视频样式文件 import 'vue-video-player/src/custom-theme.css' // 引入插件样式文件 // 在Vue实例中使用插件 export default { components: { videoPlayer }, data() { return { videoOptions: { sources: [ { src: 'your-video-url.mp4', type: 'video/mp4' } ] } } } } ``` 请将"your-video-url"替换为您的实际视频地址。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [vue视频播放插件vue-video-player的具体使用方法](https://download.csdn.net/download/weixin_38517095/13674028)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [vue-video-player:vue2.0+vue-video-player实现hls播放全过程](https://download.csdn.net/download/weixin_42123237/18213340)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [go语言恶意代码检测系统-对接前端可视化与算法检测部分](https://download.csdn.net/download/liufang_imei/88222624)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值