网页视频播放器(easyplayer和vue-video-player的使用)

这篇博客介绍了如何在网页中使用easyplayer和vue-video-player两种不同的视频播放器组件。文章详细阐述了安装过程、配置选项,并通过代码展示了各自的特点,包括支持的视频格式、播放控制及自定义设置。同时,提供了实际的运行效果图进行对比展示。
摘要由CSDN通过智能技术生成

网页视频播放器(easyplayer和vue-video-player的使用)

描述

  1. 两种方式实现的网页播放器
  2. 支持的视频格式不太相同

安装插件

 npm install @easydarwin/easyplayer --save
 npm install copy-webpack-plugin@5.1.2 --save-dev
 cnpm install --save videojs-contrib-hls
 cnpm install vue-video-player --save   

video.vue

<template>
  <!-- vue-video-player -->
  <div class="videoBox">
    <div class="videoBoxCenter">
      <video-player
        ref="videoPlayer"
        :playsinline="true"
        :options="playerOptions"
        class="video-player vjs-custom-skin"
      />
    </div>
    <!-- 采用easyplayer.js -->
    <div class="videoBoxCenter1">
      <easy-player :video-url="videoUrl" :poster="videoImg" />
    </div>
  </div>
</template>

<script>
import EasyPlayer from '@easydarwin/easyplayer'
import 'videojs-contrib-hls'
export default {
  components: {
    // eslint-disable-next-line vue/no-unused-components
    EasyPlayer
  },
  data() {
    return {
      videoUrl: require('@/assets/video/DPlayer.webm'),
      videoImg: require('@/assets/avatar.jpg'),
      playerOptions: {
        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将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
        sources: [
          {
            type: 'video/mp4', // 这里的种类支持很多种:基本视频格式、直播、流媒体等,具体可以参看git网址项目
            // eslint-disable-next-line no-dupe-keys
            type: 'video/webm',
            // eslint-disable-next-line no-dupe-keys
            type: 'application/x-mpegURL',
            // src: require('@/assets/video/DPlayer.mp4')// url地址
            src: 'https://cdn.letv-cdn.com/2018/12/05/JOCeEEUuoteFrjCg/playlist.m3u8'
          }
        ],
        poster: require('@/assets/avatar.jpg'), // 你的封面地址
        // width: document.documentElement.clientWidth, //播放器宽度
        // notSupportedMessage: '此视频暂无法播放,请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true // 全屏按钮
        }
      },
      methods: {}
    }
  }
}
</script>

<style lang="scss" scoped >
.videoBox {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center; /*垂直居中*/
  // justify-content: center; /*水平居中*/
}
.videoBoxCenter {
  width: 800px;
  margin-left: 1%;
}
.videoBoxCenter1 {
  width: 800px;
  margin-left: 3%;
}
.video-player {
  width: 100%;
  height: 100%;
}
</style>

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)

vue.config.js

const CopyWebpackPlugin = require('copy-webpack-plugin')
 plugins: [
      new CopyWebpackPlugin([{
        from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer.swf',
        to: './libs/EasyPlayer/'
      },
      {
        from: 'node_modules/@easydarwin/easyplayer/dist/component/crossdomain.xml',
        to: './libs/EasyPlayer/'
      },
      {
        from: 'node_modules/@easydarwin/easyplayer/dist/component/EasyPlayer-lib.min.js',
        to: './libs/EasyPlayer/'
      }
      ])
    ]
   

在这里插入图片描述

index.html引入EasyPlayer-element.min.js

<script src="./EasyPlayer-element.min.js"></script>

效果图(右:video-player,左:easyPlayer)

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拼搏的小浣熊

你的鼓励是我创作的巨大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值