当前位置: 首页 > news >正文

Vue2使用easyplayer

说一下easyplayer在vue2中的使用,vue3中没测试,估计应该差不多,大家可自行验证。

安装:

pnpm i @easydarwin/easyplayer

组件封装

习惯性将其封装为单独的组件

<template><div class="EasyPlayer"><easy-playerstyle="width: 100%;height: 100%;"@error="restartPlayer"@ended="restartPlayer"@play="videoPlay"ref="EasyPlayerRef":videoUrl="url":aspect="aspect":showEnterprise="false":show-custom-button="false":alt="alt":autoplay="autoplay":loop="loop":muted="muted"fluentstretch></easy-player></div>
</template>
<script>import EasyPlayer from '@easydarwin/easyplayer'export default {data() {return {timer: null}},components: { EasyPlayer },props: {url: {type: String,default: ''},aspect: {type: String,default: '16:9'},alt: {type: String,default: '无信号'},autoplay: {type: Boolean,default: true},loop: {type: Boolean,default: true},muted: {type: Boolean,default: true}},destroyed() {if(this.timer) {clearInterval(this.timer)this.timer = null}},methods: {restartPlayer(e) {console.log(e,'播放异常或播放结束或直播断流------->>>>>>>>>')this.$refs.EasyPlayerRef.initPlayer()  //初始化播放器this.$emit('pullFlow')this.timer = setInterval(() => {this.$refs.EasyPlayerRef.initPlayer()  //初始化播放器this.$emit('pullFlow')}, 3000)},// 播放事件videoPlay(a) {// console.log(a,'视频播放------>>')if(this.timer) {clearInterval(this.timer)this.timer = null}},},}
</script>
<style scoped>
.EasyPlayer {width: 100%;height: 100%;
}/* 阻止单击双击视频全屏或者跳转官网 *//* /deep/ .vjs-tech {pointer-events: none!important;} *//* /deep/ .video-js.vjs-fullscreen::backdrop,:not(:root):fullscreen::backdrop {position: fixed!important;top: 0!important;left: 0!important;width: 50%!important;height: 50%!important;right: 50%!important;bottom: 50%!important;background-color: transparent!important;}/deep/ .video-js.vjs-fullscreen .vjs-tech {position: absolute;top: 50%;left: 50%;width: 50%!important;height: 50%!important;transform: translateX(-50%)!important;}/deep/ .video-js {background-color: transparent!important;} */
</style>

 引入使用

<template><div class="container"><div class="easy-player"><EasyPlayer:url="playerUrl"@pullFlow="pullFlow"/></div></div>
</template>
<script>
import EasyPlayer from './EasyPlayer/index.vue'
export default {data() {return {playerUrl: 'http://playertest.longtailvideo.com/adaptive/bipbop/gear4/prog_index.m3u8'}},components: { EasyPlayer },methods:{// 播放异常 重新拉流pullFlow() {// .....}},
}
</script>
<style scoped>
.container {width: 100%;height: 100%;padding: 100px 0 0 100px;box-sizing: border-box;
}.easy-player {width: 450px;height: 300px;border: 1px solid red;
}
</style>

报错处理

会发现控制台有下面报错 

看到报错不要慌,大家跟着我处理

首先我们安装个插件(注意:不要大于6.0版本的,不然会有bug ,还会有乱七八槽的报错): 

pnpm add copy-webpack-plugin@5.1.2 --save-dev

然后在vue.config.js中: 

const { defineConfig } = require("@vue/cli-service");
const CopyWebpackPlugin = require('copy-webpack-plugin')
module.exports = defineConfig({// easy-player  相关configureWebpack: {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/'}])]},transpileDependencies: true,lintOnSave: false,productionSourceMap: false
});

配置上之后还没完,还需要在public/index.html 引入EasyPlayer-element.min.js,可以直接在node_modules里找到@easydarwin/easyplayer下的dist/element/EasyPlayer-element.min.js复制到pubilc目录下,还有需要EasyPlayer.wasm同样放到public目录下如下所示:

 

然后在public/index.html下再引入即可 

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

这样就OK了!

http://www.lryc.cn/news/119818.html

相关文章:

  • Map映射学习
  • 【每日一题Day292】LC1572矩阵对角线元素的和 模拟
  • Mongodb:业务应用(2)
  • DSO学习笔记
  • 【Windows 常用工具系列 5 -- 如何在网页(CSDN)中实现右上角及右下角数字显示】
  • sql注入--报错注入
  • Nginx常用功能
  • 【Express.js】express-validator
  • 沁恒ch32V208处理器开发(三)GPIO控制
  • Jenkins 中 shell 脚本执行失败却不自行退出
  • 2021年12月 C/C++(一级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • 计算机网络 网络层 IPv4数据报
  • 有哪些可以用于性能测试方法?【举例说明】
  • Linux进程管理命令
  • pytest 常用命令参数
  • 从安装 Seata 开始的分布式事务之旅 springboot集成seata
  • Laravel 使用mix引入本地样式文件 报错 Unable to locate Mix处理
  • QT学习笔记-QT安装oracle oci驱动
  • 【React学习】—类的基本知识(五)
  • 【AI】《动手学-深度学习-PyTorch版》笔记(十六):自定义网络层、保存/加载参数、使用GPU
  • 微软杀入Web3:打造基于区块链的AI产品
  • 聊聊51单片机
  • Linux yum 命令,Linux apt 命令
  • Vue+SpringBoot项目开发:登录页面美化,登录功能实现(三)
  • 2.若依前后端分离版第一个增删查改
  • javaSE_2.2——【方法的介绍】
  • 【02】基础知识:typescript数据类型
  • DIP: NAS(Neural Architecture Search)论文阅读与总结(双份快乐)
  • AI:02-基于深度学习的动物图像检索算法的研究
  • IDEA项目实践——Spring集成mybatis、spring当中的事务