1.1.4 • Published 2 years ago

rtsp-web-player v1.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

rtsp-web-player

介绍

支持WEB浏览器播放RTSP流前端播放器,需要依赖客户端插件服务(exe文件进行安装。插件需要本地一些操作权限,为了更好使用该插件,安装时请以管理员身份运行安装),客户端插件服务安装启动后可接入当前前端插件包进行对接。

软件架构

前端插件以typescript 编写支持npm安装引入、cdn方式引入,不限于技术栈如vuejs、react、angularjs目前市面上主流MVVM框架结构

安装

npm命令行,

npm install rtsp-web-player --save
or
yarn add rtsp-web-player

使用说明

入口文件样式引入

import 'rtsp-web-player/dist/style/index.css'

vue3引入示例

<template>
  <div class="hello">
    <div id="playerRef" style="height: 700px"></div>
    <button @click="handlePlay">播放</button>
    <button @click="handlePlayByWnd">指定窗口播放</button>
    <button @click="handleSwitchWnd">切换窗口</button>
    <button @click="handleSnapshot">抓拍</button>
    <button @click="handleClear">清空</button>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted } from 'vue';
import RtspPlayer, { RtspWindowEnum } from 'rtsp-web-player';
export default defineComponent({
  name: 'HelloWorld',
  props: {
    msg: String
  },
  setup() {
    let player: RtspPlayer | null = null;
    const init = () => {
      player = new RtspPlayer({
        timeOut: 30000,
        theme: {
          primaryColor: '#8528EE',
          backgroundColor: '#18181C',
          borderColor: '#2D2D30',
          fontColor: '#909092'
        },
        wnd: RtspWindowEnum.SIX,
        target: document.querySelector('#playerRef') as HTMLElement,
        onWindowActiveEvent: (wndInfo) => {
        },
        onEvents: (event) => {
        }
      });
    };
    const handlePlay = () => {
      player?.play({
        rtspUrl: 'rtsp://xxx:xx@123@10.40.147.252/LiveMedia/ch1/Media1',
        cameraName: '252'
      });
    };
    const handleSwitchWnd = () => {
      player?.switchWindow(RtspWindowEnum.SIXTEEN);
    };
    const handlePlayByWnd = () => {
      player?.play({
        rtspUrl: 'rtsp://xxx:xx10.40.147.252/LiveMedia/ch1/Media1',
        cameraName: '252',
        wnd: 1
      });
    };
    const handleClear = () => {
      player?.clearPlayer();
    };
    const handleSnapshot = () => {
      player?.localSnapshot({ wnd: 1, isDownload: false }).then((res) => {
        console.log(
          '🚀 ~ file: HelloWorld.vue ~ line 56 ~ player?.localSnapshot ~ res',
          res
        );
      });
    };
    onMounted(() => {
      init();
    });
    return {
      handlePlay,
      handleSwitchWnd,
      handleClear,
      handlePlayByWnd,
      handleSnapshot
    };
  }
});
</script>

RtspPlayer实例

名称构造参数默认值说明
RtspPlayerRtspOptions初始化的基础参数信息
RtspOptions
名称类型默认值说明
wndRtspWindowEnum默认9窗格默认窗口数,支持1,4,6,9,12,16
targetHTMLElement插件承载的元素容器
qualitynumber100画面的质量数值越高质量越好,最大值为100,数值越低性能越好,图片质量较差。
imageStreamFormatRtspImageFormatjpeg帧画面格式,png和jpeg
frameRatenumber120每秒推送的帧数最大25,数值越大性能要求越高,画面细节更多。
timeOutnumber播放器请求超时时间
snapshotPathstringc:\soc\snapshot抓拍图片存储路径
videoPathstringc:\soc\video本地录像存储路径
wndInfostring | HTMLElement空闲窗口显示内容
serverUrlstring默认客户端插件服务地址,如果是手机端需要填写服务端地址
themePlayerTheme播放器主题颜色
onErrorfunction(err: ErrorMessage) => void异常上报事件回调
onEventsfunction(data: PlayerEvents) => void;播放器事件上报回调函数
onWindowActiveEventfunction(data: any) => void窗口激活事件

方法

名称参数类型默认值返回值说明
playPlayOptionsPromise实时画面/录像回放
batchPlay( PlayOptions[],callback)void批量播放实况/录像
switchWindowRtspWindowEnumvoid设置窗口数
closePlayerWindownumbervoid关闭指定窗口
clearPlayervoid清空所有窗口
localSnapshotSnapshotOptionsPromise抓拍
startRecwnd激活窗口void开启本地录像
stopRecwnd激活窗口void停止本地录像
destroyvoid播放器销毁
RtspWindowEnum 枚举
枚举名称类型枚举说明
ONEnumber1窗格数
FOURnumber4窗格数
SIXnumber6窗格数
NINEnumber9窗格数
TWELVEnumber12窗格数
SIXTEENnumber16窗格数
PlayOptions
名称类型默认值说明
cameraNamestring摄像机名称
rtspUrlstring媒体流地址
wndnumber自动获取空闲窗口如若传入,则指定窗口播放
PlayerTheme
名称类型默认值说明
primaryColorstring主题颜色
fontColorstring字体颜色
borderColorstring边框颜色
backgroundColorstring背景颜色

本地插件唤醒