index.vue
5.08 KB
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
<template>
<div class="vion-player" ref="container"></div>
</template>
<script>
// import { watermarkBase64 } from './data';
import { getWatermarkCanvasImg } from './utils';
export default {
name: 'VionPlayer',
props: {
type: {
type: String,
default: 'live', // playback
},
playUrl: {
type: String,
default: '', // 若配置,则播放器加载后,自动播放
},
datetimeRange: {
type: Array,
default: null,
},
watermarkText: {
type: String,
default: '',
},
controlAutoHide: {
type: Boolean,
default: true,
},
showPtz: {
type: Boolean,
default: true,
},
},
data() {
return {
// eslint-disable-next-line
_jessibuca: null,
playing: false,
player: {
height: 0,
width: 0,
},
}
},
mounted() {
console.log("this.playUrl", this.playUrl);
this.init();
},
unmounted() {
this.destroy();
},
methods:{
init(params = {}) {
console.log("this.playUrl", this.playUrl);
const options = Object.assign({
container: this.$refs.container,
decoder: '/jessibuca-pro/decoder-pro.js',
isResize: false,
text: '', // TODO: 功能暂不清楚
useMSE: true,
useWCS: false,
isNotMute: false,
timeout: 10,
keepScreenOn: true, // 屏幕常亮
debug: false, // 是否开启控制台调试打印
// 按钮和界面
loadingText: '加载中...',
controlAutoHide: this.controlAutoHide,
supportDblclickFullscreen: false,
showBandwidth: false, // 显示网速
// TODO: 水印功能暂不可用
/* watermarkConfig: {
image: {
src: this.getWatermarkBase64(),
width: 150,
height: 48
},
right: 10,
top: 30
}, */
operateBtns: {
fullscreen: true,
screenshot: false,
play: true,
audio: true,
ptz: true, // 云台
zoom: true,
performance: false,
},
extendOperateBtns: [],
// 云台控制
ptzClickType: 'click', // click mouseDownAndUp
ptzZoomShow: true,
ptzMoreArrowShow: true,
ptzApertureShow: true,
ptzFocusShow: true,
});
this._jessibuca = new window.JessibucaPro(options);
this.registerEvent(this._jessibuca);
console.log("this.playUrl", this.playUrl);
if (this.playUrl) {
// 示例上有延迟写法
setTimeout(this.play(this.playUrl), 150);
}
},
registerEvent(playerIns) {
playerIns.on("log", msg => {
console.log("on-log", msg);
});
playerIns.on("videoInfo", (data) => {
console.log('width:', data.width, 'height:', data.height);
this.player.width = data.width;
this.player.height = data.height;
});
playerIns.on('play', (flag) => {
console.log('on-play', flag);
this.playing = true;
});
playerIns.on('pause', (flag) => {
console.log('on-pause', flag);
this.playing = false;
});
playerIns.on('ptz', (arrow) => {
// console.log('ptz', arrow);
this.$emit('ptz-control', arrow);
});
},
getWatermarkBase64() {
const data = getWatermarkCanvasImg(150, 48, '文安智能');
console.log('getWatermarkBase64', data);
},
// 暴露方法
play(url) {
if (url) {
this._jessibuca.play(url);
} else {
console.error('The url is not valid');
}
},
pause() {
this._jessibuca.pause();
},
stop() {
this._jessibuca.pause(true);
},
destroy() {
if (this._jessibuca) {
this._jessibuca.destroy().then(() => {
this._jessibuca = null;
this.playing = false;
});
}
},
screenshot(filename = '', format = 'png', quality = 0.92, type = 'base64') {
return new Promise((resolve, reject) => {
// 如果是播放状态
if (!this.player.height || !this.player.width || !this.playing) {
reject(new Error('invaild data'));
}
// 创建一个新的图片对象
const image = new Image();
// 当图像加载完成后执行
image.onload = () => {
// 创建一个 Canvas 元素
const canvas = getWatermarkCanvasImg(this.player.width, this.player.height, this.watermarkText, image);;
// 将带有水印的 Canvas 转换回 base64
const watermarkedBase64 = canvas.toDataURL('image/png');
// 现在,watermarkedBase64 包含了带有水印的 base64 图像数据
// console.log(watermarkedBase64);
resolve(watermarkedBase64);
};
image.error = function() {
reject(new Error('image loade fail'));
}
// 设置图像的 src 属性,加载图像
image.src = this._jessibuca.screenshot(filename, format, quality, type);
});
},
},
}
</script>
<style lang="scss" scoped>
.vion-player {
background-color: rgba(13, 14, 27, 0.7);
}
</style>