zwplayer-vue2x 1.0.33 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +778 -16
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -132,49 +132,783 @@ export default {
|
|
|
132
132
|
@onmediaevent="onPlayerMediaEvent"
|
|
133
133
|
:snapshotButton="true"
|
|
134
134
|
:optionButton="true"
|
|
135
|
-
:
|
|
135
|
+
:infoButton="true"
|
|
136
|
+
:enableDanmu="true"
|
|
137
|
+
:chapterButton="true"
|
|
138
|
+
danmuBarId="danmu-controlbar"
|
|
139
|
+
:fluid="true"
|
|
140
|
+
:autoplay="false"
|
|
141
|
+
:disableMutedConfirm="true"
|
|
142
|
+
/>
|
|
143
|
+
</div>
|
|
144
|
+
</template>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 使用示例
|
|
148
|
+
|
|
149
|
+
#### 1. 基础使用
|
|
150
|
+
|
|
151
|
+
最简单的播放器配置,展示基本功能:
|
|
152
|
+
|
|
153
|
+
```html
|
|
154
|
+
<template>
|
|
155
|
+
<div class="demo">
|
|
156
|
+
<zwplayer
|
|
157
|
+
v-if="playerOpen"
|
|
158
|
+
ref="zwplayerRef"
|
|
159
|
+
nodeid="main-player"
|
|
160
|
+
:murl="movieUrl"
|
|
161
|
+
@onready="onPlayerReady"
|
|
162
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
163
|
+
:snapshotButton="true"
|
|
164
|
+
:optionButton="true"
|
|
165
|
+
:infoButton="true"
|
|
166
|
+
:localPlayback="true"
|
|
167
|
+
:recordButton="true"
|
|
168
|
+
:segmentButton="true"
|
|
169
|
+
:autoplay="false"
|
|
170
|
+
:enableDanmu="true"
|
|
171
|
+
:chapterButton="true"
|
|
172
|
+
:fluid="true"
|
|
173
|
+
:disableMutedConfirm="true"
|
|
174
|
+
danmuBarId="danmu-controlbar"
|
|
175
|
+
/>
|
|
176
|
+
</div>
|
|
177
|
+
</template>
|
|
178
|
+
|
|
179
|
+
<script>
|
|
180
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
181
|
+
|
|
182
|
+
export default {
|
|
183
|
+
name: 'BasicDemo',
|
|
184
|
+
components: {
|
|
185
|
+
zwplayer
|
|
186
|
+
},
|
|
187
|
+
data() {
|
|
188
|
+
return {
|
|
189
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
190
|
+
playerOpen: true
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
methods: {
|
|
194
|
+
onPlayerReady() {
|
|
195
|
+
console.log('播放器已准备就绪')
|
|
196
|
+
},
|
|
197
|
+
onPlayerMediaEvent(event) {
|
|
198
|
+
console.log('媒体事件:', event.type)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
</script>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### 2. 弹幕功能
|
|
206
|
+
|
|
207
|
+
展示播放器弹幕功能,支持实时弹幕发送和接收:
|
|
208
|
+
|
|
209
|
+
```html
|
|
210
|
+
<template>
|
|
211
|
+
<div class="demo">
|
|
212
|
+
<zwplayer
|
|
213
|
+
v-if="playerOpen"
|
|
214
|
+
ref="zwplayerRef"
|
|
215
|
+
:murl="movieUrl"
|
|
216
|
+
@onready="onPlayerReady"
|
|
217
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
218
|
+
:autoplay="false"
|
|
136
219
|
:sendDanmu="sendDanmu"
|
|
220
|
+
:enableDanmu="true"
|
|
221
|
+
:fluid="true"
|
|
222
|
+
:disableMutedConfirm="true"
|
|
223
|
+
danmuBarId="danmu-controlbar"
|
|
224
|
+
/>
|
|
225
|
+
|
|
226
|
+
<!-- 弹幕控制条 -->
|
|
227
|
+
<div class="danmubar" id="danmu-controlbar"></div>
|
|
228
|
+
</div>
|
|
229
|
+
</template>
|
|
230
|
+
|
|
231
|
+
<script>
|
|
232
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
233
|
+
|
|
234
|
+
export default {
|
|
235
|
+
name: 'DanmuDemo',
|
|
236
|
+
components: {
|
|
237
|
+
zwplayer
|
|
238
|
+
},
|
|
239
|
+
data() {
|
|
240
|
+
return {
|
|
241
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
242
|
+
playerOpen: true,
|
|
243
|
+
player: null
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
methods: {
|
|
247
|
+
onPlayerReady() {
|
|
248
|
+
this.player = this.$refs.zwplayerRef
|
|
249
|
+
|
|
250
|
+
// 添加测试弹幕
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
if (this.player && this.player.appendDanmu) {
|
|
253
|
+
const testDanmu1 = {
|
|
254
|
+
border: '1px solid #ccc',
|
|
255
|
+
text: '欢迎来到 zwplayer 弹幕演示!',
|
|
256
|
+
color: '#ff6b6b'
|
|
257
|
+
}
|
|
258
|
+
this.player.appendDanmu(testDanmu1)
|
|
259
|
+
}
|
|
260
|
+
}, 3000)
|
|
261
|
+
},
|
|
262
|
+
onPlayerMediaEvent(event) {
|
|
263
|
+
console.log('媒体事件:', event.type)
|
|
264
|
+
},
|
|
265
|
+
sendDanmu(danmuText) {
|
|
266
|
+
console.log('发送弹幕:', danmuText)
|
|
267
|
+
|
|
268
|
+
if (!danmuText) return
|
|
269
|
+
|
|
270
|
+
const danmu = {
|
|
271
|
+
border: '1px solid #ccc',
|
|
272
|
+
text: danmuText
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 将弹幕添加到播放器
|
|
276
|
+
if (this.player && this.player.appendDanmu) {
|
|
277
|
+
this.player.appendDanmu(danmu)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
</script>
|
|
283
|
+
|
|
284
|
+
<style scoped>
|
|
285
|
+
.danmubar {
|
|
286
|
+
height: 50px;
|
|
287
|
+
background-color: #232323;
|
|
288
|
+
padding: 8px;
|
|
289
|
+
box-sizing: border-box;
|
|
290
|
+
}
|
|
291
|
+
</style>
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
#### 3. 字幕功能
|
|
295
|
+
|
|
296
|
+
展示播放器字幕功能,支持多语言字幕切换:
|
|
297
|
+
|
|
298
|
+
```html
|
|
299
|
+
<template>
|
|
300
|
+
<div class="demo">
|
|
301
|
+
<zwplayer
|
|
302
|
+
v-if="playerOpen"
|
|
303
|
+
ref="zwplayerRef"
|
|
304
|
+
nodeid="main-player"
|
|
305
|
+
:murl="movieUrl"
|
|
306
|
+
@onready="onPlayerReady"
|
|
307
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
308
|
+
:autoplay="false"
|
|
309
|
+
:fluid="true"
|
|
310
|
+
:disableMutedConfirm="true"
|
|
311
|
+
/>
|
|
312
|
+
</div>
|
|
313
|
+
</template>
|
|
314
|
+
|
|
315
|
+
<script>
|
|
316
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
317
|
+
|
|
318
|
+
export default {
|
|
319
|
+
name: 'SubtitleDemo',
|
|
320
|
+
components: {
|
|
321
|
+
zwplayer
|
|
322
|
+
},
|
|
323
|
+
data() {
|
|
324
|
+
return {
|
|
325
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
326
|
+
playerOpen: true
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
methods: {
|
|
330
|
+
onPlayerReady() {
|
|
331
|
+
const player = this.$refs.zwplayerRef
|
|
332
|
+
|
|
333
|
+
// 添加多个字幕轨道
|
|
334
|
+
setTimeout(() => {
|
|
335
|
+
if (player) {
|
|
336
|
+
player.addSubtitle('/subtitles/zh.vtt', '1')
|
|
337
|
+
player.addSubtitle('/subtitles/en.vtt', '2')
|
|
338
|
+
}
|
|
339
|
+
}, 1000)
|
|
340
|
+
},
|
|
341
|
+
onPlayerMediaEvent(event) {
|
|
342
|
+
console.log('媒体事件:', event.type)
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
</script>
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### 4. 缩略图预览
|
|
350
|
+
|
|
351
|
+
在进度条上显示视频帧预览:
|
|
352
|
+
|
|
353
|
+
```html
|
|
354
|
+
<template>
|
|
355
|
+
<div class="demo">
|
|
356
|
+
<zwplayer
|
|
357
|
+
v-if="playerOpen"
|
|
358
|
+
ref="zwplayerRef"
|
|
359
|
+
nodeid="main-player"
|
|
360
|
+
:murl="movieUrl"
|
|
361
|
+
@onready="onPlayerReady"
|
|
362
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
363
|
+
:thumbnails="thumbnails"
|
|
364
|
+
:enableDanmu="true"
|
|
365
|
+
:chapterButton="true"
|
|
366
|
+
:fluid="true"
|
|
367
|
+
:disableMutedConfirm="true"
|
|
368
|
+
:autoplay="false"
|
|
369
|
+
/>
|
|
370
|
+
</div>
|
|
371
|
+
</template>
|
|
372
|
+
|
|
373
|
+
<script>
|
|
374
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
375
|
+
|
|
376
|
+
export default {
|
|
377
|
+
name: 'ThumbnailDemo',
|
|
378
|
+
components: {
|
|
379
|
+
zwplayer
|
|
380
|
+
},
|
|
381
|
+
data() {
|
|
382
|
+
return {
|
|
383
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
384
|
+
playerOpen: true,
|
|
385
|
+
thumbnails: {
|
|
386
|
+
url: 'https://cdn.zwplayer.cn/media/b44c43c90be3521bc352aad1e80f9cd0_thumb.jpg',
|
|
387
|
+
width: 160,
|
|
388
|
+
height: 90,
|
|
389
|
+
row: 9,
|
|
390
|
+
col: 9,
|
|
391
|
+
total: 74
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
methods: {
|
|
396
|
+
onPlayerReady() {
|
|
397
|
+
console.log('播放器已准备就绪')
|
|
398
|
+
},
|
|
399
|
+
onPlayerMediaEvent(event) {
|
|
400
|
+
console.log('媒体事件:', event.type)
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
</script>
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
#### 5. 章节分段
|
|
408
|
+
|
|
409
|
+
展示播放器章节分段功能:
|
|
410
|
+
|
|
411
|
+
```html
|
|
412
|
+
<template>
|
|
413
|
+
<div class="demo">
|
|
414
|
+
<zwplayer
|
|
415
|
+
v-if="playerOpen"
|
|
416
|
+
ref="zwplayerRef"
|
|
417
|
+
nodeid="main-player"
|
|
418
|
+
:murl="movieUrl"
|
|
419
|
+
@onready="onPlayerReady"
|
|
420
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
421
|
+
:chapterButton="true"
|
|
422
|
+
:autoplay="false"
|
|
423
|
+
:fluid="true"
|
|
424
|
+
:disableMutedConfirm="true"
|
|
425
|
+
/>
|
|
426
|
+
</div>
|
|
427
|
+
</template>
|
|
428
|
+
|
|
429
|
+
<script>
|
|
430
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
431
|
+
|
|
432
|
+
export default {
|
|
433
|
+
name: 'ChapterDemo',
|
|
434
|
+
components: {
|
|
435
|
+
zwplayer
|
|
436
|
+
},
|
|
437
|
+
data() {
|
|
438
|
+
return {
|
|
439
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
440
|
+
playerOpen: true
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
methods: {
|
|
444
|
+
onPlayerReady() {
|
|
445
|
+
const player = this.$refs.zwplayerRef
|
|
446
|
+
|
|
447
|
+
setTimeout(() => {
|
|
448
|
+
if (player) {
|
|
449
|
+
const chapters = [{
|
|
450
|
+
title: "分段1",
|
|
451
|
+
desc: "分段1描述",
|
|
452
|
+
time: 0,
|
|
453
|
+
duration: 50,
|
|
454
|
+
thumb: null
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
title: "分段2",
|
|
458
|
+
desc: "分段2描述",
|
|
459
|
+
time: 50,
|
|
460
|
+
duration: 100,
|
|
461
|
+
style: {
|
|
462
|
+
background: "blue"
|
|
463
|
+
},
|
|
464
|
+
image: null
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
title: "分段3",
|
|
468
|
+
desc: "分段3描述",
|
|
469
|
+
time: 100,
|
|
470
|
+
duration: 200,
|
|
471
|
+
style: {
|
|
472
|
+
background: "green"
|
|
473
|
+
},
|
|
474
|
+
image: null
|
|
475
|
+
}
|
|
476
|
+
]
|
|
477
|
+
player.setChapters(chapters)
|
|
478
|
+
}
|
|
479
|
+
}, 1000)
|
|
480
|
+
},
|
|
481
|
+
onPlayerMediaEvent(event) {
|
|
482
|
+
console.log('媒体事件:', event.type)
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
</script>
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
#### 6. 截图功能
|
|
490
|
+
|
|
491
|
+
展示播放器截图功能,支持一键截取当前播放画面:
|
|
492
|
+
|
|
493
|
+
```html
|
|
494
|
+
<template>
|
|
495
|
+
<div class="demo">
|
|
496
|
+
<zwplayer
|
|
497
|
+
v-if="playerOpen"
|
|
498
|
+
ref="zwplayerRef"
|
|
499
|
+
nodeid="main-player"
|
|
500
|
+
:murl="movieUrl"
|
|
501
|
+
@onready="onPlayerReady"
|
|
502
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
503
|
+
:snapshotButton="true"
|
|
504
|
+
:fluid="true"
|
|
505
|
+
:autoplay="false"
|
|
506
|
+
:disableMutedConfirm="true"
|
|
507
|
+
/>
|
|
508
|
+
</div>
|
|
509
|
+
</template>
|
|
510
|
+
|
|
511
|
+
<script>
|
|
512
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
513
|
+
|
|
514
|
+
export default {
|
|
515
|
+
name: 'ScreenshotDemo',
|
|
516
|
+
components: {
|
|
517
|
+
zwplayer
|
|
518
|
+
},
|
|
519
|
+
data() {
|
|
520
|
+
return {
|
|
521
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
522
|
+
playerOpen: true
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
methods: {
|
|
526
|
+
onPlayerReady() {
|
|
527
|
+
console.log('播放器已准备就绪')
|
|
528
|
+
},
|
|
529
|
+
onPlayerMediaEvent(event) {
|
|
530
|
+
console.log('媒体事件:', event.type)
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
</script>
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
#### 7. 流式播放
|
|
538
|
+
|
|
539
|
+
展示播放器的流式布局功能,播放器会自适应容器宽度:
|
|
540
|
+
|
|
541
|
+
```html
|
|
542
|
+
<template>
|
|
543
|
+
<div class="demo">
|
|
544
|
+
<zwplayer
|
|
545
|
+
v-if="playerOpen"
|
|
546
|
+
ref="zwplayerRef"
|
|
547
|
+
nodeid="main-player"
|
|
548
|
+
:murl="movieUrl"
|
|
549
|
+
@onready="onPlayerReady"
|
|
550
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
551
|
+
:snapshotButton="true"
|
|
552
|
+
:optionButton="true"
|
|
137
553
|
:infoButton="true"
|
|
138
554
|
:enableDanmu="true"
|
|
139
555
|
:chapterButton="true"
|
|
140
|
-
|
|
556
|
+
:fluid="true"
|
|
557
|
+
:autoplay="false"
|
|
558
|
+
:disableMutedConfirm="true"
|
|
141
559
|
/>
|
|
142
560
|
</div>
|
|
143
561
|
</template>
|
|
562
|
+
|
|
563
|
+
<script>
|
|
564
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
565
|
+
|
|
566
|
+
export default {
|
|
567
|
+
name: 'FluidDemo',
|
|
568
|
+
components: {
|
|
569
|
+
zwplayer
|
|
570
|
+
},
|
|
571
|
+
data() {
|
|
572
|
+
return {
|
|
573
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
574
|
+
playerOpen: true
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
methods: {
|
|
578
|
+
onPlayerReady() {
|
|
579
|
+
console.log('播放器已准备就绪')
|
|
580
|
+
},
|
|
581
|
+
onPlayerMediaEvent(event) {
|
|
582
|
+
console.log('媒体事件:', event.type)
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
</script>
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
#### 8. Logo水印
|
|
590
|
+
|
|
591
|
+
展示播放器Logo水印功能,支持自定义Logo位置、大小和透明度:
|
|
592
|
+
|
|
593
|
+
```html
|
|
594
|
+
<template>
|
|
595
|
+
<div class="demo">
|
|
596
|
+
<zwplayer
|
|
597
|
+
v-if="playerOpen"
|
|
598
|
+
ref="zwplayerRef"
|
|
599
|
+
nodeid="main-player"
|
|
600
|
+
:murl="movieUrl"
|
|
601
|
+
@onready="onPlayerReady"
|
|
602
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
603
|
+
:autoplay="false"
|
|
604
|
+
:logo="logo"
|
|
605
|
+
:poster="poster"
|
|
606
|
+
:fluid="true"
|
|
607
|
+
:disableMutedConfirm="true"
|
|
608
|
+
/>
|
|
609
|
+
</div>
|
|
610
|
+
</template>
|
|
611
|
+
|
|
612
|
+
<script>
|
|
613
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
614
|
+
|
|
615
|
+
export default {
|
|
616
|
+
name: 'LogoDemo',
|
|
617
|
+
components: {
|
|
618
|
+
zwplayer
|
|
619
|
+
},
|
|
620
|
+
data() {
|
|
621
|
+
return {
|
|
622
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
623
|
+
playerOpen: true,
|
|
624
|
+
poster: 'https://www.zwplayer.cn/zwplayer-preview.png',
|
|
625
|
+
logo: {
|
|
626
|
+
icon: 'https://cdn.zwplayer.cn/logo.png',
|
|
627
|
+
dock: 'right',
|
|
628
|
+
x: '5%',
|
|
629
|
+
y: '5%',
|
|
630
|
+
width: '10%',
|
|
631
|
+
height: '10%',
|
|
632
|
+
opacity: 70
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
},
|
|
636
|
+
methods: {
|
|
637
|
+
onPlayerReady() {
|
|
638
|
+
console.log('播放器已准备就绪')
|
|
639
|
+
},
|
|
640
|
+
onPlayerMediaEvent(event) {
|
|
641
|
+
console.log('媒体事件:', event.type)
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
</script>
|
|
144
646
|
```
|
|
145
647
|
|
|
146
648
|
### 主要属性说明
|
|
147
649
|
|
|
148
|
-
| 属性名称 | 说明 |
|
|
149
|
-
|
|
150
|
-
| murl |
|
|
151
|
-
|
|
|
152
|
-
|
|
|
153
|
-
|
|
|
154
|
-
|
|
|
650
|
+
| 属性名称 | 类型 | 说明 | 默认值 |
|
|
651
|
+
|---------|------|------|--------|
|
|
652
|
+
| murl | String/Object/Array | 媒体地址参数,支持动态切换 | - |
|
|
653
|
+
| fluid | Boolean | 是否启用流式布局(自适应容器宽度) | false |
|
|
654
|
+
| autoplay | Boolean | 是否自动播放 | false |
|
|
655
|
+
| disableMutedConfirm | Boolean | 禁用静音确认 | false |
|
|
656
|
+
| enableDanmu | Boolean | 是否启用弹幕功能 | false |
|
|
657
|
+
| snapshotButton | Boolean | 是否显示截图按钮 | false |
|
|
658
|
+
| optionButton | Boolean | 是否显示设置按钮 | false |
|
|
659
|
+
| infoButton | Boolean | 是否显示信息按钮 | false |
|
|
660
|
+
| chapterButton | Boolean | 是否显示章节按钮 | false |
|
|
661
|
+
| recordButton | Boolean | 是否显示录制按钮 | false |
|
|
662
|
+
| segmentButton | Boolean | 是否显示分段按钮 | false |
|
|
663
|
+
| localPlayback | Boolean | 是否启用本地播放功能 | false |
|
|
664
|
+
| sendDanmu | Function | 发送弹幕的回调函数 | - |
|
|
665
|
+
| thumbnails | Object | 缩略图配置对象 | - |
|
|
666
|
+
| logo | Object | Logo水印配置对象 | - |
|
|
667
|
+
| poster | String | 视频封面图地址 | - |
|
|
668
|
+
| 其它 | - | 请参考 [zwplayer 播放器构造函数参数](https://www.zwplayer.cn/docs/support/guide-configuration.html) | - |
|
|
669
|
+
|
|
670
|
+
**缩略图配置对象(thumbnails)示例:**
|
|
671
|
+
|
|
672
|
+
```javascript
|
|
673
|
+
thumbnails: {
|
|
674
|
+
url: 'https://cdn.zwplayer.cn/media/b44c43c90be3521bc352aad1e80f9cd0_thumb.jpg',
|
|
675
|
+
width: 160, // 每个小缩略图的宽度
|
|
676
|
+
height: 90, // 每个小缩略图的高度
|
|
677
|
+
row: 9, // 缩略图总行数
|
|
678
|
+
col: 9, // 缩略图总列数
|
|
679
|
+
total: 74 // 缩略图总数
|
|
680
|
+
}
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
**Logo水印配置对象(logo)示例:**
|
|
684
|
+
|
|
685
|
+
```javascript
|
|
686
|
+
logo: {
|
|
687
|
+
icon: 'https://cdn.zwplayer.cn/logo.png', // Logo图片地址
|
|
688
|
+
dock: 'right', // 停靠位置(left/right/top/bottom)
|
|
689
|
+
x: '5%', // X轴偏移
|
|
690
|
+
y: '5%', // Y轴偏移
|
|
691
|
+
width: '10%', // Logo宽度
|
|
692
|
+
height: '10%', // Logo高度
|
|
693
|
+
opacity: 70 // 透明度(0-100)
|
|
694
|
+
}
|
|
695
|
+
```
|
|
155
696
|
|
|
156
697
|
### 事件
|
|
157
698
|
|
|
158
699
|
组件提供了 `onready`、`onmediaevent` 等事件,详细说明请参考 [zwplayer 事件文档](https://www.zwplayer.cn/docs/support/guide-events.html)。
|
|
159
700
|
|
|
701
|
+
**常用事件:**
|
|
702
|
+
|
|
703
|
+
| 事件名称 | 说明 | 回调参数 |
|
|
704
|
+
|---------|------|---------|
|
|
705
|
+
| onready | 播放器初始化完成事件 | - |
|
|
706
|
+
| onmediaevent | 媒体播放事件(播放、暂停、结束等) | event对象,包含type等属性 |
|
|
707
|
+
|
|
708
|
+
**使用示例:**
|
|
709
|
+
|
|
710
|
+
```javascript
|
|
711
|
+
methods: {
|
|
712
|
+
onPlayerReady() {
|
|
713
|
+
console.log('播放器已准备就绪')
|
|
714
|
+
// 可以在这里进行播放器初始化后的操作
|
|
715
|
+
const player = this.$refs.zwplayerRef
|
|
716
|
+
// 例如:添加字幕、设置章节等
|
|
717
|
+
},
|
|
718
|
+
onPlayerMediaEvent(event) {
|
|
719
|
+
console.log('媒体事件:', event.type)
|
|
720
|
+
// event.type 可能的值:play, pause, ended, timeupdate 等
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
```
|
|
724
|
+
|
|
160
725
|
### 方法调用
|
|
161
726
|
|
|
162
727
|
通过 `ref` 引用调用播放器方法:
|
|
163
728
|
|
|
729
|
+
**基础方法:**
|
|
730
|
+
|
|
164
731
|
```javascript
|
|
165
732
|
// 获取播放器实例
|
|
166
733
|
const player = this.$refs.zwplayerRef
|
|
167
734
|
|
|
168
|
-
//
|
|
169
|
-
player.play()
|
|
170
|
-
player.pause()
|
|
171
|
-
player.
|
|
735
|
+
// 播放控制
|
|
736
|
+
player.play() // 播放
|
|
737
|
+
player.pause() // 暂停
|
|
738
|
+
player.seekTime(120) // 跳转到指定秒数
|
|
739
|
+
player.stop() // 停止
|
|
740
|
+
|
|
172
741
|
```
|
|
173
742
|
|
|
174
|
-
|
|
743
|
+
**高级方法:**
|
|
744
|
+
|
|
745
|
+
```javascript
|
|
746
|
+
// 字幕相关
|
|
747
|
+
player.addSubtitle('/subtitles/zh.vtt', '1') // 添加字幕轨道
|
|
748
|
+
player.removeSubtitle('1') // 移除字幕轨道
|
|
749
|
+
|
|
750
|
+
// 弹幕相关
|
|
751
|
+
player.appendDanmu({
|
|
752
|
+
border: '1px solid #ccc',
|
|
753
|
+
text: '这是一条弹幕',
|
|
754
|
+
color: '#ff6b6b'
|
|
755
|
+
})
|
|
756
|
+
|
|
757
|
+
// 章节相关
|
|
758
|
+
player.setChapters([{
|
|
759
|
+
title: "章节1",
|
|
760
|
+
desc: "章节1描述",
|
|
761
|
+
time: 0,
|
|
762
|
+
duration: 50
|
|
763
|
+
}])
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
// 获取信息
|
|
767
|
+
player.getDuration() // 获取视频总时长
|
|
768
|
+
player.getCurrentTime() // 获取当前播放时间
|
|
769
|
+
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
### 完整示例
|
|
773
|
+
|
|
774
|
+
结合所有功能的完整组件示例:
|
|
775
|
+
|
|
776
|
+
```html
|
|
777
|
+
<template>
|
|
778
|
+
<div class="video-player">
|
|
779
|
+
<zwplayer
|
|
780
|
+
v-if="playerOpen"
|
|
781
|
+
ref="zwplayerRef"
|
|
782
|
+
nodeid="main-player"
|
|
783
|
+
:murl="movieUrl"
|
|
784
|
+
:poster="poster"
|
|
785
|
+
:logo="logo"
|
|
786
|
+
:thumbnails="thumbnails"
|
|
787
|
+
:autoplay="false"
|
|
788
|
+
:fluid="true"
|
|
789
|
+
:enableDanmu="true"
|
|
790
|
+
:snapshotButton="true"
|
|
791
|
+
:optionButton="true"
|
|
792
|
+
:infoButton="true"
|
|
793
|
+
:chapterButton="true"
|
|
794
|
+
:recordButton="true"
|
|
795
|
+
:localPlayback="true"
|
|
796
|
+
:sendDanmu="sendDanmu"
|
|
797
|
+
:disableMutedConfirm="true"
|
|
798
|
+
danmuBarId="danmu-controlbar"
|
|
799
|
+
@onready="onPlayerReady"
|
|
800
|
+
@onmediaevent="onPlayerMediaEvent"
|
|
801
|
+
/>
|
|
802
|
+
|
|
803
|
+
<div class="danmubar" id="danmu-controlbar"></div>
|
|
804
|
+
|
|
805
|
+
<div class="controls">
|
|
806
|
+
<button @click="play">播放</button>
|
|
807
|
+
<button @click="pause">暂停</button>
|
|
808
|
+
<button @click="snapshot">截图</button>
|
|
809
|
+
<button @click="addSubtitle">添加字幕</button>
|
|
810
|
+
</div>
|
|
811
|
+
</div>
|
|
812
|
+
</template>
|
|
813
|
+
|
|
814
|
+
<script>
|
|
815
|
+
import { zwplayer } from 'zwplayer-vue2x'
|
|
816
|
+
|
|
817
|
+
export default {
|
|
818
|
+
name: 'VideoPlayer',
|
|
819
|
+
components: {
|
|
820
|
+
zwplayer
|
|
821
|
+
},
|
|
822
|
+
data() {
|
|
823
|
+
return {
|
|
824
|
+
movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
|
|
825
|
+
poster: 'https://www.zwplayer.cn/zwplayer-preview.png',
|
|
826
|
+
playerOpen: true,
|
|
827
|
+
player: null,
|
|
828
|
+
logo: {
|
|
829
|
+
icon: 'https://cdn.zwplayer.cn/logo.png',
|
|
830
|
+
dock: 'right',
|
|
831
|
+
x: '5%',
|
|
832
|
+
y: '5%',
|
|
833
|
+
width: '10%',
|
|
834
|
+
height: '10%',
|
|
835
|
+
opacity: 70
|
|
836
|
+
},
|
|
837
|
+
thumbnails: {
|
|
838
|
+
url: 'https://cdn.zwplayer.cn/media/b44c43c90be3521bc352aad1e80f9cd0_thumb.jpg',
|
|
839
|
+
width: 160,
|
|
840
|
+
height: 90,
|
|
841
|
+
row: 9,
|
|
842
|
+
col: 9,
|
|
843
|
+
total: 74
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
methods: {
|
|
848
|
+
onPlayerReady() {
|
|
849
|
+
console.log('播放器已准备就绪')
|
|
850
|
+
this.player = this.$refs.zwplayerRef
|
|
851
|
+
},
|
|
852
|
+
onPlayerMediaEvent(event) {
|
|
853
|
+
console.log('媒体事件:', event.type)
|
|
854
|
+
},
|
|
855
|
+
play() {
|
|
856
|
+
this.player.play()
|
|
857
|
+
},
|
|
858
|
+
pause() {
|
|
859
|
+
this.player.pause()
|
|
860
|
+
},
|
|
861
|
+
snapshot() {
|
|
862
|
+
this.player.snapshot()
|
|
863
|
+
},
|
|
864
|
+
addSubtitle() {
|
|
865
|
+
this.player.addSubtitle('/subtitles/zh.vtt', '1')
|
|
866
|
+
},
|
|
867
|
+
sendDanmu(danmuText) {
|
|
868
|
+
if (!danmuText) return
|
|
869
|
+
this.player.appendDanmu({
|
|
870
|
+
border: '1px solid #ccc',
|
|
871
|
+
text: danmuText
|
|
872
|
+
})
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
</script>
|
|
877
|
+
|
|
878
|
+
<style scoped>
|
|
879
|
+
.video-player {
|
|
880
|
+
max-width: 1280px;
|
|
881
|
+
margin: 0 auto;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
.danmubar {
|
|
885
|
+
height: 50px;
|
|
886
|
+
background-color: #232323;
|
|
887
|
+
padding: 8px;
|
|
888
|
+
box-sizing: border-box;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
.controls {
|
|
892
|
+
margin-top: 20px;
|
|
893
|
+
text-align: center;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
.controls button {
|
|
897
|
+
margin: 0 10px;
|
|
898
|
+
padding: 8px 16px;
|
|
899
|
+
background-color: #409eff;
|
|
900
|
+
color: white;
|
|
901
|
+
border: none;
|
|
902
|
+
border-radius: 4px;
|
|
903
|
+
cursor: pointer;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
.controls button:hover {
|
|
907
|
+
background-color: #66b1ff;
|
|
908
|
+
}
|
|
909
|
+
</style>
|
|
910
|
+
```
|
|
175
911
|
|
|
176
|
-
- **Gitee**: https://gitee.com/chenfanyu/zwplayer-vue2x-demo
|
|
177
|
-
- **GitHub**: https://github.com/chenfanyu/zwplayer-vue2x-demo
|
|
178
912
|
|
|
179
913
|
## 其他版本
|
|
180
914
|
|
|
@@ -187,3 +921,31 @@ npm install zwplayervue3 --save
|
|
|
187
921
|
```
|
|
188
922
|
|
|
189
923
|
详细文档:[zwplayervue3](https://www.zwplayer.cn/guide-vue-framework.html)
|
|
924
|
+
|
|
925
|
+
## 相关资源
|
|
926
|
+
|
|
927
|
+
### 官方文档
|
|
928
|
+
- [ZWPlayer 官网](https://www.zwplayer.cn)
|
|
929
|
+
- [在线体验](https://www.zwplayer.cn/videoplayer.html)
|
|
930
|
+
- [Vue 框架集成指南](https://www.zwplayer.cn/docs/support/guide-vue-framework.html)
|
|
931
|
+
- [配置参数文档](https://www.zwplayer.cn/docs/support/guide-configuration.html)
|
|
932
|
+
- [API 方法文档](https://www.zwplayer.cn/docs/support/guide-api.html)
|
|
933
|
+
- [事件文档](https://www.zwplayer.cn/docs/support/guide-events.html)
|
|
934
|
+
|
|
935
|
+
### 示例项目
|
|
936
|
+
- [Vue 3 示例 (Gitee)](https://gitee.com/chenfanyu/zwplayervue3-demo)
|
|
937
|
+
- [Vue 3 示例 (GitHub)](https://github.com/chenfanyu/zwplayervue3-demo)
|
|
938
|
+
- [Vue 2 示例 (Gitee)](https://gitee.com/chenfanyu/zwplayer-vue2x-demo)
|
|
939
|
+
- [Vue 2 示例 (GitHub)](https://github.com/chenfanyu/zwplayer-vue2x-demo)
|
|
940
|
+
|
|
941
|
+
## 许可证
|
|
942
|
+
|
|
943
|
+
本组件遵循 MIT 许可证。ZWPlayer 核心库完全免费使用。
|
|
944
|
+
|
|
945
|
+
## 技术支持
|
|
946
|
+
|
|
947
|
+
如有问题或建议,请通过以下方式联系:
|
|
948
|
+
- 邮箱:893366640@qq.com
|
|
949
|
+
- QQ:893366640
|
|
950
|
+
- 微信:zwplayerX
|
|
951
|
+
- 公众号:zwplayer
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zwplayer-vue2x",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "A fully functional and lightweight free open-source web player",
|
|
5
5
|
"main": "lib/zwplayervue2.umd.min.js",
|
|
6
|
-
"
|
|
6
|
+
"keywords": [
|
|
7
|
+
"zwplayer",
|
|
8
|
+
"zwplayervue2",
|
|
9
|
+
"zwplayer-vue2x",
|
|
10
|
+
"zero-web-player",
|
|
11
|
+
"video-player",
|
|
12
|
+
"vue2",
|
|
13
|
+
"player"
|
|
14
|
+
],
|
|
7
15
|
"license": "MIT",
|
|
8
16
|
"private": false,
|
|
9
17
|
"scripts": {
|