vue 实现多个视频播放 vue-video-player

vue 实现多个视频播放 vue-video-player

实现方式:利用vue的一个组件 vue-video-player

步骤一:安装vue-video-player插件 安装:npm install vue-video-player --save或者cnpm install vue-video-player --save 步骤二:在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)

步骤三:在自己需要的页面进行引用

<div class="list-vedio" v-for="(item, index) in reply" :key="index">
          <video-player
            class="video-player vjs-custom-skin"
            ref="videoPlayer"
            :playsinline="true"
            :options="playerOptions[index]"
          ></video-player>
          <div class="vediotitle">{
         
  { item.title }}</div>
          <div>{
         
  { item.represent }}</div>
        </div>

步骤四:从后台获取视频的地址,标题,封面等你需要的数据

if (res.code == 0) {
          this.reply = res.response;
          for (let i of this.reply) {
            let arrStr = {
              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将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
              notSupportedMessage: "此视频暂无法播放,请稍后再试", //允许覆盖Video.js无法播放媒体源时显示的默认信息。
              sources: [
                {
                  type: "", //这里的种类支持很多种:基本视频格式、直播、流媒体等
                  src: i.address, //url地址 "../../static/vedio/test1.mp4"
                },
              ],
              poster: i.fengmian, //你的封面地址 "../../static/vedio/test.jpg"
              controlBar: {
                timeDivider: true,
                durationDisplay: true,
                remainingTimeDisplay: false,
                fullscreenToggle: true, //全屏按钮
              },
            };
            this.playerOptions.push(arrStr);
          }
        }
经验分享 程序员 微信小程序 职场和发展