vue2 使用 vue-video-player 播放m3u8 流地址视频

安装插件  :

注意需要引入  videojs-contrib-hls ,否则无法播放hls流文件 

npm install vue-video-player@5.0.1 --save
npm install videojs-contrib-hls@5.15.0 --save

main.js 引入

require('vue-video-player/src/custom-theme.css')
require('video.js/dist/video-js.css')
import VideoPlayer from 'vue-video-player'
import hls from "videojs-contrib-hls"; 

Vue.use(VideoPlayer)
Vue.use(hls);

代码内引入:

注意点:   

1.type: 'application/x-mpegURL' ,否则无法播放流文件 

2.aspectRatio: '16:9',  宽高比需要进行设置, 若没有进行设置,会出现黑边过高或者过宽的问题

<video-player ref="videoPlayer" :options="playerOptions" class="video-player vjs-custom-skin"/>


playerOptions: {
        autoplay: true,
        hls:true,
        aspectRatio: '16:9',
        fluid: false, 
        sources: [
          {
            src: '',
            // type: 'video/mu38'
            type: 'application/x-mpegURL'
          }
        ],
      },

常用API方法:

// 加载视频
this.$refs.videoPlayer.player.load();
// 播放视频
this.$refs.videoPlayer.player.play();
// 暂停播放
this.$refs.videoPlayer.player.pause();
// 直接全屏 如果当前设备支持的话
this.$refs.videoPlayer.player.requestFullscreen();

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值