zwplayer-react 1.0.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +550 -0
  3. package/lib/index.esm.js +585 -0
  4. package/lib/index.js +591 -0
  5. package/package.json +60 -0
  6. package/scripts/install.js +177 -0
  7. package/zwplayerlib/css/openhand.cur +0 -0
  8. package/zwplayerlib/css/zwplayer.css +1 -0
  9. package/zwplayerlib/css/zwplayer.ttf +0 -0
  10. package/zwplayerlib/css/zwplayer.woff +0 -0
  11. package/zwplayerlib/css/zwplayer.woff2 +0 -0
  12. package/zwplayerlib/plugins/dash.all.min.js +3 -0
  13. package/zwplayerlib/plugins/flv.live.js +358 -0
  14. package/zwplayerlib/plugins/flv.min.js +2 -0
  15. package/zwplayerlib/plugins/hls.light.min.js +2 -0
  16. package/zwplayerlib/plugins/hls.min.js +2 -0
  17. package/zwplayerlib/plugins/mpeg.min.js +9 -0
  18. package/zwplayerlib/widgets/danmu_setting.html +116 -0
  19. package/zwplayerlib/widgets/smiles/p1.png +0 -0
  20. package/zwplayerlib/widgets/smiles/p10.png +0 -0
  21. package/zwplayerlib/widgets/smiles/p11.png +0 -0
  22. package/zwplayerlib/widgets/smiles/p12.png +0 -0
  23. package/zwplayerlib/widgets/smiles/p13.png +0 -0
  24. package/zwplayerlib/widgets/smiles/p14.png +0 -0
  25. package/zwplayerlib/widgets/smiles/p15.png +0 -0
  26. package/zwplayerlib/widgets/smiles/p16.png +0 -0
  27. package/zwplayerlib/widgets/smiles/p17.png +0 -0
  28. package/zwplayerlib/widgets/smiles/p18.png +0 -0
  29. package/zwplayerlib/widgets/smiles/p19.png +0 -0
  30. package/zwplayerlib/widgets/smiles/p2.png +0 -0
  31. package/zwplayerlib/widgets/smiles/p20.png +0 -0
  32. package/zwplayerlib/widgets/smiles/p21.png +0 -0
  33. package/zwplayerlib/widgets/smiles/p22.png +0 -0
  34. package/zwplayerlib/widgets/smiles/p23.png +0 -0
  35. package/zwplayerlib/widgets/smiles/p24.png +0 -0
  36. package/zwplayerlib/widgets/smiles/p25.png +0 -0
  37. package/zwplayerlib/widgets/smiles/p26.png +0 -0
  38. package/zwplayerlib/widgets/smiles/p27.png +0 -0
  39. package/zwplayerlib/widgets/smiles/p28.png +0 -0
  40. package/zwplayerlib/widgets/smiles/p29.png +0 -0
  41. package/zwplayerlib/widgets/smiles/p3.png +0 -0
  42. package/zwplayerlib/widgets/smiles/p30.png +0 -0
  43. package/zwplayerlib/widgets/smiles/p31.png +0 -0
  44. package/zwplayerlib/widgets/smiles/p32.png +0 -0
  45. package/zwplayerlib/widgets/smiles/p33.png +0 -0
  46. package/zwplayerlib/widgets/smiles/p34.png +0 -0
  47. package/zwplayerlib/widgets/smiles/p35.png +0 -0
  48. package/zwplayerlib/widgets/smiles/p36.png +0 -0
  49. package/zwplayerlib/widgets/smiles/p37.png +0 -0
  50. package/zwplayerlib/widgets/smiles/p38.png +0 -0
  51. package/zwplayerlib/widgets/smiles/p39.png +0 -0
  52. package/zwplayerlib/widgets/smiles/p4.png +0 -0
  53. package/zwplayerlib/widgets/smiles/p40.png +0 -0
  54. package/zwplayerlib/widgets/smiles/p5.png +0 -0
  55. package/zwplayerlib/widgets/smiles/p6.png +0 -0
  56. package/zwplayerlib/widgets/smiles/p7.png +0 -0
  57. package/zwplayerlib/widgets/smiles/p8.png +0 -0
  58. package/zwplayerlib/widgets/smiles/p9.png +0 -0
  59. package/zwplayerlib/zwplayer.js +940 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 [你的名字]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,550 @@
1
+ # zwplayer-react
2
+
3
+ React wrapper component for zwplayer, providing easy-to-use video playback capabilities.
4
+
5
+ **[English](#english) | [中文](#中文)**
6
+
7
+ ---
8
+
9
+ <a id="english"></a>
10
+
11
+ React wrapper component for zwplayer, providing easy-to-use video playback capabilities.
12
+
13
+ ## About zwplayer
14
+
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
+
17
+ ### Core Principles
18
+
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
24
+
25
+ ### Key Features
26
+
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
34
+
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/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/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/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/tools/subtitle/) |
57
+ | 5 | **Chapter Editor** | Visually create and export video chapter marker data | [chapter](https://www.zwplayer.com/tools/chapter/) |
58
+ | 6 | **Thumbnail Generator** | Quickly generate video sprite sheets and ZWMAP JSON configuration | [thumbnail](https://www.zwplayer.com/tools/thumbnail/) |
59
+ | 7 | **Playlist Editor** | Visually manage and export playlist data, with group and auto-play support | [playlist](https://www.zwplayer.com/tools/playlist/) |
60
+ | 8 | **Watermark Editor** | Visually configure image watermarks, text watermarks, animated roaming watermarks, and tiled watermarks | [watermark](https://www.zwplayer.com/tools/watermark/) |
61
+
62
+ For more details, please visit:
63
+ - [zwplayer Official Website](https://www.zwplayer.com)
64
+ - [Online Demo](https://www.zwplayer.com/tools/videoplayer/)
65
+
66
+ ## Getting Started
67
+
68
+ ### Installation
69
+
70
+ ```bash
71
+ npm install zwplayer-react --save
72
+ ```
73
+
74
+ #### Installation Notes
75
+
76
+ **Important**: This component depends on the `zwplayer` core library. Please note the following during installation:
77
+
78
+ 1. **Automatic Configuration**: `npm install` will automatically run the `postinstall` script, which will copy the `zwplayer` core library to the `public/zwplayer` directory
79
+
80
+ 2. **Core Library Must Be Deployed**: The `public/zwplayer` directory must be deployed along with your project to production
81
+
82
+ 3. **Dynamic Loading Mechanism**: zwplayer uses a dynamic loading mechanism, supporting seamless upgrades without modifying your application code
83
+
84
+ 4. **Intranet / Offline Deployment**: zwplayer does not depend on CDNs and fully supports intranet and offline environments
85
+
86
+ ### Component Usage
87
+
88
+ ```jsx
89
+ import React, { useRef } from 'react';
90
+ import { ZwPlayer } from 'zwplayer-react';
91
+
92
+ function App() {
93
+ const playerRef = useRef(null);
94
+
95
+ const handlePlayerReady = () => {
96
+ console.log('Player ready');
97
+ };
98
+
99
+ const handlePlayerMediaEvent = (event) => {
100
+ console.log('Media event:', event.type);
101
+ };
102
+
103
+ return (
104
+ <ZwPlayer
105
+ ref={playerRef}
106
+ murl="https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4"
107
+ onready={handlePlayerReady}
108
+ onmediaevent={handlePlayerMediaEvent}
109
+ snapshotButton={true}
110
+ optionButton={true}
111
+ infoButton={true}
112
+ enableDanmu={true}
113
+ chapterButton={true}
114
+ fluid={true}
115
+ autoplay={false}
116
+ disableMutedConfirm={true}
117
+ />
118
+ );
119
+ }
120
+
121
+ export default App;
122
+ ```
123
+
124
+ ### Danmaku Example
125
+
126
+ ```jsx
127
+ import React, { useRef } from 'react';
128
+ import { ZwPlayer } from 'zwplayer-react';
129
+
130
+ function DanmuDemo() {
131
+ const playerRef = useRef(null);
132
+
133
+ const handlePlayerReady = () => {
134
+ const player = playerRef.current;
135
+ if (player && player.appendDanmu) {
136
+ player.appendDanmu({
137
+ border: '1px solid #ccc',
138
+ text: 'Welcome to zwplayer!',
139
+ color: '#ff6b6b'
140
+ });
141
+ }
142
+ };
143
+
144
+ const handleSendDanmu = (danmuText) => {
145
+ if (!danmuText) return;
146
+ const player = playerRef.current;
147
+ if (player && player.appendDanmu) {
148
+ player.appendDanmu({ border: '1px solid #ccc', text: danmuText });
149
+ }
150
+ };
151
+
152
+ return (
153
+ <div>
154
+ <ZwPlayer
155
+ ref={playerRef}
156
+ murl="https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4"
157
+ onready={handlePlayerReady}
158
+ enableDanmu={true}
159
+ sendDanmu={handleSendDanmu}
160
+ fluid={true}
161
+ disableMutedConfirm={true}
162
+ danmuBarId="danmu-controlbar"
163
+ />
164
+ <div id="danmu-controlbar" style={{ height: 50, backgroundColor: '#232323', padding: 8 }}></div>
165
+ </div>
166
+ );
167
+ }
168
+
169
+ export default DanmuDemo;
170
+ ```
171
+
172
+ ### Main Properties
173
+
174
+ | Property | Type | Description | Default |
175
+ |---------|------|-------------|---------|
176
+ | murl | String/Object/Array | Media URL parameter, supports dynamic switching | - |
177
+ | fluid | Boolean | Enable fluid layout (adaptive to container width) | false |
178
+ | autoplay | Boolean | Auto-play on load | false |
179
+ | disableMutedConfirm | Boolean | Disable muted playback confirmation | false |
180
+ | enableDanmu | Boolean | Enable danmaku (bullet comments) | false |
181
+ | snapshotButton | Boolean | Show screenshot button | false |
182
+ | optionButton | Boolean | Show settings button | false |
183
+ | infoButton | Boolean | Show info button | false |
184
+ | chapterButton | Boolean | Show chapter button | false |
185
+ | recordButton | Boolean | Show record button | false |
186
+ | segmentButton | Boolean | Show segment button | false |
187
+ | localPlayback | Boolean | Enable local file playback | false |
188
+ | sendDanmu | Function | Callback function for sending danmaku | - |
189
+ | thumbnails | Object | Thumbnail configuration object | - |
190
+ | logo | Object | Logo watermark configuration object | - |
191
+ | poster | String | Video poster image URL | - |
192
+ | timeFormat | String | Time format: `'s'` = seconds, `'ms'` = milliseconds | `'s'` |
193
+ | castButton | Boolean | Show cast button | false |
194
+ | zoomButton | Boolean | Show magnifier button | false |
195
+ | annotationButton | Boolean | Show annotation/hotspot button | false |
196
+ | annotation | Object | Annotation/hotspot configuration data | - |
197
+ | annotations | Object | Annotation/hotspot configuration data (alias for annotation) | - |
198
+ | watermark | Array | Watermark configuration array | - |
199
+ | watermarks | Array | Watermark configuration array (alias for watermark) | - |
200
+ | translateApi | String | Translation API endpoint | - |
201
+ | defVolume | Number | Default volume percentage (0-100) | 61.25 |
202
+ | hideControlbarTimeout | Number | Control bar auto-hide timeout (milliseconds) | 10000 |
203
+ | Others | - | See [zwplayer constructor parameters](https://www.zwplayer.com/docs/support/guide-configuration.html) | - |
204
+
205
+ ### Events
206
+
207
+ | Event Name | Description | Callback Parameters |
208
+ |-----------|-------------|---------------------|
209
+ | onready | Player initialization complete | player instance |
210
+ | onmediaevent | Media playback event (play, pause, ended, etc.) | event object |
211
+
212
+ ### Method Calls
213
+
214
+ ```jsx
215
+ const player = playerRef.current;
216
+
217
+ // Basic playback control
218
+ player.play() // play
219
+ player.pause() // pause
220
+ player.seekTime(120) // seek to 120 seconds
221
+ player.stop() // stop
222
+
223
+ // Subtitles
224
+ player.addSubtitle('/subtitles/zh.vtt', '1')
225
+ player.removeSubtitle('1')
226
+
227
+ // Danmaku
228
+ player.appendDanmu({ border: '1px solid #ccc', text: 'Hello!', color: '#ff6b6b' })
229
+
230
+ // Chapters
231
+ player.setChapters([{ title: "Chapter 1", time: 0, duration: 50 }])
232
+
233
+ // Info
234
+ player.getDuration()
235
+ player.getCurrentTime()
236
+ ```
237
+
238
+ ### Example Project
239
+
240
+ - **Gitee**: https://gitee.com/chenfanyu/zwplayer-react-demo
241
+ - **GitHub**: https://github.com/chenfanyu/zwplayer-react-demo
242
+
243
+ ## Other Versions
244
+
245
+ ### Vue 2.x
246
+
247
+ ```bash
248
+ npm install zwplayer-vue2x --save
249
+ ```
250
+
251
+ ### Vue 3.x
252
+
253
+ ```bash
254
+ npm install zwplayervue3 --save
255
+ ```
256
+
257
+ ## Related Resources
258
+
259
+ ### Official Documentation
260
+ - [ZWPlayer Official Website](https://www.zwplayer.com)
261
+ - [Online Demo](https://www.zwplayer.com/tools/videoplayer/)
262
+ - **[React Framework Guide](https://www.zwplayer.com/docs/support/guide-react-framework.html)** — Complete React integration tutorial
263
+ - [Configuration Parameters](https://www.zwplayer.com/docs/support/guide-configuration.html)
264
+ - [API Methods](https://www.zwplayer.com/docs/support/guide-api.html)
265
+ - [Events](https://www.zwplayer.com/docs/support/guide-events.html)
266
+
267
+ ## License
268
+
269
+ MIT License. ZWPlayer core library is completely free to use.
270
+
271
+ ## Technical Support
272
+
273
+ - Email: 893366640@qq.com
274
+ - QQ: 893366640
275
+ - WeChat: zwplayerX
276
+ - Official Account: zwplayer
277
+
278
+ ---
279
+
280
+ <a id="中文"></a>
281
+
282
+ React 的 zwplayer 组件封装,提供简单易用的视频播放能力。
283
+
284
+ ## 关于 zwplayer
285
+
286
+ `zwplayer`(Zero Web Player)是一款秉持"智能傻瓜式"设计理念的网页播放器,致力于将开发者的使用成本降至无限接近于零。
287
+
288
+ ### 核心特点
289
+
290
+ ✅ **零费用成本** - 完全免费,永久免费,无需支付任何费用
291
+
292
+ ✅ **零学习成本** - 提供统一简洁的 API,智能引擎自动处理所有流媒体技术细节
293
+
294
+ ✅ **零升级成本** - API 永久固化,版本升级仅需替换文件
295
+
296
+ ✅ **零风险成本** - 代码纯净,无广告、无统计、无联网后门
297
+
298
+ ✅ **零部署成本** - 不依赖第三方库和 CDN,私网、内网均可使用
299
+
300
+ ### 主要功能
301
+
302
+ - **广泛协议支持**:HLS、DASH、HTTP-FLV、HTTP-TS、WS、WebRTC(WHEP/ARTC/BRTC/TRTC)
303
+ - **特色协议**:支持 RTSP 网页播放(无需插件)
304
+ - **本地文件播放**:支持直接播放用户设备上的本地视频/音频文件
305
+ - **智能字幕**:支持双字幕、字幕搜索、字幕翻译、章节搜索、拖拽加载本地字幕/章节文件
306
+ - **丰富功能**:弹幕、进度条预览、画面调节、截图、音量增益、AB循环、录制、音频提取等
307
+ - **直播优化**:超低延时直播、直播追帧、多码流切换
308
+ - **灵活模式**:画中画、网页全屏、自动小窗口、强制锁定模式
309
+
310
+ ### v3.3.0 新增功能
311
+
312
+ - **投屏**:支持通过浏览器 Presentation API / AirPlay 投射到外部设备
313
+ - **水印**:支持多水印、图片水印、文字水印、动态游走水印,兼容旧版 `logo` 配置
314
+ - **播放列表**:支持 XML 格式播放列表,多集分组管理,自动播放下一集
315
+ - **视频交互热区(标注)**:可视化拖拽设计视频交互热区,支持表单、测验、投票等交互节点
316
+ - **逐帧步进**:通过键盘方向键逐帧精确控制播放
317
+ - **字幕翻译**:可设置翻译 API,支持实时字幕翻译面板
318
+ - **音量增强**:通过 Web Audio API 实现超过 100% 的音量增益
319
+ - **时间格式**:支持秒和毫秒两种时间显示格式
320
+ - **放大镜**:全新重写的放大镜功能
321
+
322
+ ### 在线工具
323
+
324
+ ZWPlayer 提供 **8 个免费在线工具**,无需注册,即开即用:
325
+
326
+ | # | 工具 | 说明 | 链接 |
327
+ |---|------|------|------|
328
+ | 1 | **在线播放器** | 全协议在线试播与本地文件预览,支持 WebRTC/RTSP/HLS/DASH/FLV 等所有协议 | [videoplayer](https://www.zwplayer.com/tools/videoplayer/) |
329
+ | 2 | **代码生成器** | 可视化配置播放器 UI 皮肤、自动播放策略、字幕挂载与视频热区,一键导出集成代码 | [generator](https://www.zwplayer.com/tools/generator/) |
330
+ | 3 | **交互标注编辑器** | 可视化拖拽设计视频交互热区,支持表单、测验、投票等交互节点 | [annotation](https://www.zwplayer.com/tools/annotation/) |
331
+ | 4 | **字幕编辑器** | 在线创建、翻译和导出 SRT、VTT、BCC、JSON 等格式字幕 | [subtitle](https://www.zwplayer.com/tools/subtitle/) |
332
+ | 5 | **章节编辑器** | 可视化创建和导出视频章节标记数据 | [chapter](https://www.zwplayer.com/tools/chapter/) |
333
+ | 6 | **缩略图生成器** | 快速生成视频雪碧图(Sprite Sheet)和 ZWMAP JSON 配置 | [thumbnail](https://www.zwplayer.com/tools/thumbnail/) |
334
+ | 7 | **播放列表编辑器** | 可视化管理和导出播放列表数据,支持分组和自动播放 | [playlist](https://www.zwplayer.com/tools/playlist/) |
335
+ | 8 | **水印编辑器** | 可视化配置图片水印、文字水印、动态游走水印和铺满水印 | [watermark](https://www.zwplayer.com/tools/watermark/) |
336
+
337
+ 更多详情请访问:
338
+ - [zwplayer 官网](https://www.zwplayer.com)
339
+ - [在线体验](https://www.zwplayer.com/tools/videoplayer/)
340
+
341
+ ## 使用说明
342
+
343
+ ### 安装
344
+
345
+ ```bash
346
+ npm install zwplayer-react --save
347
+ ```
348
+
349
+ #### 安装注意事项
350
+
351
+ ⚠️ **重要**:本组件依赖 `zwplayer` 核心库,安装时请注意以下事项:
352
+
353
+ 1. **自动配置**:`npm install` 会自动执行 `postinstall` 脚本,将 `zwplayer` 核心库复制到 `public/zwplayer` 目录
354
+
355
+ 2. **核心库必须发布**:`public/zwplayer` 目录必须随项目一起发布到生产环境
356
+
357
+ 3. **动态加载机制**:zwplayer 采用动态加载机制,升级时只需替换 `public/zwplayer` 目录中的文件
358
+
359
+ 4. **内网/私网部署**:zwplayer 不依赖 CDN,完全支持内网和离线环境部署
360
+
361
+ ### 组件使用
362
+
363
+ ```jsx
364
+ import React, { useRef } from 'react';
365
+ import { ZwPlayer } from 'zwplayer-react';
366
+
367
+ function App() {
368
+ const playerRef = useRef(null);
369
+
370
+ return (
371
+ <ZwPlayer
372
+ ref={playerRef}
373
+ murl="https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4"
374
+ onready={() => console.log('Player ready')}
375
+ onmediaevent={(e) => console.log('Media event:', e.type)}
376
+ snapshotButton={true}
377
+ optionButton={true}
378
+ infoButton={true}
379
+ enableDanmu={true}
380
+ chapterButton={true}
381
+ fluid={true}
382
+ autoplay={false}
383
+ disableMutedConfirm={true}
384
+ />
385
+ );
386
+ }
387
+ ```
388
+
389
+ ### 弹幕功能示例
390
+
391
+ ```jsx
392
+ import React, { useRef } from 'react';
393
+ import { ZwPlayer } from 'zwplayer-react';
394
+
395
+ function DanmuDemo() {
396
+ const playerRef = useRef(null);
397
+
398
+ const handlePlayerReady = () => {
399
+ const player = playerRef.current;
400
+ if (player && player.appendDanmu) {
401
+ player.appendDanmu({
402
+ border: '1px solid #ccc',
403
+ text: '欢迎来到 zwplayer!',
404
+ color: '#ff6b6b'
405
+ });
406
+ }
407
+ };
408
+
409
+ const handleSendDanmu = (danmuText) => {
410
+ if (!danmuText) return;
411
+ const player = playerRef.current;
412
+ if (player && player.appendDanmu) {
413
+ player.appendDanmu({ border: '1px solid #ccc', text: danmuText });
414
+ }
415
+ };
416
+
417
+ return (
418
+ <div>
419
+ <ZwPlayer
420
+ ref={playerRef}
421
+ murl="https://cdn.zwplayer.cn/media/VMAP9lxJvRpgn5sP3lV6rQ9qkzQmh5psggso3185.mp4"
422
+ onready={handlePlayerReady}
423
+ enableDanmu={true}
424
+ sendDanmu={handleSendDanmu}
425
+ fluid={true}
426
+ disableMutedConfirm={true}
427
+ danmuBarId="danmu-controlbar"
428
+ />
429
+ <div id="danmu-controlbar" style={{ height: 50, backgroundColor: '#232323', padding: 8, boxSizing: 'border-box' }}></div>
430
+ </div>
431
+ );
432
+ }
433
+ ```
434
+
435
+ ### 主要属性说明
436
+
437
+ | 属性名称 | 类型 | 说明 | 默认值 |
438
+ |---------|------|------|--------|
439
+ | murl | String/Object/Array | 媒体地址参数,支持动态切换 | - |
440
+ | fluid | Boolean | 是否启用流式布局(自适应容器宽度) | false |
441
+ | autoplay | Boolean | 是否自动播放 | false |
442
+ | disableMutedConfirm | Boolean | 禁用静音确认 | false |
443
+ | enableDanmu | Boolean | 是否启用弹幕功能 | false |
444
+ | snapshotButton | Boolean | 是否显示截图按钮 | false |
445
+ | optionButton | Boolean | 是否显示设置按钮 | false |
446
+ | infoButton | Boolean | 是否显示信息按钮 | false |
447
+ | chapterButton | Boolean | 是否显示章节按钮 | false |
448
+ | recordButton | Boolean | 是否显示录制按钮 | false |
449
+ | segmentButton | Boolean | 是否显示分段按钮 | false |
450
+ | localPlayback | Boolean | 是否启用本地播放功能 | false |
451
+ | sendDanmu | Function | 发送弹幕的回调函数 | - |
452
+ | thumbnails | Object | 缩略图配置对象 | - |
453
+ | logo | Object | Logo水印配置对象 | - |
454
+ | poster | String | 视频封面图地址 | - |
455
+ | timeFormat | String | 时间格式:`'s'`=秒,`'ms'`=毫秒 | `'s'` |
456
+ | castButton | Boolean | 是否显示投屏按钮 | false |
457
+ | zoomButton | Boolean | 是否显示放大镜按钮 | false |
458
+ | annotationButton | Boolean | 是否显示标注/热区按钮 | false |
459
+ | annotation | Object | 标注/热区配置数据 | - |
460
+ | annotations | Object | 标注/热区配置数据(annotation 别名) | - |
461
+ | watermark | Array | 水印配置数组 | - |
462
+ | watermarks | Array | 水印配置数组(watermark 别名) | - |
463
+ | translateApi | String | 翻译 API 端点 | - |
464
+ | defVolume | Number | 默认音量百分比 (0-100) | 61.25 |
465
+ | hideControlbarTimeout | Number | 控制栏自动隐藏等待时间(毫秒) | 10000 |
466
+ | 其它 | - | 请参考 [zwplayer 播放器构造函数参数](https://www.zwplayer.com/docs/support/guide-configuration.html) | - |
467
+
468
+ ### 事件
469
+
470
+ | 事件名称 | 说明 | 回调参数 |
471
+ |---------|------|---------|
472
+ | onready | 播放器初始化完成 | player 实例 |
473
+ | onmediaevent | 媒体事件(播放、暂停、结束等) | event 对象 |
474
+
475
+ ### 方法调用
476
+
477
+ 通过 `ref` 引用调用播放器方法:
478
+
479
+ ```jsx
480
+ const player = playerRef.current;
481
+
482
+ // 播放控制
483
+ player.play() // 播放
484
+ player.pause() // 暂停
485
+ player.seekTime(120) // 跳转到指定秒数
486
+ player.stop() // 停止
487
+
488
+ // 字幕
489
+ player.addSubtitle('/subtitles/zh.vtt', '1')
490
+ player.removeSubtitle('1')
491
+
492
+ // 弹幕
493
+ player.appendDanmu({ border: '1px solid #ccc', text: '这是一条弹幕', color: '#ff6b6b' })
494
+
495
+ // 章节
496
+ player.setChapters([{ title: "章节1", desc: "章节1描述", time: 0, duration: 50 }])
497
+
498
+ // 获取信息
499
+ player.getDuration() // 获取视频总时长
500
+ player.getCurrentTime() // 获取当前播放时间
501
+ ```
502
+
503
+ 更多方法请参考 [zwplayer API 文档](https://www.zwplayer.com/docs/support/guide-api.html)。
504
+
505
+ ### 示例项目
506
+
507
+ - **Gitee**: https://gitee.com/chenfanyu/zwplayer-react-demo
508
+ - **GitHub**: https://github.com/chenfanyu/zwplayer-react-demo
509
+
510
+ ## 其他版本
511
+
512
+ ### Vue 2.x
513
+
514
+ ```bash
515
+ npm install zwplayer-vue2x --save
516
+ ```
517
+
518
+ ### Vue 3.x
519
+
520
+ ```bash
521
+ npm install zwplayervue3 --save
522
+ ```
523
+
524
+ ## 相关资源
525
+
526
+ ### 官方文档
527
+ - [ZWPlayer 官网](https://www.zwplayer.com)
528
+ - [在线体验](https://www.zwplayer.com/tools/videoplayer/)
529
+ - **[React 框架使用指南](https://www.zwplayer.com/zh/docs/support/guide-react-framework.html)** — 完整的 React 集成教程
530
+ - [配置参数文档](https://www.zwplayer.com/docs/support/guide-configuration.html)
531
+ - [API 方法文档](https://www.zwplayer.com/docs/support/guide-api.html)
532
+ - [事件文档](https://www.zwplayer.com/docs/support/guide-events.html)
533
+
534
+ ### 示例项目
535
+ - [React 示例 (Gitee)](https://gitee.com/chenfanyu/zwplayer-react-demo)
536
+ - [React 示例 (GitHub)](https://github.com/chenfanyu/zwplayer-react-demo)
537
+ - [Vue 3 示例 (Gitee)](https://gitee.com/chenfanyu/zwplayervue3-demo)
538
+ - [Vue 2 示例 (Gitee)](https://gitee.com/chenfanyu/zwplayer-vue2x-demo)
539
+
540
+ ## 许可证
541
+
542
+ 本组件遵循 MIT 许可证。ZWPlayer 核心库完全免费使用。
543
+
544
+ ## 技术支持
545
+
546
+ 如有问题或建议,请通过以下方式联系:
547
+ - 邮箱:893366640@qq.com
548
+ - QQ:893366640
549
+ - 微信:zwplayerX
550
+ - 公众号:zwplayer