zoukankan      html  css  js  c++  java
  • vue.js 视频播放

    最近心学习vue.js开发,video开发播放!

    使用第三方的封装:https://www.npmjs.com/package/vue-video-player

    1. npm install vue-video --save 安装播放第三方插件;

    2.在main.js中

    import VueVideoPlayer from 'vue-video-player'
     
    Vue.use(VueVideoPlayer)
     

    3.使用vue里边

    import { videoPlayer } from 'vue-video-player'
     
    //声明组建
    components: {
    Header,
    videoPlayer
    }
     
    使用
    <template>
      <video-player  ref="videoPlayer"
                     :options="playerOptions"
     
                     title="you can listen some event if you need"
                     @play="onPlayerPlay($event)"
                     @pause="onPlayerPause($event)"
                     @ended="onPlayerEnded($event)"
                     @loadeddata="onPlayerLoadeddata($event)"
                     @waiting="onPlayerWaiting($event)"
                     @playing="onPlayerPlaying($event)"
                     @timeupdate="onPlayerTimeupdate($event)"
                     @canplay="onPlayerCanplay($event)"
                     @canplaythrough="onPlayerCanplaythrough($event)"
     
                     title="or listen state change"
                     @statechanged="playerStateChanged($event)"
     
                     title="The prepared event will be triggered after the videojs program instance completes, and its callback player object is the videojs callback function in this context"
                     @ready="playerReadied">
      </video-player>
    </template>
     
    <script>
      // Similarly, you can also introduce the plugin resource pack you want to use within the component
      // require('some-videojs-plugin')
      export default {
        data() {
          return {
            playerOptions: {
     
              // component options
              start: 0,
              playsinline: false,
     
              // 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]
          }
        }
      }
    </script>
     
     
    
    
  • 相关阅读:
    activity 背景透明
    win系统注册缺少的库 32位系统 64位系统
    android 窗
    wireshark抓包分析
    juqery select 标签
    IOS开发应用之Quartz 2D学习指南
    为什么你总会觉得自己的产品不够好
    日志宝
    Android之Inflate()方法用途+setContentView和inflate区别
    Ralasafe
  • 原文地址:https://www.cnblogs.com/PeterWolf/p/7244473.html
Copyright © 2011-2022 走看看