網頁移動端 vue-video-player 視頻播放器使用記錄


 

完整的代碼, 可以復制引用

 

引入視頻播放器插件

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

組件模板

<template>
  <section class="my-video">
    <TopBar title="video" />
    <section ref="goods_swipe" class="goods-swipe" v-for="(item,index) in videoList" :key="index">
      <section class="video-title">
        怎么賺錢
      </section>
      <video-player class="goods-video" ref="videoPlayer" :options="videoList[index]"></video-player>
    </section>
  </section>
</template>

<script>
import TopBar from '@/components/TopBar';
export default {
name: "video",
components: {
TopBar
},
data() {
return {
current: 0, // 當前是視頻還是圖片,0代表視頻
videoList: [ // 視頻列表
{
fluid: true,
aspectRatio: '16:9',
poster: '',
sources: [{
type: "video/mp4",
src: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
}]
},
{
fluid: true,
aspectRatio: '16:9',
poster: '',
sources: [{
type: "video/mp4",
src: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
}]
},
]
}
},
computed: {
player() {
return this.$refs.videoPlayer.player; // 獲取視頻播放器對象
},
},
mounted() {

},
methods: {
onChange(index) {
this.current = index; // 修改當前類型
this.player.pause(); // 暫停播放
},
},
}
    </script>

<style scoped lang="less">
.my-video {
  .video-title{
    text-align: center;
    padding:10px 0 8px;
    font-family: Alhyznht;
    color: #ccc;
  }
  .goods-swipe {
    position: relative;
    width: 100%;
    background: #000;
    margin-top: 15px;
    .van-swipe{
      overflow: auto;
    }
    .goods-video {
      height: 100%;
  .video-js {
    width: 100%;
    height: 100%;
  }
  .vjs-tech{
    height: auto;
  }

  .vjs-control-bar {
    bottom: 40px;
  }

  /deep/ .vjs-big-play-button {
    border-radius: 50%;
    width: 40px;
    height: 40px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    line-height: normal;

    .vjs-icon-placeholder {
      &:before {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: auto;
        height: auto;
      }
    }
  }

  .vjs-control-bar {
    .vjs-play-control,
    .vjs-fullscreen-control {
      .vjs-icon-placeholder {
        &:before {
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          width: auto;
          height: auto;
          font-size: 25px;
        }
      }
    }

    .vjs-volume-panel,
    .vjs-picture-in-picture-control {
      display: none;
    }
  }
}
}
}
    </style>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM