wangzhibo
7 天以前 1c3ae7bcad167c9a593f4634968a6e142d9b08f9
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<script lang="ts" setup>
defineOptions({
    name: 'ezuikit-player'
});
import { EZUIKitPlayer } from "ezuikit-js";
import { onMounted, ref } from "vue";
 
interface IPlayer {
  play: Function;
  stop: Function;
  getOSDTime: Function;
  capturePicture: Function;
  openSound: Function;
  closeSound: Function;
  startSave: Function;
  stopSave: Function;
  startTalk: Function;
  stopTalk: Function;
  fullscreen: Function;
  destroy: Function;
  eventEmitter: any;
  on: any // eventEmitter
}
 
let player: IPlayer;
 
const accessToken = ref(
  "at.daz914gk2cnsdm748wt7r6im1ww50d8q-9o0d9tbx2h-0mefajp-pd25qljk"
);
const url = ref("ezopen://open.ys7.com/BC7799091/1.hd.live");
const staticPath = ref("");
 
const play = () => {
  if (player) player.play()
};
 
const stop = () => {
  if (player) player.stop();
};
 
const getOSDTime = () => {
  if (player)
  player.getOSDTime().then((data: any) => {
    console.log("getOSDTime 获取 数据", data);
  });
};
 
const capturePicture = () => {
  if (player)
    player.capturePicture(
      `${new Date().getTime()}`
    ).then((data: any) => {
      console.log("capturePicture 获取 数据", data);
    });
};
 
const openSound = () => {
    if (player) player.openSound();
};
 
const closeSound = () => {
    if (player) player.closeSound();
};
 
const startSave = () => {
  if (player)
    player.startSave(`${new Date().getTime()}`).then((data: any) => {
      console.log("startSave 获取 数据", data);
    });
};
 
const stopSave = () => {
  if (player)
    player.stopSave().then((data: any) => {
      console.log("stopSave 获取 数据", data);
    });
};
 
const startTalk = () => {
  if (player) player.startTalk();
};
 
const stopTalk = () => {
  if (player) player.stopTalk();
};
 
const fullscreen = () => {
  if (player) player.fullscreen();
};
 
const destroy = () => {
  if (player) {
    player.destroy().then((data: any) => {
      console.log("promise 获取 数据", data);
    });
    player = null!;
  }
};
 
const init = () => {
  if (player) {
    destroy();
  }
  console.group("mounted 组件挂载完毕状态===============》");
  // fetch("https://open.ys7.com/jssdk/ezopen/demo/token")
  //   .then((response) => response.json())
  //   .then((res) => {
  //     var accessToken = res.data.accessToken;
  player = new EZUIKitPlayer({
    id: "video-container", // 视频容器ID
    accessToken: accessToken.value,
    url: url.value,
    // simple: 极简版; pcLive: pc直播; pcRec: pc回放; mobileLive: 移动端直播; mobileRec: 移动端回放;security: 安防版; voice: 语音版;
    template: "pcLive",
    // width: 600,
    height: 400,
    // quality: 1, // 
    // language: "en", // zh | en
    handleError: (err: any) => {
      console.error("handleError", err);
    },
    // 自定义清晰度 默认 null, 如果有值 sdk 内部不在进行获取, null 默认使用接口获取的清晰度列表, videoLevelList.length === 0 不展示清晰度控件 sdk 内部不在进行获取, videoLevelList.length > 0 展示控件 sdk 内部不在进行获取
    // videoLevelList: [
    //   { level: 0, name: "流畅", streamTypeIn: 1 },
    //   { level: 1, name: "标清", streamTypeIn: 1 },
    // ],
    staticPath: staticPath.value,  // || "./ezuikit_static", // 如果想使用本地静态资源,请复制根目录下ezuikit_static 到当前目录下, 然后设置该值. 默认使用CDN静态资源 "https://openstatic.ys7.com/ezuikit_js/v{version}/ezuikit_static",
    scaleMode: 1, // 默认 0 完全填充窗口,会有拉伸 1: 等比适配 2: 等比完全填充窗口, 超出隐藏 @sine 8.2.0
    env: {
      // https://open.ys7.com/help/1772?h=domain
      // domain默认是 https://open.ys7.com, 如果是私有化部署或海外的环境,请配置对应的domain
      // The default domain is https://open.ys7.com If it is a private deployment or overseas (outside of China) environment, please configure the corresponding domain
      domain: "https://open.ys7.com",
    },
    // 日志打印设置
    loggerOptions: {
      // player.setLoggerOptions(options)
      level: "INFO", // INFO LOG  WARN  ERROR
      name: "ezuikit",
      showTime: true,
    },
    // 视频流的信息回调类型
    /**
     * 打开流信息回调,监听 streamInfoCB 事件
     * 0 : 每次都回调
     * 1 : 只回调一次
     * 注意:会影响性能
     * 默认值 1
     */
    streamInfoCBType: 1,
    // v8.1.10
    // 自定义清晰度 默认 null, 如果有值 sdk 内部不在进行获取, null 默认使用接口获取的清晰度列表, videoLevelList.length === 0 不展示清晰度控件 sdk 内部不在进行获取, videoLevelList.length > 0 展示控件 sdk 内部不在进行获取
    // videoLevelList: [
    //   { level: 1, name: "标清", streamTypeIn: 2 }, // 需要保证支持子码流 (streamTypeIn=2)
    //   { level: 2, name: "高清", streamTypeIn: 1 },
    // ],
    // videoLevelList: [
    //   { level: -1, name: "标清", streamTypeIn: 2 }, // 8.1.17 开始 当 level 的值小于 0时, 不在向设备发送指令,仅根据 streamTypeIn 切换码流 (请保证 streamTypeIn 对应的码流存在)
    //   { level: -2, name: "高清", streamTypeIn: 1 }, // 8.1.17 开始 当 level 的值小于 0时, 不在向设备发送指令,仅根据 streamTypeIn 切换码流 (请保证 streamTypeIn 对应的码流存在)
    // ]
  });
 
      // 8.1.x 事件监听
      // player.eventEmitter.on(EZUIKitPlayer.EVENTS.videoInfo, (info) => {
      //   console.warn("eventEmitter videoInfo", info);
      // });
      // 8.2.x 事件监听
      player.on(EZUIKitPlayer.EVENTS.videoInfo, (info: any) => {
        console.warn("videoInfo", info);
      });
 
      // 8.1.x 事件监听
      // player.eventEmitter.on(EZUIKitPlayer.EVENTS.audioInfo, (info) => {
      //   console.warn("eventEmitter audioInfo", info);
      // });
      // 8.2.x 事件监听
      player.on(EZUIKitPlayer.EVENTS.audioInfo, (info: any) => {
        console.warn("audioInfo", info);
      });
 
      // 首帧渲染成功
      // first frame display
      // 8.1.x 事件监听
      // player.eventEmitter.on(EZUIKitPlayer.EVENTS.firstFrameDisplay, () => {
      //     console.warn("eventEmitter firstFrameDisplay ");
      // });
      // 8.2.x 事件监听
      player.on(EZUIKitPlayer.EVENTS.firstFrameDisplay, () => {
        console.warn("firstFrameDisplay ");
      });
 
      // 8.1.x 事件监听
      // player.eventEmitter.on(EZUIKitPlayer.EVENTS.streamInfoCB, (info) => {
      //   console.warn("eventEmitter streamInfoCB ", info);
      // });
      // 8.2.x 事件监听
      player.on(EZUIKitPlayer.EVENTS.streamInfoCB, (info: any) => {
        console.warn("streamInfoCB ", info);
      });
 
      window.player = player;
  // });
};
 
onMounted(() => {
  init();
});
</script>
 
<template>
  <div class="hello-ezuikit-js">
    <div>
      <div id="video-container" style="height: 400px"></div>
    </div>
    <div style="margin-bottom: 12px">
      <label style="display: flex; margin-bottom: 8px">
        url:
        <input
          v-model="url"
          type="text"
          placeholder="请输入播放地址"
          style="width: 100%"
        />
      </label>
      <label style="display: flex; margin-bottom: 8px">
        accessToken:
        <input
          v-model="accessToken"
          type="text"
          placeholder="请输入 accessToken"
          style="width: 100%"
        />
      </label>
      <label style="display: flex; margin-bottom: 8px">
        staticPath:
        <input
          v-model="staticPath"
          type="text"
          placeholder="请输入 staticPath"
          style="width: 100%"
        />
      </label>
    </div>
    <div>
      <button @click="init">init</button>
      <button @click="stop">stop</button>
      <button @click="play">play</button>
      <button @click="openSound">openSound</button>
      <button @click="closeSound">closeSound</button>
      <button @click="startSave">startSave</button>
      <button @click="stopSave">stopSave</button>
      <button @click="capturePicture">capturePicture</button>
      <button @click="fullscreen">fullscreen</button>
      <button @click="getOSDTime">getOSDTime</button>
      <button @click="startTalk">startTalk</button>
      <button @click="stopTalk">stopTalk</button>
      <button @click="destroy">destroy</button>
    </div>
  </div>
</template>