网页移动端 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>

posted on   完美前端  阅读(1529)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-03-03 flutter-mac配置电脑环境

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示