支持视频播放

插件:

https://github.com/surmon-china/vue-video-player

安装方法

下载

vue3.0直接搜索


vue2:
npm install vue-video-player --save

调用

这里使用global方法

import Vue from 'vue'
import VueVideoPlayer from 'vue-video-player'

// require videojs style
import 'video.js/dist/video-js.css'
// import 'vue-video-player/src/custom-theme.css'

Vue.use(VueVideoPlayer, /* {
  options: global default options,
  events: global videojs events
} */)

使用

模版


  

代码

export default {
    data() {
      return {
        playerOptions: {
          // videojs options
          muted: true,
          language: 'en',
          playbackRates: [0.7, 1.0, 1.5, 2.0],
          sources: [{
            type: "video/mp4",
            src: "https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm"
          }],
          poster: "/static/images/author.jpg",
        }
      }
    },
    mounted() {
      console.log('this is current player instance object', this.player)
    },
    computed: {
      player() {
        return this.$refs.videoPlayer.player
      }
    },
    methods: {
      // listen event
      onPlayerPlay(player) {
        // console.log('player play!', player)
      },
      onPlayerPause(player) {
        // console.log('player pause!', player)
      },
      // ...player event

      // or listen state event
      playerStateChanged(playerCurrentState) {
        // console.log('player current update state', playerCurrentState)
      },

      // player is ready
      playerReadied(player) {
        console.log('the player is readied', player)
        // you can use it to do something...
        // player.[methods]
      }
    }
  }

提示

videojs参数中包含,autoplay设置为'any'时会以任意可播放方式来播放,controls设置为false时不再显示控制条

api:

https://docs.videojs.com/tutorial-options.html

https://docs.videojs.com/

https://www.jianshu.com/p/16fa00a1ca8e

参考:

https://www.jianshu.com/p/e8e747e33ef0

你可能感兴趣的:(支持视频播放)