vue2之jessibuca视频插件使用教程

vue2之jessibuca视频插件使用教程

  • jessibuca简介
  • 前期准备
    • 下载相关js
    • vue index.html文件引入
  • 组件封装
  • 使用
    • 小知识 引入iconfont

jessibuca简介

Jessibuca是一款开源的纯H5直播流播放器,通过Emscripten将音视频解码库编译成Js(ams.js/wasm)运行于浏览器之中。兼容几乎所有浏览器,可以运行在PC、手机、微信中,无需额外安装插件。

前期准备

下载相关js

从官网下载相关压缩包将文件移入自身项目中,并根据自身vue版本放入Public或者Static文件夹下。
jessibuca官网-源码下载链接
在这里插入图片描述

解压后的文件

在这里插入图片描述

vue index.html文件引入

<script type="text/javascript" src="/jessibuca/jessibuca.js"></script>

组件封装

<template><divref="container"@dblclick="fullscreenSwich"style="width: 100%; height: 100%; background-color: #000000; margin: 0 auto; position: relative"><divclass="buttons-box"id="buttonsBox"><div class="buttons-box-left"><iv-if="!playing"class="iconfont icon-play jessibuca-btn"@click="playBtnClick"></i><iv-if="playing"class="iconfont icon-pause jessibuca-btn"@click="pause"></i><iclass="iconfont icon-stop jessibuca-btn"@click="destroy"></i><iv-if="isNotMute"class="iconfont icon-audio-high jessibuca-btn"@click="mute()"></i><iv-if="!isNotMute"class="iconfont icon-audio-mute jessibuca-btn"@click="cancelMute()"></i></div><div class="buttons-box-right"><span class="jessibuca-btn">{{ kBps }} kb/s</span><iclass="iconfont icon-camera1196054easyiconnet jessibuca-btn"@click="screenshot"style="font-size: 1rem !important"></i><iclass="iconfont icon-shuaxin11 jessibuca-btn"@click="playBtnClick"></i><iv-if="!fullscreen"class="iconfont icon-weibiaoti10 jessibuca-btn"@click="fullscreenSwich"></i><iv-if="fullscreen"class="iconfont icon-weibiaoti11 jessibuca-btn"@click="fullscreenSwich"></i><istyle="font-size: 28px"class="iconfont icon-video-close jessibuca-btn"@click="closeVideo()"></i></div></div></div>
</template><script>
let jessibucaPlayer = {};
export default {name: "wkVideoPlayer",data() {return {playing: false,isNotMute: false,quieting: false,fullscreen: false,loaded: false, // mutespeed: 0,performance: "", // 工作情况kBps: 0,btnDom: null,};},props: ["videoUrl", "error", "hasAudio", "height"],mounted() {this.$nextTick(() => {this.updatePlayerDomSize();this.btnDom = document.getElementById("buttonsBox");window.onresize = () => {this.updatePlayerDomSize();};if (this.videoUrl) {this.play(this.videoUrl);} else {return;}});},watch: {videoUrl(newData) {this.play(newData);},immediate: true,},methods: {updatePlayerDomSize() {let dom = this.$refs.container;let width = dom.parentNode.clientWidth;let height = dom.parentNode.clientHeight;const clientHeight = Math.min(document.body.clientHeight,document.documentElement.clientHeight);if (height > clientHeight) {height = clientHeight;width = (16 / 9) * height;}dom.style.width = width + "px";dom.style.height = height + "px";},create() {let options = {};jessibucaPlayer[this._uid] = new window.Jessibuca(Object.assign({container: this.$refs.container,autoWasm: true, // 在使用MSE或者Webcodecs 播放H265的时候,是否自动降级到wasm模式。background: "", //背景图片controlAutoHide: false, //底部控制台是否自动隐藏debug: false, //是否开启控制台调试打印decoder: "/jessibuca/decoder.js",hasAudio: typeof this.hasAudio == "undefined" ? true : this.hasAudio, // 是否有音频,如果设置false,则不对音频数据解码,提升性能。hasVideo: true, //  是否开启控制台调试打印heartTimeout: 5, //设置超时时长, 单位秒播放中途,如果超过设定时长无数据返回,则回调timeout事件heartTimeoutReplay: true, //是否开启心跳超时之后自动再播放heartTimeoutReplayTimes: 3, //重试次数  heartTimeoutReplay 重试失败之后,不再重新播放视频地址。如果想无限次重试,可以设置为-1hiddenAutoPause: false, //是否开启当页面的'visibilityState'变为'hidden'的时候,自动暂停播放。hotKey: false, //是否开启键盘快捷键 esc -> 退出全屏;arrowUp -> 声音增加;arrowDown -> 声音减少;isFlv: false, //当为true的时候:ws协议不检验是否以.flv为依据,进行协议解析。isFullResize: false, //当为true的时候:视频画面做等比缩放后,完全填充canvas区域,画面不被拉伸,没有黑边,但画面显示不全isNotMute: this.isNotMute, // 是否开启声音,默认是关闭声音播放的。isResize: false, //当为true的时候:视频画面做等比缩放后,高或宽对齐canvas区域,画面不被拉伸,但有黑边。 当为false的时候:视频画面完全填充canvas区域,画面会被拉伸。keepScreenOn: false, //开启屏幕常亮,在手机浏览器上, canvas标签渲染视频并不会像video标签那样保持屏幕常亮。PC端不会生效,仅手机端生效loadingText: "请稍等, 视频加载中......", // 视频加载转圈时的提示文字loadingTimeout: 10, //当play()的时候,如果没有数据返回,则回调loadingTimeoutReplay: true, ///是否开启loading超时之后自动再播放loadingTimeoutReplayTimes: 3, //loadingTimeoutReplay 重试失败之后,不再重新播放视频地址。operateBtns: {// 配置操作按钮 其中fullscreen: false, //全屏按钮screenshot: false, //截图按钮play: false, //播放暂停按钮audio: false, //声音按钮record: false, //录制按钮},recordType: "webm", //默认录制的视频格式rotate: 0, //设置旋转角度showBandwidth: false, // 显示网速supportDblclickFullscreen: false, // 是否支持屏幕的双击事件,触发全屏,取消全屏事件。timeout: 10, //设置超时时长, 单位秒在连接成功之前(loading)和播放中途(heart),如果超过设定时长无数据返回,则回调timeout事件useMSE: location.hostname !== "localhost" && location.protocol !== "https:", //是否开启MediaSource硬解码useWCS: location.hostname === "localhost" || location.protocol === "https", //是否开启Webcodecs硬解码useWebFullScreen: false, //是否使用web全屏(旋转90度)(只会在移动端生效)。videoBuffer: 0, // 设置最大缓冲时长,单位秒,播放器会自动消除延迟。wasmDecodeErrorReplay: true, // 是否开启解码失败重新播放wcsUseVideoRender: true, //webcodecs硬解码是否通过video标签渲染},options));let jessibuca = jessibucaPlayer[this._uid];let _this = this;// 监听 jessibuca 初始化事件。jessibuca.on("load", function () {// console.log("on load init");});// 信息,包含错误信息jessibuca.on("log", function (msg) {// console.log("on log", msg);});// 触发暂停事件jessibuca.on("pause", function () {_this.playing = false;});// 触发播放事件jessibuca.on("play", function () {_this.playing = true;});// 当前是否全屏jessibuca.on("fullscreen", function (msg) {// console.log("on fullscreen", msg);_this.fullscreen = msg;});// 触发声音事件,返回boolean值jessibuca.on("mute", function (msg) {// console.log("on mute", msg);_this.isNotMute = !msg;});// 当解析出音频信息时回调,2个回调参数// numOfChannels:声频通道// sampleRate 采样率// encTypeCode 音频编码类型(10:aac,7:ALAW(g711a),8:MULAW(g711u))// encType 音频编码类型(字符串)jessibuca.on("audioInfo", function (msg) {// console.log("audioInfo", msg);});let _ts = 0;// 当前视频帧pts,单位毫秒msjessibuca.on("timeUpdate", function (ts) {_ts = ts;});// 当解析出视频信息时回调,2个回调参数//width:视频宽//height:视频高//encTypeCode 视频编码类型(10:h264,12:h265)//encType 视频编码类型(字符串)jessibuca.on("videoInfo", function (info) {// console.log("videoInfo", info);});// 错误信息// 目前已有的错误信息:// jessibuca.ERROR.playError ;播放错误,url 为空的时候,调用play方法// jessibuca.ERROR.fetchError ;http 请求失败// jessibuca.ERROR.websocketError; websocket 请求失败// jessibuca.ERROR.webcodecsH265NotSupport; webcodecs 解码 h265 失败// jessibuca.ERROR.mediaSourceH265NotSupport; mediaSource 解码 h265 失败// jessibuca.ERROR.wasmDecodeError ; wasm 解码失败jessibuca.on("error", function (error) {// console.log("error", error);});// 当设定的超时时间内无数据返回,则回调jessibuca.on("timeout", function () {// console.log("timeout");});// 渲染开始jessibuca.on("start", function () {// console.log("start");});// 渲染性能统计,流开始播放后回调,每秒1次。// 0: 表示卡顿// 1: 表示流畅// 2: 表示非常流程jessibuca.on("performance", function (performance) {let show = "卡顿";if (performance === 2) {show = "非常流畅";} else if (performance === 1) {show = "流畅";}_this.performance = show;});// 流状态统计,流开始播放后回调,每秒1次。// buf: 当前缓冲区时长,单位毫秒,// fps: 当前视频帧率,// abps: 当前音频码率,单位byte,// vbps: 当前视频码率,单位byte,// ts:当前视频帧pts,单位毫秒jessibuca.on("stats", function (stats) {});// 当前网速, 单位KB 每秒1次,jessibuca.on("kBps", function (kBps) {_this.kBps = Math.round(kBps);});},playBtnClick: function (event) {this.play(this.videoUrl);},play: function (url) {console.log(url);if (jessibucaPlayer[this._uid]) {this.destroy();}this.create();jessibucaPlayer[this._uid].on("play", () => {this.playing = true;this.loaded = true;this.quieting = jessibuca.quieting;});if (jessibucaPlayer[this._uid].hasLoaded()) {jessibucaPlayer[this._uid].play(url);} else {jessibucaPlayer[this._uid].on("load", () => {console.log("load 播放");jessibucaPlayer[this._uid].play(url);});}},pause: function () {if (jessibucaPlayer[this._uid]) {jessibucaPlayer[this._uid].pause();}this.playing = false;this.err = "";this.performance = "";},screenshot: function () {if (jessibucaPlayer[this._uid]) {jessibucaPlayer[this._uid].screenshot();}},mute: function () {if (jessibucaPlayer[this._uid]) {jessibucaPlayer[this._uid].mute();}},cancelMute: function () {if (jessibucaPlayer[this._uid]) {jessibucaPlayer[this._uid].cancelMute();}},destroy: function () {if (jessibucaPlayer[this._uid]) {jessibucaPlayer[this._uid].destroy();}if (document.getElementById("buttonsBox") == null) {this.$refs.container.appendChild(this.btnDom);}jessibucaPlayer[this._uid] = null;this.playing = false;this.err = "";this.performance = "";},eventcallbacK: function (type, message) {},fullscreenSwich: function () {let isFull = this.isFullscreen();jessibucaPlayer[this._uid].setFullscreen(!isFull);this.fullscreen = !isFull;},isFullscreen: function () {return (document.fullscreenElement ||document.msFullscreenElement ||document.mozFullScreenElement ||document.webkitFullscreenElement ||false);},closeVideo: function () {this.destroy();this.$emit("videoClose");},},
};
</script><style>
.buttons-box {width: 100%;height: 28px;background-color: rgba(43, 51, 63, 0.7);position: absolute;display: -webkit-box;display: -ms-flexbox;display: flex;left: 0;bottom: 0;user-select: none;z-index: 10;
}.jessibuca-btn {width: 20px;color: rgb(255, 255, 255);line-height: 27px;margin: 0px 10px;padding: 0px 2px;cursor: pointer;text-align: center;font-size: 0.8rem !important;
}.buttons-box-right {position: absolute;right: 0;
}
@font-face {font-family: "iconfont"; /* Project id 1291092 */src: url("~@/assets/iconfont/iconfont.woff2?t=1673251105600") format("woff2");
}.iconfont {font-family: "iconfont" !important;font-size: 16px;font-style: normal;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;
}.icon-play:before {content: "\e603";
}.icon-pause:before {content: "\e6c6";
}.icon-stop:before {content: "\e6a8";
}.icon-audio-high:before {content: "\e793";
}.icon-audio-mute:before {content: "\e792";
}.icon-shuaxin11:before {content: "\e720";
}.icon-weibiaoti10:before {content: "\e78f";
}.icon-weibiaoti11:before {content: "\e790";
}.icon-camera1196054easyiconnet:before {content: "\e791";
}
</style>

使用

     <wk-video-playerclass="video"ref="player":videoUrl="videoUrl"@videoClose="onVideoClose"/>
---          
videoUrl:'直播流url地址'
onVideoClose() {this.$set(this.videoUrl, "");
},

小知识 引入iconfont

将iconfont 下载好的图标 放入assets即可,该字体已上传
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/48910.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

PHP基础语法(五)

一、定义语法 1、索引数组 2、php5.4之后简化的语法 3、关联数组 4、多维数组 $colors array("Red", "Green", "Blue");$colors ["Red", "Green", "Blue"];$person array("name" > "Jo…

基于PyCharm在Windows系统上远程连接Linux服务器中Docker容器进行Python项目开发与部署

文章目录 摘要项目结构项目开发项目上线参考文章 摘要 本文介绍了如何在Windows 10系统上使用PyCharm专业版2024.1&#xff0c;通过Docker容器在阿里云CentOS 7.9服务器上进行Python项目的开发和生产部署。文章详细阐述了项目结构的搭建、PyCharm的使用技巧、以及如何将开发项…

Superset二次开发之Dashboard状态变更源码解读

接口PUTapi/v1/dashboard/<dashboard_ID>前端文件 superset-frontend\src\dashboard\components\PublishedStatus\index.jsx 69行 togglePublished() togglePublished() { this.props.savePublished(this.props.dashboardId, !this.props.isPublished); } …

基于深度学习的医学影像分类

基于深度学习的医学影像分类是利用深度学习模型对医学影像&#xff08;如X光片、CT、MRI等&#xff09;进行自动分类&#xff0c;以辅助医生进行疾病诊断和治疗决策。以下是对这一领域的系统介绍&#xff1a; 1. 任务和目标 医学影像分类的主要任务和目标包括&#xff1a; 疾…

12.Spring事务和事务传播机制

文章目录 1.为什么需要事务2.Spring 中事务的实现2.1 MySQL 中的事务使⽤2.2 Spring 编程式事务2.3 Spring 声明式事务&#xff08;自动&#xff09;2.3.1 Transactional 作⽤范围2.3.2 Transactional 参数说明2.3.3 注意事项2.3.4 Transactional ⼯作原理 3.事务隔离级别3.1 事…

vue+element的table合并单元格(竖着合并行)及合计行添加并计算

1 效果: 代码分析: 1 表格头配置: 2 懒得写的:自己复制吧 <el-table:data"tableData"style"width: 98%":height"height"v-loading"isLoading"stripe"false" :span-method"objectSpanMethod"show-summary:summ…

c++ 线程

在 C 中&#xff0c;std::thread 构造函数可以用于将参数传递给线程。这里是一个基本的示例&#xff0c;展示了如何使用 std::thread 来传递参数&#xff1a; #include <iostream> #include <thread>// 定义一个被线程调用的函数 void threadFunc(int arg1, doubl…

C++多线程编程中的锁详解

在现代软件开发中&#xff0c;多线程编程是提升应用程序性能和响应能力的重要手段。然而&#xff0c;多线程编程也带来了数据竞争和死锁等复杂问题。为了确保线程间的同步和共享数据的一致性&#xff0c;C标准库提供了多种锁机制。 1. std::mutex std::mutex是最基础的互斥锁…

视图、存储过程、触发器

一、视图 视图是从一个或者几个基本表&#xff08;或视图&#xff09;导出的表。它与基 本表不同&#xff0c;是一个虚表&#xff0c;视图只能用来从查询&#xff0c;不能做增删改(虚拟的表) 1.创建视图 创建视图的语法&#xff1a; create view 视图名【view_xxx / v_xxx】 a…

深入理解MySQL锁机制与性能优化:详解记录锁、间隙锁、临键锁及慢SQL查询分析

1. 事务隔离和锁机制详解 记录锁 第一种情况,当我们对于唯一性的索引(包括唯一索引和主键索引)使用等值查询,精准匹配到一条记录的时候,这个时候使用的就是记录锁。 比如 where id = 1 4 7 10。 间隙锁 第二种情况,当我们查询的记录不存在,无论是用等值查询还是范围…

如何使用 API 查看极狐GitLab 镜像仓库中的镜像?

GitLab 是一个全球知名的一体化 DevOps 平台&#xff0c;很多人都通过私有化部署 GitLab 来进行源代码托管。极狐GitLab &#xff1a;https://gitlab.cn/install?channelcontent&utm_sourcecsdn 是 GitLab 在中国的发行版&#xff0c;专门为中国程序员服务。可以一键式部署…

Thinkphp开发文档二次整理版

基础部分 安装 环境要求 ​ *php>7.1.0 命令下载 通过Composer进行下载&#xff0c;操作步骤下载软件 phpstudy --->点击软件管理 --->安装Composer --->再点击网站 --->点击管理 --->点击Composer --->复制如下命令代码&#xff1a; ​ 稳定版&…

国际化技术参考

一、概述 国际化就是用户可以选择对应的语言,页面展示成对应的语言; 一个系统的国际化按照信息的所在位置,可以分为三种国际化信息: 前端页面信息后端提示信息数据库的字典类信息二、前端页面国际化 使用i18n库实现国际化 i18n国际化库思路:通过jquery或者dom操作拿到需…

推荐4款简单高效的视频转文字工具。

最近我要将很多的以前的培训视频转换成笔记&#xff0c;觉得很麻烦&#xff0c;于是就搜索有没有什么工具可以帮助。结果就真的找到了很多将视频转换成文字的软件和网站。解决了一个大工程&#xff0c;后来发现其实很多人都会碰到像我这样的问题&#xff0c;于是在这里将我使用…

【前端】JavaScript入门及实战106-110

文章目录 106 a的索引问题107 使用DOM操作CSS108 读取元素当前的样式109 getStyle()110 其他样式操作的属性滚动条练习 106 a的索引问题 <!DOCTYPE html> <html> <head> <title></title> <meta charset"utf-8"> <script typ…

HR问:前端实习生简历实习筛不了,一天上百份,但是都一样,怎么办?

前两天&#xff0c;我们HR过来问&#xff1a;“前端的实习生投的实在太多了&#xff0c;一天下来就几百份了&#xff0c;怎么办&#xff1f;” 我大致看了看这些简历发现&#xff0c;这几百份的简历除了学校不同之外&#xff0c;几乎没有什么区别。 如何筛选&#xff1f; 有…

类和对象:完结

1.再深构造函数 • 之前我们实现构造函数时&#xff0c;初始化成员变量主要使⽤函数体内赋值&#xff0c;构造函数初始化还有⼀种⽅ 式&#xff0c;就是初始化列表&#xff0c;初始化列表的使⽤⽅式是以⼀个冒号开始&#xff0c;接着是⼀个以逗号分隔的数据成 员列表&#xf…

通信原理-思科实验三:无线局域网实验

实验三 无线局域网实验 一&#xff1a;无线局域网基础服务集 实验步骤&#xff1a; 进入物理工作区&#xff0c;导航选择 城市家园; 选择设备 AP0&#xff0c;并分别选择Laptop0、Laptop1放在APO范围外区域 修改笔记本的网卡&#xff0c;从以太网卡切换到无线网卡WPC300N 切…

【C#/C++】C#调C++的接口,给C++传结构体数组

C#调C的接口&#xff0c;给C传结构体数组 1、背景2、实现 1、背景 C#软件创建了一个结构体数组用来存储图像的区域信息&#xff0c;分别是矩形框的左上像素的xy坐标和矩形框右下像素的xy坐标。需要传入给调用的C函数的参数列表中&#xff0c;我们选择使用C#传入一个结构体数组…

力扣Hot100-543二叉树的直径

给你一棵二叉树的根节点&#xff0c;返回该树的 直径 。 二叉树的 直径 是指树中任意两个节点之间最长路径的 长度 。这条路径可能经过也可能不经过根节点 root 。 两节点之间路径的 长度 由它们之间边数表示。 示例 1&#xff1a; 输入&#xff1a;root [1,2,3,4,5] 输出&a…