vue使用vue-video-player

1、安裝vue-video-player:

npm install vue-video-player --save

2、引入

//在main.js入口文件中引入
import VideoPlayer from 'vue-video-player'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.use(VideoPlayer)


//在.vue中單獨引入
import { videoPlayer } from 'vue-video-player'
import 'video.js/dist/video-js.css'
// import 'video.js/dist/lang/zh-CN'
import 'vue-video-player/src/custom-theme.css'

videoPlayerComp.vue:

<!--vue-video-player-->
<template>
    <div>
      <video-player  class="video-player vjs-custom-skin"
                     ref="videoPlayer"
                     :playsinline="true"
                     :options="playerOptions"
      ></video-player>
    </div>
</template>

<script>
  import { videoPlayer } from 'vue-video-player'
  import 'video.js/dist/video-js.css'
  // import 'video.js/dist/lang/zh-CN'
  import 'vue-video-player/src/custom-theme.css'
  export default {
    name: "videoPlayerComp",
    components: {
      videoPlayer
    },
    props: ['videoUrls','autoPlay','poster'],
    watch: {
      videoUrls: {
        handler(newVideoUrls, VideoUrls) {
          this.playerOptions.sources=newVideoUrls;
        },
        immediate: true
      },
      autoPlay: {
        handler(newVal, oldVal) {
          this.playerOptions.autoplay=newVal;
        },
        immediate: true
      },
      poster: {
        handler(newVal, oldVal) {
          this.playerOptions.poster=newVal;
        },
        immediate: true
      }
    },
    data(){
      return{
        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: [],
          poster: "", //你的封面地址
          notSupportedMessage: '此視頻暫無法播放,請稍後再試', //允許覆蓋Video.js無法播放媒體源時顯示的默認信息。
          controlBar: {
            timeDivider: true,
            durationDisplay: true,
            remainingTimeDisplay: false,
            fullscreenToggle: true  //全屏按鈕
          }
        }
      }
    }

  }
</script>

<style>
  .video-js .vjs-big-play-button{
    /*
    播放按鈕換成圓形
    */
    height: 2em;
    width: 2em;
    line-height: 2em;
    border-radius: 1em;
  }
</style>

 

調用組件:

<video-comp v-if="false" :autoPlay="autoPlay" :poster="poster" :videoUrls="sources" ></video-comp>







//參數
autoPlay: true,//視頻打開是否自動播放
poster: '',//視頻封面圖片
videoUrls: [
  ['http://localhost:9999/sky-rxy-web/common/player', 'video/mp4', '進度條播放', 1],
  ['http://localhost:9999/sky-rxy-web/common/getVideo', 'video/mp4', '普通播放', 0]
] ,//視頻地址
sources:[{
  src: 'http://localhost:9999/sky-rxy-web/common/getVideo',  // 路徑
  type: 'video/mp4'  // 類型
  }, {
    src: './test.webm',
    type: 'video/webm'
 }]

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章