zwplayer-vue2x 1.0.32 → 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 CHANGED
@@ -1,24 +1,951 @@
1
1
  # zwplayer-vue2x
2
2
 
3
- ## Project setup
3
+ 基于 Vue 2.x 的 zwplayer 组件封装,提供简单易用的视频播放能力。
4
+
5
+ ## 关于 zwplayer
6
+
7
+ `zwplayer`(Zero Web Player)是一款秉持"智能傻瓜式"设计理念的网页播放器,致力于将开发者的使用成本降至无限接近于零。
8
+
9
+ ### 核心特点
10
+
11
+ ✅ **零费用成本** - 完全免费,永久免费,无需支付任何费用
12
+
13
+ ✅ **零学习成本** - 提供统一简洁的 API,智能引擎自动处理所有流媒体技术细节
14
+
15
+ ✅ **零升级成本** - API 永久固化,版本升级仅需替换文件
16
+
17
+ ✅ **零风险成本** - 代码纯净,无广告、无统计、无联网后门
18
+
19
+ ✅ **零部署成本** - 不依赖第三方库和 CDN,私网、内网均可使用
20
+
21
+ ### 主要功能
22
+
23
+ - **广泛协议支持**:HLS、DASH、HTTP-FLV、HTTP-TS、WS、WebRTC(WHEP/ARTC/BRTC/TRTC)
24
+ - **特色协议**:支持 RTSP 网页播放(无需插件)
25
+ - **本地文件播放**:支持直接播放用户设备上的本地视频/音频文件
26
+ - **智能字幕**:支持双字幕、字幕搜索、章节搜索、拖拽加载本地字幕、章节文件
27
+ - **丰富功能**:弹幕、进度条预览、画面调节、截图、音量增益、AB循环、录制、音频提取等
28
+ - **直播优化**:超低延时直播、直播追帧、多码流切换
29
+ - **灵活模式**:画中画、网页全屏、自动小窗口、强制锁定模式
30
+
31
+ 更多详情请访问:
32
+ 1. [zwplayer 官网](https://www.zwplayer.cn)
33
+ 2. [在线体验](https://www.zwplayer.cn/videoplayer.html)
34
+ 3. [vue框架使用](https://www.zwplayer.cn/docs/support/guide-vue-framework.html)
35
+ 3. [vue框架使用](https://www.zwplayer.cn/docs/support/guide-vue-framework.html)
36
+ 4. 调用示例项目:
37
+ - **Gitee**: https://gitee.com/chenfanyu/zwplayer-vue2x-demo
38
+ - **GitHub**: https://github.com/chenfanyu/zwplayer-vue2x-demo
39
+
40
+
41
+ ## 使用说明
42
+
43
+ ### 安装
44
+
45
+ ```bash
46
+ npm install zwplayer-vue2x --save
4
47
  ```
5
- npm install
48
+
49
+ #### 安装注意事项
50
+
51
+ ⚠️ **重要**:本组件依赖 `zwplayer` 核心库,安装时请注意以下事项:
52
+
53
+ 1. **自动配置**:`npm install` 会自动执行 `postinstall` 脚本,该脚本会:
54
+ - 创建 `public` 目录(如果不存在)
55
+ - 将 `zwplayer` 核心库复制到 `public/zwplayer` 目录
56
+
57
+ 2. **核心库必须发布**:`public/zwplayer` 目录必须随项目一起发布到生产环境
58
+ - 确保该目录完整包含所有 zwplayer 相关文件
59
+ - 不要在部署时忽略此目录
60
+
61
+ 3. **动态加载机制**:zwplayer 采用动态加载机制
62
+ - 支持无缝升级,无需修改业务代码
63
+ - 升级时只需替换 `public/zwplayer` 目录中的文件即可
64
+
65
+ 4. **内网/私网部署**:zwplayer 不依赖 CDN,完全支持内网和离线环境部署
66
+ ### 组件注册
67
+
68
+ #### 全局注册
69
+
70
+ 在 `src/main.js` 中添加:
71
+
72
+ ```javascript
73
+ import Vue from 'vue'
74
+ import App from './App.vue'
75
+ import ZwModule from 'zwplayer-vue2x'
76
+
77
+ Vue.use(ZwModule)
78
+
79
+ new Vue({
80
+ render: h => h(App),
81
+ }).$mount('#app')
6
82
  ```
7
83
 
8
- ### Compiles and hot-reloads for development
84
+ 全局注册后,可在项目任何组件中使用 `<zwplayer>` 组件。
85
+
86
+ #### 局部注册
87
+
88
+ 在组件中单独注册:
89
+
90
+ ```javascript
91
+ import { zwplayer } from 'zwplayer-vue2x'
92
+
93
+ export default {
94
+ name: 'MyComponent',
95
+ components: {
96
+ zwplayer
97
+ },
98
+ data() {
99
+ return {
100
+ movieUrl: 'https://d2zihajmogu5jn.cloudfront.net/elephantsdream/ed_hd.mp4',
101
+ playerOpen: true
102
+ }
103
+ },
104
+ methods: {
105
+ onPlayerReady() {
106
+ console.log('player ready event.')
107
+ },
108
+ onPlayerMediaEvent(event) {
109
+ console.log('media event:', event.type)
110
+ },
111
+ sendDanmu(danmu) {
112
+ console.log('sendDanmu:', danmu)
113
+ // 调用websocket等方法将弹幕实际发送出去
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ ### 组件使用
120
+
121
+ 在模板中使用组件:
122
+
123
+ ```html
124
+ <template>
125
+ <div class="player-container">
126
+ <zwplayer
127
+ v-if="playerOpen"
128
+ ref="zwplayerRef"
129
+ nodeid="main-player"
130
+ :murl="movieUrl"
131
+ @onready="onPlayerReady"
132
+ @onmediaevent="onPlayerMediaEvent"
133
+ :snapshotButton="true"
134
+ :optionButton="true"
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>
9
145
  ```
10
- npm run serve
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>
11
203
  ```
12
204
 
13
- ### Compiles and minifies for production
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"
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>
14
292
  ```
15
- npm run build
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>
16
347
  ```
17
348
 
18
- ### Lints and fixes files
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>
19
405
  ```
20
- npm run lint
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>
21
487
  ```
22
488
 
23
- ### Customize configuration
24
- See [Configuration Reference](https://cli.vuejs.org/config/).
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"
553
+ :infoButton="true"
554
+ :enableDanmu="true"
555
+ :chapterButton="true"
556
+ :fluid="true"
557
+ :autoplay="false"
558
+ :disableMutedConfirm="true"
559
+ />
560
+ </div>
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>
646
+ ```
647
+
648
+ ### 主要属性说明
649
+
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
+ ```
696
+
697
+ ### 事件
698
+
699
+ 组件提供了 `onready`、`onmediaevent` 等事件,详细说明请参考 [zwplayer 事件文档](https://www.zwplayer.cn/docs/support/guide-events.html)。
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
+
725
+ ### 方法调用
726
+
727
+ 通过 `ref` 引用调用播放器方法:
728
+
729
+ **基础方法:**
730
+
731
+ ```javascript
732
+ // 获取播放器实例
733
+ const player = this.$refs.zwplayerRef
734
+
735
+ // 播放控制
736
+ player.play() // 播放
737
+ player.pause() // 暂停
738
+ player.seekTime(120) // 跳转到指定秒数
739
+ player.stop() // 停止
740
+
741
+ ```
742
+
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
+ ```
911
+
912
+
913
+ ## 其他版本
914
+
915
+ ### Vue 3.x
916
+
917
+ 如果你使用 Vue 3.x,请安装 `zwplayervue3`:
918
+
919
+ ```bash
920
+ npm install zwplayervue3 --save
921
+ ```
922
+
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