vue2中视频的播放

文章介绍了如何在Vue2项目中安装和使用vue-video-player组件,包括指定版本安装、在main.js中引入以及在组件中创建和配置播放器的详细步骤。
摘要由CSDN通过智能技术生成

1、安装依赖(vue2中要限制版本号)

npm install vue-video-player@4.0.6

2、在main.js主文件中引入


     import VideoPlayer from 'vue-video-player'
     import 'vue-video-player/src/custom-theme.css'
     import 'video.js/dist/video-js.css'
     Vue.use(VideoPlayer)

3、创建Home.vue组件

<template>

  <div @click="big" class="bb" :class="{aa:flag}">

      <video-player   class="video-player vjs-custom-skin"

                    ref="videoPlayer"

                    :playsinline="true"

                    :options="playerOptions"

      ></video-player>

      <p>hhhhhhhhhhhhhhhhhhhhhhhhh</p>

  </div>

</template>

<script>

  export default {

      name: "demo7",

      data(){

          return {

            flag:false,

              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  //全屏按钮

                  }

              },

          }

      },

      methods: {

        big() {

           this.flag=true

        }

      },

      created () {

       

      },


 

  }

</script>

<style scoped lang="less">

.bb{

    margin: 0 auto;

    width: 500px;

    height: 300px;

}

.aa{

    margin: 0 auto;

    // style="width: 500px;height: 150px;margin:0 auto;box-shadow:5px 5px 8px #888888"

    width: 700px;

    height: 400px;

    border: 3px solid red;

}

/deep/.video-js .vjs-big-play-button{

    border-width: 3px;

    border-color: rgb(255, 255, 255);

    border-style: solid;

    border-radius: 50%;

    width: 70px;

    height: 60px;

    line-height: 50px;

    background-color: rgba(0,0,0,0);

    position: absolute;

    top: 0;

    bottom: 0;

    left: 0;

    right: 0;

    margin: auto;

  }


 

</style>

  

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值