使用vue-video-player播放视频

本文介绍如何使用Vue.js集成视频播放器组件,并配置HLS流媒体支持。通过npm安装必要包,如vue-video-player和videojs-contrib-hls,然后在项目中引入并设置播放器选项。

1、npm安装

vue-video-player
videojs-contrib-hls

2、在main.js中引入

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import VideoPlayer from 'vue-video-player'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'
import '@/assets/css/tailwind.css'
import '@/assets/iconfont.css'
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(VideoPlayer)
Vue.use(Element)
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

3、使用的页面

<template>
  <div>
    <div class='demo col-md-3'>
      <video-player class="video-player vjs-custom-skin"
                    ref="videoPlayer"
                    :playsinline="true"
                    :options="playerOptions0">
      </video-player>
    </div>
  </div>
</template>

<script>
import 'videojs-contrib-hls'
export default {
  name: 'VideoMp4',
  data () {
    return {
      playerOptions0: {
        // 播放速度
        playbackRates: [0.5, 1.0, 1.5, 2.0],
        // 如果true,浏览器准备好时开始回放。
        autoplay: false,
        // 默认情况下将会消除任何音频。
        muted: false,
        // 导致视频一结束就重新开始。
        loop: false,
        // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
        preload: 'auto',
        language: 'zh-CN',
        // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
        aspectRatio: '16:9',
        // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
        fluid: true,
        sources: [
          {
            // 类型
            type: 'video/mp4',
            // url地址
            src: ''
          }, {
            // 类型
            type: 'video/mp4',
            // url地址 http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
            src: ''
          }, {
            type: 'application/x-mpegURL', // 这里的种类支持很多种:基本视频格式、直播、流媒体等,具体可以参看git网址项目
            src: 'http://hls01open.ys7.com/openlive/6d499d610a0c4a6182e36ac7dca124ad.m3u8' // url地址
          }
        ],
        // 你的封面地址
        poster: '',
        // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        notSupportedMessage: '此视频暂无法播放,请稍后再试',
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          // 全屏按钮
          fullscreenToggle: true
        }
      }
    }
  }
}
</script>

<style scoped>
.demo{
  display: inline-block;
  width: 600px;
  height: auto;
  text-align: center;
  line-height: 100px;
  border: 1px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
  position: relative;
  /* box-shadow: 0 1px 1px rgba(0, 0, 0, .2); */

}

.demo:hover{
  display: block;
}
.vjs-custom-skin > .video-js .vjs-big-play-button {
  transform: scale(0.6) !important;
}
</style>

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值