vue中使用video.js

标题

1.首先下载Video。js

2.引入:import Video from 'video.js'

3.页面中使用: 

<video

              style="display:none"

              :id="'myVideo'+index"

              class="video-js"

              :src="item.sourceUrl"

              controls

              preload="auto">

            </video>

4. 后台返回数据做处理: 

this.$nextTick(() => {

            let myCollection = document.getElementsByClassName('video-js')

            this.durationT = []

            Array.from(myCollection).map((item, index) => {

              var myPlayer = Video('myVideo' + index, {

                preload: 'auto',

                controlBar: {

                  'durationDisplay': true

                }

              }, () => {

                this.timer = setTimeout(() => {

                  this.durationT.push(myPlayer.controlBar.durationDisplay.formattedTime_)

                }, 200)

              })

            })

          })

Vue项目使用video.js需要先安装video.jsvue-video-player插件。 首先,在项目根目录下打开命令行工具,执行以下命令安装video.jsvue-video-player插件: ``` npm install video.js vue-video-player ``` 安装完成后,在需要使用video.js的组件引入video.jsvue-video-player插件,并在template添加video标签和播放器组件的调用代码。 在组件的script标签添加以下代码: ```javascript import 'video.js/dist/video-js.css'; // 引入video.js的CSS样式 import VideoPlayer from 'vue-video-player'; // 引入vue-video-player插件 import 'vue-video-player/src/custom-theme.css'; // 引入vue-video-player的样式 export default { components: { videoPlayer: VideoPlayer // 注册vue-video-player组件 }, data() { return { options: { // 设置video.js的配置项 autoplay: true, controls: true, sources: [{ src: 'your_video_url', type: 'video/mp4' }] } }; } }; ``` 然后,在template添加video标签和播放器组件的调用代码: ```html <template> <div> <video ref="video" class="video-js vjs-default-skin vjs-big-play-centered" :options="options"></video> <video-player :options="options"></video-player> </div> </template> ``` 其,options是video.js的配置项,可以根据自己的需求进行修改。your_video_url需要替换为实际的视频地址。 最后,可以通过调用video.js的API来控制视频的播放、暂停等操作。具体的API可以参考video.js的官方文档。 以上就是在Vue项目使用video.js的基本步骤。希望能对你有所帮助!如果还有其他问题,请继续提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值