zwplayer-vue2x 1.0.35 → 1.1.0

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,73 +1,99 @@
1
1
  # zwplayer-vue2x
2
2
 
3
- 基于 Vue 2.x zwplayer 组件封装,提供简单易用的视频播放能力。
3
+ Vue 2.x wrapper component for zwplayer, providing easy-to-use video playback capabilities.
4
4
 
5
- ## 关于 zwplayer
5
+ **[English](#english) | [中文](#中文)**
6
6
 
7
- `zwplayer`(Zero Web Player)是一款秉持"智能傻瓜式"设计理念的网页播放器,致力于将开发者的使用成本降至无限接近于零。
7
+ ---
8
8
 
9
- ### 核心特点
9
+ <a id="english"></a>
10
10
 
11
- **零费用成本** - 完全免费,永久免费,无需支付任何费用
11
+ Vue 2.x wrapper component for zwplayer, providing easy-to-use video playback capabilities.
12
12
 
13
- **零学习成本** - 提供统一简洁的 API,智能引擎自动处理所有流媒体技术细节
13
+ ## About zwplayer
14
14
 
15
- **零升级成本** - API 永久固化,版本升级仅需替换文件
15
+ `zwplayer` (Zero Web Player) is a web video player built on the "zero-effort" design philosophy, dedicated to reducing the developer's integration cost to as close to zero as possible.
16
16
 
17
- **零风险成本** - 代码纯净,无广告、无统计、无联网后门
17
+ ### Core Principles
18
18
 
19
- **零部署成本** - 不依赖第三方库和 CDN,私网、内网均可使用
19
+ - **Zero Cost** - Completely free, forever free, no payment required
20
+ - **Zero Learning Curve** - Provides a clean, unified API; the smart engine handles all streaming technical details automatically
21
+ - **Zero Upgrade Cost** - The API is permanently stabilized; upgrading only requires replacing a single file
22
+ - **Zero Risk** - Clean codebase with no ads, no analytics, no network backdoors
23
+ - **Zero Deployment Cost** - No dependency on third-party libraries or CDNs; works on private networks and intranets
20
24
 
21
- ### 主要功能
25
+ ### Key Features
22
26
 
23
- - **广泛协议支持**:HLSDASHHTTP-FLVHTTP-TS、WS、WebRTCWHEP/ARTC/BRTC/TRTC
24
- - **特色协议**:支持 RTSP 网页播放(无需插件)
25
- - **本地文件播放**:支持直接播放用户设备上的本地视频/音频文件
26
- - **智能字幕**:支持双字幕、字幕搜索、章节搜索、拖拽加载本地字幕、章节文件
27
- - **丰富功能**:弹幕、进度条预览、画面调节、截图、音量增益、AB循环、录制、音频提取等
28
- - **直播优化**:超低延时直播、直播追帧、多码流切换
29
- - **灵活模式**:画中画、网页全屏、自动小窗口、强制锁定模式
27
+ - **Broad Protocol Support**: HLS, DASH, HTTP-FLV, HTTP-TS, WebSocket, WebRTC (WHEP/ARTC/BRTC/TRTC)
28
+ - **Unique Protocol**: RTSP web playback support (no browser plugin required)
29
+ - **Local File Playback**: Play video/audio files directly from the user's device
30
+ - **Smart Subtitles**: Dual subtitles, subtitle search, subtitle translation, chapter search, drag-and-drop loading of local subtitle/chapter files
31
+ - **Rich Functionality**: Danmaku (bullet comments), progress bar preview, image adjustment, screenshots, volume boost, A-B loop, recording, audio extraction, and more
32
+ - **Live Streaming Optimization**: Ultra-low latency streaming, live catch-up, multi-bitrate switching
33
+ - **Flexible Modes**: Picture-in-Picture, browser fullscreen, auto mini-window, forced lock mode
30
34
 
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. 调用示例项目:
35
+ ### What's New in v3.3.0
36
+
37
+ - **Casting**: Cast to external devices via the browser Presentation API / AirPlay
38
+ - **Watermarks**: Multiple watermarks, image watermarks, text watermarks, animated roaming watermarks; backward-compatible with the legacy `logo` configuration
39
+ - **Playlists**: XML-format playlists, multi-episode group management, auto-play next episode
40
+ - **Interactive Video Annotations (Hotspots)**: Visual drag-and-drop design of interactive video hotspots, supporting form, quiz, vote, and other interactive nodes
41
+ - **Frame-by-Frame Stepping**: Precise frame-by-frame playback control via keyboard arrow keys
42
+ - **Subtitle Translation**: Configurable translation API with a real-time subtitle translation panel
43
+ - **Volume Boost**: Volume gain beyond 100% via the Web Audio API
44
+ - **Time Format**: Display time in seconds or milliseconds
45
+ - **Magnifier**: Fully rewritten magnifier feature
46
+
47
+ ### Online Tools
48
+
49
+ ZWPlayer provides **8 free online tools** — no registration required, ready to use:
50
+
51
+ | # | Tool | Description | Link |
52
+ |---|------|-------------|------|
53
+ | 1 | **Online Player** | Universal protocol player for live testing and local file preview, supporting WebRTC/RTSP/HLS/DASH/FLV and all other protocols | [videoplayer](https://www.zwplayer.com/zh/tools/videoplayer/) |
54
+ | 2 | **Code Generator** | Visually configure player UI skins, autoplay policies, subtitle attachment, and video hotspots; one-click export of integration code | [generator](https://www.zwplayer.com/zh/tools/generator/) |
55
+ | 3 | **Annotation Editor** | Visual drag-and-drop design of interactive video hotspots, supporting form, quiz, vote, and other interactive nodes | [annotation](https://www.zwplayer.com/zh/tools/annotation/) |
56
+ | 4 | **Subtitle Editor** | Create, translate, and export subtitles in SRT, VTT, BCC, JSON, and other formats online | [subtitle](https://www.zwplayer.com/zh/tools/subtitle/) |
57
+ | 5 | **Chapter Editor** | Visually create and export video chapter marker data | [chapter](https://www.zwplayer.com/zh/tools/chapter/) |
58
+ | 6 | **Thumbnail Generator** | Quickly generate video sprite sheets and ZWMAP JSON configuration | [thumbnail](https://www.zwplayer.com/zh/tools/thumbnail/) |
59
+ | 7 | **Playlist Editor** | Visually manage and export playlist data, with group and auto-play support | [playlist](https://www.zwplayer.com/zh/tools/playlist/) |
60
+ | 8 | **Watermark Editor** | Visually configure image watermarks, text watermarks, animated roaming watermarks, and tiled watermarks | [watermark](https://www.zwplayer.com/zh/tools/watermark/) |
61
+
62
+ For more details, please visit:
63
+ 1. [zwplayer Official Website](https://www.zwplayer.cn)
64
+ 2. [Online Demo](https://www.zwplayer.cn/videoplayer.html)
65
+ 3. [Vue Framework Integration Guide](https://www.zwplayer.cn/docs/support/guide-vue-framework.html)
66
+ 4. Example projects:
37
67
  - **Gitee**: https://gitee.com/chenfanyu/zwplayer-vue2x-demo
38
68
  - **GitHub**: https://github.com/chenfanyu/zwplayer-vue2x-demo
39
-
40
69
 
41
- ## 使用说明
70
+ ## Getting Started
42
71
 
43
- ### 安装
72
+ ### Installation
44
73
 
45
74
  ```bash
46
75
  npm install zwplayer-vue2x --save
47
76
  ```
48
77
 
49
- #### 安装注意事项
78
+ #### Installation Notes
50
79
 
51
- ⚠️ **重要**:本组件依赖 `zwplayer` 核心库,安装时请注意以下事项:
80
+ **Important**: This component depends on the `zwplayer` core library. Please note the following during installation:
52
81
 
53
- 1. **自动配置**:`npm install` 会自动执行 `postinstall` 脚本,该脚本会:
54
- - 创建 `public` 目录(如果不存在)
55
- - `zwplayer` 核心库复制到 `public/zwplayer` 目录
82
+ 1. **Automatic Configuration**: `npm install` will automatically run the `postinstall` script, which will:
83
+ - Create the `public` directory (if it does not exist)
84
+ - Copy the `zwplayer` core library to the `public/zwplayer` directory
56
85
 
57
- 2. **核心库必须发布**:`public/zwplayer` 目录必须随项目一起发布到生产环境
58
- - 确保该目录完整包含所有 zwplayer 相关文件
59
- - 不要在部署时忽略此目录
86
+ 2. **Core Library Must Be Deployed**: The `public/zwplayer` directory must be deployed along with your project to production
60
87
 
61
- 3. **动态加载机制**:zwplayer 采用动态加载机制
62
- - 支持无缝升级,无需修改业务代码
63
- - 升级时只需替换 `public/zwplayer` 目录中的文件即可
88
+ 3. **Dynamic Loading Mechanism**: zwplayer uses a dynamic loading mechanism, supporting seamless upgrades without modifying your application code
64
89
 
65
- 4. **内网/私网部署**:zwplayer 不依赖 CDN,完全支持内网和离线环境部署
66
- ### 组件注册
90
+ 4. **Intranet / Offline Deployment**: zwplayer does not depend on CDNs and fully supports intranet and offline environments
67
91
 
68
- #### 全局注册
92
+ ### Component Registration
69
93
 
70
- `src/main.js` 中添加:
94
+ #### Global Registration
95
+
96
+ Add in `src/main.js`:
71
97
 
72
98
  ```javascript
73
99
  import Vue from 'vue'
@@ -81,11 +107,11 @@ new Vue({
81
107
  }).$mount('#app')
82
108
  ```
83
109
 
84
- 全局注册后,可在项目任何组件中使用 `<zwplayer>` 组件。
110
+ After global registration, you can use the `<zwplayer>` component anywhere in your project.
85
111
 
86
- #### 局部注册
112
+ #### Local Registration
87
113
 
88
- 在组件中单独注册:
114
+ Register in a single component:
89
115
 
90
116
  ```javascript
91
117
  import { zwplayer } from 'zwplayer-vue2x'
@@ -110,15 +136,12 @@ export default {
110
136
  },
111
137
  sendDanmu(danmu) {
112
138
  console.log('sendDanmu:', danmu)
113
- // 调用websocket等方法将弹幕实际发送出去
114
139
  }
115
140
  }
116
141
  }
117
142
  ```
118
143
 
119
- ### 组件使用
120
-
121
- 在模板中使用组件:
144
+ ### Component Usage
122
145
 
123
146
  ```html
124
147
  <template>
@@ -144,87 +167,158 @@ export default {
144
167
  </template>
145
168
  ```
146
169
 
147
- ### 使用示例
170
+ ### Main Properties
171
+
172
+ | Property | Type | Description | Default |
173
+ |---------|------|-------------|---------|
174
+ | murl | String/Object/Array | Media URL parameter, supports dynamic switching | - |
175
+ | fluid | Boolean | Enable fluid layout (adaptive to container width) | false |
176
+ | autoplay | Boolean | Auto-play on load | false |
177
+ | disableMutedConfirm | Boolean | Disable muted playback confirmation | false |
178
+ | enableDanmu | Boolean | Enable danmaku (bullet comments) | false |
179
+ | snapshotButton | Boolean | Show screenshot button | false |
180
+ | optionButton | Boolean | Show settings button | false |
181
+ | infoButton | Boolean | Show info button | false |
182
+ | chapterButton | Boolean | Show chapter button | false |
183
+ | recordButton | Boolean | Show record button | false |
184
+ | segmentButton | Boolean | Show segment button | false |
185
+ | localPlayback | Boolean | Enable local file playback | false |
186
+ | sendDanmu | Function | Callback function for sending danmaku | - |
187
+ | thumbnails | Object | Thumbnail configuration object | - |
188
+ | logo | Object | Logo watermark configuration object | - |
189
+ | poster | String | Video poster image URL | - |
190
+ | timeFormat | String | Time format: `'s'` = seconds, `'ms'` = milliseconds | `'s'` |
191
+ | castButton | Boolean | Show cast button | false |
192
+ | zoomButton | Boolean | Show magnifier button | false |
193
+ | annotationButton | Boolean | Show annotation/hotspot button | false |
194
+ | annotation | Object | Annotation/hotspot configuration data | - |
195
+ | annotations | Object | Annotation/hotspot configuration data (alias for annotation) | - |
196
+ | watermark | Array | Watermark configuration array | - |
197
+ | watermarks | Array | Watermark configuration array (alias for watermark) | - |
198
+ | translateApi | String | Translation API endpoint | - |
199
+ | defVolume | Number | Default volume percentage (0-100) | 61.25 |
200
+ | hideControlbarTimeout | Number | Control bar auto-hide timeout (milliseconds) | 10000 |
201
+ | Others | - | See [zwplayer constructor parameters](https://www.zwplayer.cn/docs/support/guide-configuration.html) | - |
202
+
203
+ **Thumbnail configuration example:**
148
204
 
149
- #### 1. 基础使用
205
+ ```javascript
206
+ thumbnails: {
207
+ url: 'https://cdn.zwplayer.cn/media/b44c43c90be3521bc352aad1e80f9cd0_thumb.jpg',
208
+ width: 160, // width of each thumbnail
209
+ height: 90, // height of each thumbnail
210
+ row: 9, // total rows
211
+ col: 9, // total columns
212
+ total: 74 // total number of thumbnails
213
+ }
214
+ ```
150
215
 
151
- 最简单的播放器配置,展示基本功能:
216
+ **Logo watermark configuration example:**
152
217
 
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>
218
+ ```javascript
219
+ logo: {
220
+ icon: 'https://cdn.zwplayer.cn/logo.png', // logo image URL
221
+ dock: 'right', // dock position (left/right/top/bottom)
222
+ x: '5%', // X offset
223
+ y: '5%', // Y offset
224
+ width: '10%', // logo width
225
+ height: '10%', // logo height
226
+ opacity: 70 // opacity (0-100)
227
+ }
228
+ ```
178
229
 
179
- <script>
180
- import { zwplayer } from 'zwplayer-vue2x'
230
+ ### Events
181
231
 
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
- }
232
+ | Event Name | Description | Callback Parameters |
233
+ |-----------|-------------|---------------------|
234
+ | onready | Player initialization complete event | - |
235
+ | onmediaevent | Media playback event (play, pause, ended, etc.) | event object, containing `type` and other properties |
236
+
237
+ ```javascript
238
+ methods: {
239
+ onPlayerReady() {
240
+ console.log('Player is ready')
241
+ const player = this.$refs.zwplayerRef
192
242
  },
193
- methods: {
194
- onPlayerReady() {
195
- console.log('播放器已准备就绪')
196
- },
197
- onPlayerMediaEvent(event) {
198
- console.log('媒体事件:', event.type)
199
- }
243
+ onPlayerMediaEvent(event) {
244
+ console.log('Media event:', event.type)
245
+ // event.type: play, pause, ended, timeupdate, etc.
200
246
  }
201
247
  }
202
- </script>
203
248
  ```
204
249
 
205
- #### 2. 弹幕功能
250
+ ### Method Calls
251
+
252
+ ```javascript
253
+ const player = this.$refs.zwplayerRef
254
+
255
+ // Basic playback control
256
+ player.play() // play
257
+ player.pause() // pause
258
+ player.seekTime(120) // seek to 120 seconds
259
+ player.stop() // stop
260
+
261
+ // Subtitles
262
+ player.addSubtitle('/subtitles/zh.vtt', '1') // add subtitle track
263
+ player.removeSubtitle('1') // remove subtitle track
264
+
265
+ // Danmaku
266
+ player.appendDanmu({
267
+ border: '1px solid #ccc',
268
+ text: 'Hello!',
269
+ color: '#ff6b6b'
270
+ })
271
+
272
+ // Chapters
273
+ player.setChapters([{
274
+ title: "Chapter 1",
275
+ desc: "Chapter 1 description",
276
+ time: 0,
277
+ duration: 50
278
+ }])
279
+
280
+ // Info
281
+ player.getDuration() // get total duration
282
+ player.getCurrentTime() // get current playback time
283
+ ```
206
284
 
207
- 展示播放器弹幕功能,支持实时弹幕发送和接收:
285
+ ### Complete Example
208
286
 
209
287
  ```html
210
288
  <template>
211
- <div class="demo">
289
+ <div class="video-player">
212
290
  <zwplayer
213
291
  v-if="playerOpen"
214
292
  ref="zwplayerRef"
293
+ nodeid="main-player"
215
294
  :murl="movieUrl"
216
- @onready="onPlayerReady"
217
- @onmediaevent="onPlayerMediaEvent"
295
+ :poster="poster"
296
+ :logo="logo"
297
+ :thumbnails="thumbnails"
218
298
  :autoplay="false"
219
- :sendDanmu="sendDanmu"
220
- :enableDanmu="true"
221
299
  :fluid="true"
300
+ :enableDanmu="true"
301
+ :snapshotButton="true"
302
+ :optionButton="true"
303
+ :infoButton="true"
304
+ :chapterButton="true"
305
+ :recordButton="true"
306
+ :localPlayback="true"
307
+ :sendDanmu="sendDanmu"
222
308
  :disableMutedConfirm="true"
223
309
  danmuBarId="danmu-controlbar"
310
+ @onready="onPlayerReady"
311
+ @onmediaevent="onPlayerMediaEvent"
224
312
  />
225
313
 
226
- <!-- 弹幕控制条 -->
227
314
  <div class="danmubar" id="danmu-controlbar"></div>
315
+
316
+ <div class="controls">
317
+ <button @click="play">Play</button>
318
+ <button @click="pause">Pause</button>
319
+ <button @click="snapshot">Screenshot</button>
320
+ <button @click="addSubtitle">Add Subtitle</button>
321
+ </div>
228
322
  </div>
229
323
  </template>
230
324
 
@@ -232,315 +326,289 @@ export default {
232
326
  import { zwplayer } from 'zwplayer-vue2x'
233
327
 
234
328
  export default {
235
- name: 'DanmuDemo',
329
+ name: 'VideoPlayer',
236
330
  components: {
237
331
  zwplayer
238
332
  },
239
333
  data() {
240
334
  return {
241
335
  movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
336
+ poster: 'https://www.zwplayer.cn/zwplayer-preview.png',
242
337
  playerOpen: true,
243
- player: null
338
+ player: null,
339
+ logo: {
340
+ icon: 'https://cdn.zwplayer.cn/logo.png',
341
+ dock: 'right',
342
+ x: '5%',
343
+ y: '5%',
344
+ width: '10%',
345
+ height: '10%',
346
+ opacity: 70
347
+ },
348
+ thumbnails: {
349
+ url: 'https://cdn.zwplayer.cn/media/b44c43c90be3521bc352aad1e80f9cd0_thumb.jpg',
350
+ width: 160,
351
+ height: 90,
352
+ row: 9,
353
+ col: 9,
354
+ total: 74
355
+ }
244
356
  }
245
357
  },
246
358
  methods: {
247
359
  onPlayerReady() {
360
+ console.log('Player is ready')
248
361
  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
362
  },
262
363
  onPlayerMediaEvent(event) {
263
- console.log('媒体事件:', event.type)
364
+ console.log('Media event:', event.type)
365
+ },
366
+ play() {
367
+ this.player.play()
368
+ },
369
+ pause() {
370
+ this.player.pause()
371
+ },
372
+ snapshot() {
373
+ this.player.snapshot()
374
+ },
375
+ addSubtitle() {
376
+ this.player.addSubtitle('/subtitles/zh.vtt', '1')
264
377
  },
265
378
  sendDanmu(danmuText) {
266
- console.log('发送弹幕:', danmuText)
267
-
268
379
  if (!danmuText) return
269
-
270
- const danmu = {
380
+ this.player.appendDanmu({
271
381
  border: '1px solid #ccc',
272
382
  text: danmuText
273
- }
274
-
275
- // 将弹幕添加到播放器
276
- if (this.player && this.player.appendDanmu) {
277
- this.player.appendDanmu(danmu)
278
- }
383
+ })
279
384
  }
280
385
  }
281
386
  }
282
387
  </script>
283
388
 
284
389
  <style scoped>
390
+ .video-player {
391
+ max-width: 1280px;
392
+ margin: 0 auto;
393
+ }
394
+
285
395
  .danmubar {
286
396
  height: 50px;
287
397
  background-color: #232323;
288
398
  padding: 8px;
289
399
  box-sizing: border-box;
290
400
  }
401
+
402
+ .controls {
403
+ margin-top: 20px;
404
+ text-align: center;
405
+ }
406
+
407
+ .controls button {
408
+ margin: 0 10px;
409
+ padding: 8px 16px;
410
+ background-color: #409eff;
411
+ color: white;
412
+ border: none;
413
+ border-radius: 4px;
414
+ cursor: pointer;
415
+ }
416
+
417
+ .controls button:hover {
418
+ background-color: #66b1ff;
419
+ }
291
420
  </style>
292
421
  ```
293
422
 
294
- #### 3. 字幕功能
423
+ ## Other Versions
295
424
 
296
- 展示播放器字幕功能,支持多语言字幕切换:
425
+ ### Vue 3.x
297
426
 
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>
427
+ ```bash
428
+ npm install zwplayervue3 --save
429
+ ```
314
430
 
315
- <script>
316
- import { zwplayer } from 'zwplayer-vue2x'
431
+ Documentation: [zwplayervue3](https://www.zwplayer.cn/guide-vue-framework.html)
317
432
 
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
- ```
433
+ ## Related Resources
348
434
 
349
- #### 4. 缩略图预览
435
+ ### Official Documentation
436
+ - [ZWPlayer Official Website](https://www.zwplayer.cn)
437
+ - [Online Demo](https://www.zwplayer.cn/videoplayer.html)
438
+ - [Vue Framework Integration Guide](https://www.zwplayer.cn/docs/support/guide-vue-framework.html)
439
+ - [Configuration Parameters](https://www.zwplayer.cn/docs/support/guide-configuration.html)
440
+ - [API Methods](https://www.zwplayer.cn/docs/support/guide-api.html)
441
+ - [Events](https://www.zwplayer.cn/docs/support/guide-events.html)
350
442
 
351
- 在进度条上显示视频帧预览:
443
+ ### Example Projects
444
+ - [Vue 3 Example (Gitee)](https://gitee.com/chenfanyu/zwplayervue3-demo)
445
+ - [Vue 3 Example (GitHub)](https://github.com/chenfanyu/zwplayervue3-demo)
446
+ - [Vue 2 Example (Gitee)](https://gitee.com/chenfanyu/zwplayer-vue2x-demo)
447
+ - [Vue 2 Example (GitHub)](https://github.com/chenfanyu/zwplayer-vue2x-demo)
352
448
 
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>
449
+ ## License
372
450
 
373
- <script>
374
- import { zwplayer } from 'zwplayer-vue2x'
451
+ MIT License. ZWPlayer core library is completely free to use.
375
452
 
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>
453
+ ## Technical Support
454
+
455
+ - Email: 893366640@qq.com
456
+ - QQ: 893366640
457
+ - WeChat: zwplayerX
458
+ - Official Account: zwplayer
459
+
460
+ ---
461
+
462
+ <a id="中文"></a>
463
+
464
+ 基于 Vue 2.x 的 zwplayer 组件封装,提供简单易用的视频播放能力。
465
+
466
+ ## 关于 zwplayer
467
+
468
+ `zwplayer`(Zero Web Player)是一款秉持"智能傻瓜式"设计理念的网页播放器,致力于将开发者的使用成本降至无限接近于零。
469
+
470
+ ### 核心特点
471
+
472
+ **零费用成本** - 完全免费,永久免费,无需支付任何费用
473
+
474
+ ✅ **零学习成本** - 提供统一简洁的 API,智能引擎自动处理所有流媒体技术细节
475
+
476
+ **零升级成本** - API 永久固化,版本升级仅需替换文件
477
+
478
+ ✅ **零风险成本** - 代码纯净,无广告、无统计、无联网后门
479
+
480
+ ✅ **零部署成本** - 不依赖第三方库和 CDN,私网、内网均可使用
481
+
482
+ ### 主要功能
483
+
484
+ - **广泛协议支持**:HLS、DASH、HTTP-FLV、HTTP-TS、WS、WebRTC(WHEP/ARTC/BRTC/TRTC)
485
+ - **特色协议**:支持 RTSP 网页播放(无需插件)
486
+ - **本地文件播放**:支持直接播放用户设备上的本地视频/音频文件
487
+ - **智能字幕**:支持双字幕、字幕搜索、字幕翻译、章节搜索、拖拽加载本地字幕/章节文件
488
+ - **丰富功能**:弹幕、进度条预览、画面调节、截图、音量增益、AB循环、录制、音频提取等
489
+ - **直播优化**:超低延时直播、直播追帧、多码流切换
490
+ - **灵活模式**:画中画、网页全屏、自动小窗口、强制锁定模式
491
+
492
+ ### v3.3.0 新增功能
493
+
494
+ - **投屏**:支持通过浏览器 Presentation API / AirPlay 投射到外部设备
495
+ - **水印**:支持多水印、图片水印、文字水印、动态游走水印,兼容旧版 `logo` 配置
496
+ - **播放列表**:支持 XML 格式播放列表,多集分组管理,自动播放下一集
497
+ - **视频交互热区(标注)**:可视化拖拽设计视频交互热区,支持表单、测验、投票等交互节点
498
+ - **逐帧步进**:通过键盘方向键逐帧精确控制播放
499
+ - **字幕翻译**:可设置翻译 API,支持实时字幕翻译面板
500
+ - **音量增强**:通过 Web Audio API 实现超过 100% 的音量增益
501
+ - **时间格式**:支持秒和毫秒两种时间显示格式
502
+ - **放大镜**:全新重写的放大镜功能
503
+
504
+ ### 在线工具
505
+
506
+ ZWPlayer 提供 **8 个免费在线工具**,无需注册,即开即用:
507
+
508
+ | # | 工具 | 说明 | 链接 |
509
+ |---|------|------|------|
510
+ | 1 | **在线播放器** | 全协议在线试播与本地文件预览,支持 WebRTC/RTSP/HLS/DASH/FLV 等所有协议 | [videoplayer](https://www.zwplayer.com/zh/tools/videoplayer/) |
511
+ | 2 | **代码生成器** | 可视化配置播放器 UI 皮肤、自动播放策略、字幕挂载与视频热区,一键导出集成代码 | [generator](https://www.zwplayer.com/zh/tools/generator/) |
512
+ | 3 | **交互标注编辑器** | 可视化拖拽设计视频交互热区,支持表单、测验、投票等交互节点 | [annotation](https://www.zwplayer.com/zh/tools/annotation/) |
513
+ | 4 | **字幕编辑器** | 在线创建、翻译和导出 SRT、VTT、BCC、JSON 等格式字幕 | [subtitle](https://www.zwplayer.com/zh/tools/subtitle/) |
514
+ | 5 | **章节编辑器** | 可视化创建和导出视频章节标记数据 | [chapter](https://www.zwplayer.com/zh/tools/chapter/) |
515
+ | 6 | **缩略图生成器** | 快速生成视频雪碧图(Sprite Sheet)和 ZWMAP JSON 配置 | [thumbnail](https://www.zwplayer.com/zh/tools/thumbnail/) |
516
+ | 7 | **播放列表编辑器** | 可视化管理和导出播放列表数据,支持分组和自动播放 | [playlist](https://www.zwplayer.com/zh/tools/playlist/) |
517
+ | 8 | **水印编辑器** | 可视化配置图片水印、文字水印、动态游走水印和铺满水印 | [watermark](https://www.zwplayer.com/zh/tools/watermark/) |
518
+
519
+ 更多详情请访问:
520
+ 1. [zwplayer 官网](https://www.zwplayer.cn)
521
+ 2. [在线体验](https://www.zwplayer.cn/videoplayer.html)
522
+ 3. [Vue 框架使用](https://www.zwplayer.cn/docs/support/guide-vue-framework.html)
523
+ 4. 调用示例项目:
524
+ - **Gitee**: https://gitee.com/chenfanyu/zwplayer-vue2x-demo
525
+ - **GitHub**: https://github.com/chenfanyu/zwplayer-vue2x-demo
526
+
527
+ ## 使用说明
528
+
529
+ ### 安装
530
+
531
+ ```bash
532
+ npm install zwplayer-vue2x --save
405
533
  ```
406
534
 
407
- #### 5. 章节分段
535
+ #### 安装注意事项
408
536
 
409
- 展示播放器章节分段功能:
537
+ ⚠️ **重要**:本组件依赖 `zwplayer` 核心库,安装时请注意以下事项:
410
538
 
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>
539
+ 1. **自动配置**:`npm install` 会自动执行 `postinstall` 脚本,该脚本会:
540
+ - 创建 `public` 目录(如果不存在)
541
+ - 将 `zwplayer` 核心库复制到 `public/zwplayer` 目录
428
542
 
429
- <script>
430
- import { zwplayer } from 'zwplayer-vue2x'
543
+ 2. **核心库必须发布**:`public/zwplayer` 目录必须随项目一起发布到生产环境
544
+ - 确保该目录完整包含所有 zwplayer 相关文件
545
+ - 不要在部署时忽略此目录
431
546
 
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>
547
+ 3. **动态加载机制**:zwplayer 采用动态加载机制
548
+ - 支持无缝升级,无需修改业务代码
549
+ - 升级时只需替换 `public/zwplayer` 目录中的文件即可
550
+
551
+ 4. **内网/私网部署**:zwplayer 不依赖 CDN,完全支持内网和离线环境部署
552
+
553
+ ### 组件注册
554
+
555
+ #### 全局注册
556
+
557
+ 在 `src/main.js` 中添加:
558
+
559
+ ```javascript
560
+ import Vue from 'vue'
561
+ import App from './App.vue'
562
+ import ZwModule from 'zwplayer-vue2x'
563
+
564
+ Vue.use(ZwModule)
565
+
566
+ new Vue({
567
+ render: h => h(App),
568
+ }).$mount('#app')
487
569
  ```
488
570
 
489
- #### 6. 截图功能
571
+ 全局注册后,可在项目任何组件中使用 `<zwplayer>` 组件。
490
572
 
491
- 展示播放器截图功能,支持一键截取当前播放画面:
573
+ #### 局部注册
492
574
 
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>
575
+ 在组件中单独注册:
510
576
 
511
- <script>
577
+ ```javascript
512
578
  import { zwplayer } from 'zwplayer-vue2x'
513
579
 
514
580
  export default {
515
- name: 'ScreenshotDemo',
581
+ name: 'MyComponent',
516
582
  components: {
517
583
  zwplayer
518
584
  },
519
585
  data() {
520
586
  return {
521
- movieUrl: 'https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4',
587
+ movieUrl: 'https://d2zihajmogu5jn.cloudfront.net/elephantsdream/ed_hd.mp4',
522
588
  playerOpen: true
523
589
  }
524
590
  },
525
591
  methods: {
526
592
  onPlayerReady() {
527
- console.log('播放器已准备就绪')
593
+ console.log('player ready event.')
528
594
  },
529
595
  onPlayerMediaEvent(event) {
530
- console.log('媒体事件:', event.type)
596
+ console.log('media event:', event.type)
597
+ },
598
+ sendDanmu(danmu) {
599
+ console.log('sendDanmu:', danmu)
531
600
  }
532
601
  }
533
602
  }
534
- </script>
535
603
  ```
536
604
 
537
- #### 7. 流式播放
605
+ ### 组件使用
538
606
 
539
- 展示播放器的流式布局功能,播放器会自适应容器宽度:
607
+ 在模板中使用组件:
540
608
 
541
609
  ```html
542
610
  <template>
543
- <div class="demo">
611
+ <div class="player-container">
544
612
  <zwplayer
545
613
  v-if="playerOpen"
546
614
  ref="zwplayerRef"
@@ -553,96 +621,13 @@ export default {
553
621
  :infoButton="true"
554
622
  :enableDanmu="true"
555
623
  :chapterButton="true"
624
+ danmuBarId="danmu-controlbar"
556
625
  :fluid="true"
557
626
  :autoplay="false"
558
627
  :disableMutedConfirm="true"
559
628
  />
560
629
  </div>
561
630
  </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
631
  ```
647
632
 
648
633
  ### 主要属性说明
@@ -665,6 +650,17 @@ export default {
665
650
  | thumbnails | Object | 缩略图配置对象 | - |
666
651
  | logo | Object | Logo水印配置对象 | - |
667
652
  | poster | String | 视频封面图地址 | - |
653
+ | timeFormat | String | 时间格式:`'s'`=秒,`'ms'`=毫秒 | `'s'` |
654
+ | castButton | Boolean | 是否显示投屏按钮 | false |
655
+ | zoomButton | Boolean | 是否显示放大镜按钮 | false |
656
+ | annotationButton | Boolean | 是否显示标注/热区按钮 | false |
657
+ | annotation | Object | 标注/热区配置数据 | - |
658
+ | annotations | Object | 标注/热区配置数据(annotation 别名) | - |
659
+ | watermark | Array | 水印配置数组 | - |
660
+ | watermarks | Array | 水印配置数组(watermark 别名) | - |
661
+ | translateApi | String | 翻译 API 端点 | - |
662
+ | defVolume | Number | 默认音量百分比 (0-100) | 61.25 |
663
+ | hideControlbarTimeout | Number | 控制栏自动隐藏等待时间(毫秒) | 10000 |
668
664
  | 其它 | - | 请参考 [zwplayer 播放器构造函数参数](https://www.zwplayer.cn/docs/support/guide-configuration.html) | - |
669
665
 
670
666
  **缩略图配置对象(thumbnails)示例:**
@@ -705,31 +701,11 @@ logo: {
705
701
  | onready | 播放器初始化完成事件 | - |
706
702
  | onmediaevent | 媒体播放事件(播放、暂停、结束等) | event对象,包含type等属性 |
707
703
 
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
704
  ### 方法调用
726
705
 
727
706
  通过 `ref` 引用调用播放器方法:
728
707
 
729
- **基础方法:**
730
-
731
708
  ```javascript
732
- // 获取播放器实例
733
709
  const player = this.$refs.zwplayerRef
734
710
 
735
711
  // 播放控制
@@ -738,11 +714,6 @@ player.pause() // 暂停
738
714
  player.seekTime(120) // 跳转到指定秒数
739
715
  player.stop() // 停止
740
716
 
741
- ```
742
-
743
- **高级方法:**
744
-
745
- ```javascript
746
717
  // 字幕相关
747
718
  player.addSubtitle('/subtitles/zh.vtt', '1') // 添加字幕轨道
748
719
  player.removeSubtitle('1') // 移除字幕轨道
@@ -762,160 +733,15 @@ player.setChapters([{
762
733
  duration: 50
763
734
  }])
764
735
 
765
-
766
736
  // 获取信息
767
737
  player.getDuration() // 获取视频总时长
768
738
  player.getCurrentTime() // 获取当前播放时间
769
-
770
739
  ```
771
740
 
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
741
  ## 其他版本
914
742
 
915
743
  ### Vue 3.x
916
744
 
917
- 如果你使用 Vue 3.x,请安装 `zwplayervue3`:
918
-
919
745
  ```bash
920
746
  npm install zwplayervue3 --save
921
747
  ```