【vue】萤石云EZUIkit-js-SDK

萤石云 EZUIkit-js-SDK 接入官方文档:https://open.ys7.com/help/1772

vue 组件

npm 地址:https://www.npmjs.com/package/vue-ezuikit

常用功能

npm install ezuikit-js@7.6.8

7.6.8 以上为 pro 公测版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<template>
<div class="hello-ezuikit-js">
<div id="video-container"></div>
<div>
<button @click="init">初始化</button>
<button @click="stop">停止</button>
<button @click="play">播放</button>
<button @click="openSound">开启声音</button>
<button @click="closeSound">关闭声音</button>
<button @click="startSave">开始录制</button>
<button @click="stopSave">结束录制</button>
<button @click="capturePicture">截图</button>
<button @click="fullScreen">全屏</button>
<button @click="cancelFullScreen">退出全屏</button>
<button @click="getOSDTime">获取基准时间</button>
<button @click="ezopenStartTalk">开始对讲</button>
<button @click="ezopenStopTalk">结束对讲</button>
<button @click="destroy">销毁</button>
</div>
</div>
</template>

<script setup>
import { onMounted } from "vue";
import EZUIKit from "ezuikit-js";

/**
* @type {EZUIKit.EZUIKitPlayer | null}
*/
let player;

/**
* 初始化萤石云播放器
*/
function init() {
if (player) destroy();
// accessToken 请求演示(需要替换真实的accessToken请求)
fetch("https://open.ys7.com/jssdk/ezopen/demo/token")
.then((response) => response.json())
.then((res) => {
var accessToken = res.data.accessToken;
player = new EZUIKit.EZUIKitPlayer({
id: "video-container",
accessToken: accessToken,
url: "ezopen://open.ys7.com/序列号/通道号.live",
template: "simple", // simple: 极简版; standard: 标准版; security: 安防版; voice: 语音版; pcLive: pc直播; pcRec: pc回放; mobileLive: 移动端直播; mobileRec: 移动端回放
plugin: [], // 按需加载插件: talk-对讲
width: 600,
height: 400,
});
window.player = player;
});
}

onMounted(() => {
init();
});

/**
* 播放
*/
function play() {
const playPromise = player.play();
playPromise.then((data) => {
console.log("promise 获取 数据", data);
});
}

/**
* 停止
*/
function stop() {
const stopPromise = player.stop();
stopPromise.then((data) => {
console.log("promise 获取 数据", data);
});
}

/**
* 获取基准时间
*/
function getOSDTime() {
const getOSDTimePromise = player.getOSDTime();
getOSDTimePromise.then((data) => {
console.log("promise 获取 数据", data);
});
}

/**
* 截图
*/
function capturePicture() {
player.capturePicture(`${new Date().getTime()}`, (data) => {
console.log("截图数据", data);
});
}

/**
* 开启声音
*/
function openSound() {
const openSoundPromise = player.openSound();
openSoundPromise.then((data) => {
console.log("promise 获取 数据", data);
});
}

/**
* 关闭声音
*/
function closeSound() {
const openSoundPromise = player.closeSound();
openSoundPromise.then((data) => {
console.log("promise 获取 数据", data);
});
}

/**
* 开始录制
*/
function startSave() {
const startSavePromise = player.startSave(`${new Date().getTime()}`);
startSavePromise.then((data) => {
console.log("promise 获取 数据", data);
});
}

/**
* 结束录制
*/
function stopSave() {
const stopSavePromise = player.stopSave();
stopSavePromise.then((data) => {
console.log("promise 获取 数据", data);
});
}

/**
* 开启对讲
*/
function ezopenStartTalk() {
player.startTalk();
}

/**
* 关闭对讲
*/
function ezopenStopTalk() {
player.stopTalk();
}

/**
* 全屏
*/
function fullScreen() {
player.fullScreen();
}

/**
* 退出全屏
*/
function cancelFullScreen() {
player.cancelFullScreen();
}

/**
* 销毁
*/
function destroy() {
player.value = null;
document.getElementById(playerId.value)?.remove();
}
</script>