vue3 引入import videojs from “video.js“

一、安装

 $ npm install video.js

二、main.js全局引入

// 引入video.js

import Videojs from 'video.js'(可单页面引入)
 
import 'video.js/dist/video-js.css'(可单页面引入)

Vue.prototype.$video = Videojs(main。js引入)
三、页面中的使用

<div class="video1" >
  <video
                ref="Playe1"
                id="my-video1"
                class="video-js vjs-big-play-centered  vjs-default-skin videotu"
                playsinline="true"
                x-webkit-airplay="allow" >
              </video>
  </div>

四. setup方法

onMounted(() => {
      nextTick(()=>{
        initVideo()
      })
}
  const initVideo = ()=> {
      // if (!props.pull) return
      videojs('my-video1', {
        // bigPlayButton: true, //是否显示播放按钮
        // autoplay:false, // 是否自动播放
        // controls:true,
        // sourceOrder: true,
        // controlBar: false,
        // poster: props.coverImage,
        // fluid: false, // 自适应宽高
        muted: false,
        poster:video1,
        preload: 'auto' ,// 预加载
        controls: true,//视频控件
        autoplay: false,//自动播放
        techOrder:['html5', ], // 兼容顺序 'flash',
        sources: 
          // {
          //   src: ming,//播放视频地址
          //   type: 'application/x-mpegURL',//播放m3u8需要设置的格式
          // }
          {
            src: 'https://qingluan-1301935573.file.myqcloud.com/video/demo_1.mp4',//播放视频地址
            type: 'video/mp4',//播放m3u8需要设置的格式
          }
          
        ,
        controlBar: {
          remainingTimeDisplay: {
            displayNegative: false
          }
        },
        playbackRates: [0.5, 1, 1.5, 2]//设置播放速度
      })
 }

五,css方法

.video1{
    position: relative;
    width: 6.14rem;
    height: 9.44rem;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.1rem;
    .videotu{
      width: 5.5rem;
      height: 7.3rem;
    }
  }
  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值