video-react-player 0.1.0 → 0.1.1

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 (66) hide show
  1. package/dist/actions/player.d.ts.map +1 -0
  2. package/dist/actions/video.d.ts.map +1 -0
  3. package/dist/components/Bezel.d.ts.map +1 -0
  4. package/dist/components/BigPlayButton.d.ts.map +1 -0
  5. package/dist/components/ClickableComponent.d.ts.map +1 -0
  6. package/dist/components/LoadingSpinner.d.ts.map +1 -0
  7. package/dist/components/Player.d.ts.map +1 -0
  8. package/dist/components/PosterImage.d.ts.map +1 -0
  9. package/dist/components/Shortcut.d.ts.map +1 -0
  10. package/dist/components/Slider.d.ts.map +1 -0
  11. package/dist/components/Source.d.ts.map +1 -0
  12. package/dist/components/Video.d.ts.map +1 -0
  13. package/dist/components/control-bar/ClosedCaptionButton.d.ts.map +1 -0
  14. package/dist/components/control-bar/ControlBar.d.ts.map +1 -0
  15. package/dist/components/control-bar/DownloadButton.d.ts.map +1 -0
  16. package/dist/components/control-bar/ForwardControl.d.ts.map +1 -0
  17. package/dist/components/control-bar/ForwardReplayControl.d.ts.map +1 -0
  18. package/dist/components/control-bar/FullscreenToggle.d.ts.map +1 -0
  19. package/dist/components/control-bar/LoadProgressBar.d.ts.map +1 -0
  20. package/dist/components/control-bar/LoopToggle.d.ts.map +1 -0
  21. package/dist/components/control-bar/MouseTimeDisplay.d.ts.map +1 -0
  22. package/dist/components/control-bar/PictureInPictureToggle.d.ts.map +1 -0
  23. package/dist/components/control-bar/PlayProgressBar.d.ts.map +1 -0
  24. package/dist/components/control-bar/PlayToggle.d.ts.map +1 -0
  25. package/dist/components/control-bar/PlaybackRate.d.ts.map +1 -0
  26. package/dist/components/control-bar/PlaybackRateMenuButton.d.ts.map +1 -0
  27. package/dist/components/control-bar/ProgressControl.d.ts.map +1 -0
  28. package/dist/components/control-bar/QualityMenuButton.d.ts.map +1 -0
  29. package/dist/components/control-bar/ReplayControl.d.ts.map +1 -0
  30. package/dist/components/control-bar/ScreenshotButton.d.ts.map +1 -0
  31. package/dist/components/control-bar/SeekBar.d.ts.map +1 -0
  32. package/dist/components/control-bar/TheaterModeToggle.d.ts.map +1 -0
  33. package/dist/components/control-bar/VolumeMenuButton.d.ts.map +1 -0
  34. package/dist/components/menu/Menu.d.ts.map +1 -0
  35. package/dist/components/menu/MenuButton.d.ts.map +1 -0
  36. package/dist/components/menu/MenuItem.d.ts.map +1 -0
  37. package/dist/components/popup/Popup.d.ts.map +1 -0
  38. package/dist/components/popup/PopupButton.d.ts.map +1 -0
  39. package/dist/components/time-controls/CurrentTimeDisplay.d.ts.map +1 -0
  40. package/dist/components/time-controls/DurationDisplay.d.ts.map +1 -0
  41. package/dist/components/time-controls/RemainingTimeDisplay.d.ts.map +1 -0
  42. package/dist/components/time-controls/TimeDivider.d.ts.map +1 -0
  43. package/dist/components/volume-control/VolumeBar.d.ts.map +1 -0
  44. package/dist/components/volume-control/VolumeControl.d.ts.map +1 -0
  45. package/dist/components/volume-control/VolumeLevel.d.ts.map +1 -0
  46. package/dist/reducers/index.d.ts.map +1 -0
  47. package/dist/reducers/operation.d.ts.map +1 -0
  48. package/dist/reducers/player.d.ts.map +1 -0
  49. package/dist/types/component.d.ts.map +1 -0
  50. package/dist/types/player.d.ts.map +1 -0
  51. package/dist/utils/browser.d.ts.map +1 -0
  52. package/dist/utils/dom.d.ts.map +1 -0
  53. package/dist/utils/fullscreen.d.ts.map +1 -0
  54. package/dist/utils/index.d.ts.map +1 -0
  55. package/package.json +10 -5
  56. package/dist/video-react-new.cjs.js +0 -3904
  57. package/dist/video-react-new.css +0 -1155
  58. package/dist/video-react-new.es.js +0 -3861
  59. package/dist/video-react-new.full.js +0 -4578
  60. package/dist/video-react-new.full.min.js +0 -2
  61. package/dist/video-react-new.js +0 -4283
  62. package/dist/video-react-new.min.js +0 -2
  63. package/dist/video-react-player.full.js +0 -4578
  64. package/dist/video-react-player.full.min.js +0 -2
  65. package/dist/video-react-player.js +0 -4283
  66. package/dist/video-react-player.min.js +0 -2
@@ -1,3861 +0,0 @@
1
- import classNames from 'classnames';
2
- import React, { Component, forwardRef, useRef, useReducer, useEffect, useCallback, useMemo, useImperativeHandle, useState } from 'react';
3
- import { createStore } from 'redux';
4
- import PropTypes from 'prop-types';
5
-
6
- function _assertThisInitialized(e) {
7
- if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
8
- return e;
9
- }
10
- function _defineProperties(e, r) {
11
- for (var t = 0; t < r.length; t++) {
12
- var o = r[t];
13
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
14
- }
15
- }
16
- function _createClass(e, r, t) {
17
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
18
- writable: !1
19
- }), e;
20
- }
21
- function _extends() {
22
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
23
- for (var e = 1; e < arguments.length; e++) {
24
- var t = arguments[e];
25
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
26
- }
27
- return n;
28
- }, _extends.apply(null, arguments);
29
- }
30
- function _inheritsLoose(t, o) {
31
- t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
32
- }
33
- function _objectWithoutPropertiesLoose(r, e) {
34
- if (null == r) return {};
35
- var t = {};
36
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
37
- if (-1 !== e.indexOf(n)) continue;
38
- t[n] = r[n];
39
- }
40
- return t;
41
- }
42
- function _setPrototypeOf(t, e) {
43
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
44
- return t.__proto__ = e, t;
45
- }, _setPrototypeOf(t, e);
46
- }
47
- function _toPrimitive(t, r) {
48
- if ("object" != typeof t || !t) return t;
49
- var e = t[Symbol.toPrimitive];
50
- if (void 0 !== e) {
51
- var i = e.call(t, r || "default");
52
- if ("object" != typeof i) return i;
53
- throw new TypeError("@@toPrimitive must return a primitive value.");
54
- }
55
- return ("string" === r ? String : Number)(t);
56
- }
57
- function _toPropertyKey(t) {
58
- var i = _toPrimitive(t, "string");
59
- return "symbol" == typeof i ? i : i + "";
60
- }
61
-
62
- /**
63
-
64
- * Copyright (c) 2016 Video-React contributors
65
- * Copyright (c) 2025 ZingMe.Vn
66
- *
67
- * This source code is licensed under the MIT license found in the
68
- * LICENSE file in the root directory of this source tree.
69
- */
70
- var LOAD_START = 'video-react-player/LOAD_START';
71
- var CAN_PLAY = 'video-react-player/CAN_PLAY';
72
- var WAITING = 'video-react-player/WAITING';
73
- var CAN_PLAY_THROUGH = 'video-react-player/CAN_PLAY_THROUGH';
74
- var PLAYING = 'video-react-player/PLAYING';
75
- var PLAY = 'video-react-player/PLAY';
76
- var PAUSE = 'video-react-player/PAUSE';
77
- var END = 'video-react-player/END';
78
- var SEEKING = 'video-react-player/SEEKING';
79
- var SEEKED = 'video-react-player/SEEKED';
80
- var SEEKING_TIME = 'video-react-player/SEEKING_TIME';
81
- var END_SEEKING = 'video-react-player/END_SEEKING';
82
- var DURATION_CHANGE = 'video-react-player/DURATION_CHANGE';
83
- var TIME_UPDATE = 'video-react-player/TIME_UPDATE';
84
- var VOLUME_CHANGE = 'video-react-player/VOLUME_CHANGE';
85
- var PROGRESS_CHANGE = 'video-react-player/PROGRESS_CHANGE';
86
- var RATE_CHANGE = 'video-react-player/RATE_CHANGE';
87
- var SUSPEND = 'video-react-player/SUSPEND';
88
- var ABORT = 'video-react-player/ABORT';
89
- var EMPTIED = 'video-react-player/EMPTIED';
90
- var STALLED = 'video-react-player/STALLED';
91
- var LOADED_META_DATA = 'video-react-player/LOADED_META_DATA';
92
- var LOADED_DATA = 'video-react-player/LOADED_DATA';
93
- var RESIZE = 'video-react-player/RESIZE';
94
- var ERROR = 'video-react-player/ERROR';
95
- var ACTIVATE_TEXT_TRACK = 'video-react-player/ACTIVATE_TEXT_TRACK';
96
- var PICTURE_IN_PICTURE_CHANGE = 'video-react-player/PICTURE_IN_PICTURE_CHANGE';
97
- var LOOP_CHANGE = 'video-react-player/LOOP_CHANGE';
98
- var THEATER_MODE_CHANGE = 'video-react-player/THEATER_MODE_CHANGE';
99
- var QUALITY_CHANGE = 'video-react-player/QUALITY_CHANGE';
100
- function handleLoadStart(videoProps) {
101
- return {
102
- type: LOAD_START,
103
- videoProps: videoProps
104
- };
105
- }
106
- function handleCanPlay(videoProps) {
107
- return {
108
- type: CAN_PLAY,
109
- videoProps: videoProps
110
- };
111
- }
112
- function handleWaiting(videoProps) {
113
- return {
114
- type: WAITING,
115
- videoProps: videoProps
116
- };
117
- }
118
- function handleCanPlayThrough(videoProps) {
119
- return {
120
- type: CAN_PLAY_THROUGH,
121
- videoProps: videoProps
122
- };
123
- }
124
- function handlePlaying(videoProps) {
125
- return {
126
- type: PLAYING,
127
- videoProps: videoProps
128
- };
129
- }
130
- function handlePlay(videoProps) {
131
- return {
132
- type: PLAY,
133
- videoProps: videoProps
134
- };
135
- }
136
- function handlePause(videoProps) {
137
- return {
138
- type: PAUSE,
139
- videoProps: videoProps
140
- };
141
- }
142
- function handleEnd(videoProps) {
143
- return {
144
- type: END,
145
- videoProps: videoProps
146
- };
147
- }
148
- function handleSeeking(videoProps) {
149
- return {
150
- type: SEEKING,
151
- videoProps: videoProps
152
- };
153
- }
154
- function handleSeeked(videoProps) {
155
- return {
156
- type: SEEKED,
157
- videoProps: videoProps
158
- };
159
- }
160
- function handleDurationChange(videoProps) {
161
- return {
162
- type: DURATION_CHANGE,
163
- videoProps: videoProps
164
- };
165
- }
166
- function handleTimeUpdate(videoProps) {
167
- return {
168
- type: TIME_UPDATE,
169
- videoProps: videoProps
170
- };
171
- }
172
- function handleVolumeChange(videoProps) {
173
- return {
174
- type: VOLUME_CHANGE,
175
- videoProps: videoProps
176
- };
177
- }
178
- function handleProgressChange(videoProps) {
179
- return {
180
- type: PROGRESS_CHANGE,
181
- videoProps: videoProps
182
- };
183
- }
184
- function handleRateChange(videoProps) {
185
- return {
186
- type: RATE_CHANGE,
187
- videoProps: videoProps
188
- };
189
- }
190
- function handleSuspend(videoProps) {
191
- return {
192
- type: SUSPEND,
193
- videoProps: videoProps
194
- };
195
- }
196
- function handleAbort(videoProps) {
197
- return {
198
- type: ABORT,
199
- videoProps: videoProps
200
- };
201
- }
202
- function handleEmptied(videoProps) {
203
- return {
204
- type: EMPTIED,
205
- videoProps: videoProps
206
- };
207
- }
208
- function handleStalled(videoProps) {
209
- return {
210
- type: STALLED,
211
- videoProps: videoProps
212
- };
213
- }
214
- function handleLoadedMetaData(videoProps) {
215
- return {
216
- type: LOADED_META_DATA,
217
- videoProps: videoProps
218
- };
219
- }
220
- function handleLoadedData(videoProps) {
221
- return {
222
- type: LOADED_DATA,
223
- videoProps: videoProps
224
- };
225
- }
226
- function handleResize(videoProps) {
227
- return {
228
- type: RESIZE,
229
- videoProps: videoProps
230
- };
231
- }
232
- function handleError(videoProps) {
233
- return {
234
- type: ERROR,
235
- videoProps: videoProps
236
- };
237
- }
238
- function handleSeekingTime(time) {
239
- return {
240
- type: SEEKING_TIME,
241
- time: time
242
- };
243
- }
244
- function handleEndSeeking(time) {
245
- return {
246
- type: END_SEEKING,
247
- time: time
248
- };
249
- }
250
- function activateTextTrack(textTrack) {
251
- return {
252
- type: ACTIVATE_TEXT_TRACK,
253
- textTrack: textTrack
254
- };
255
- }
256
- function handlePictureInPictureChange(isPictureInPicture) {
257
- return {
258
- type: PICTURE_IN_PICTURE_CHANGE,
259
- isPictureInPicture: isPictureInPicture
260
- };
261
- }
262
- function handleLoopChange(loop) {
263
- return {
264
- type: LOOP_CHANGE,
265
- loop: loop
266
- };
267
- }
268
- function handleTheaterModeChange(isTheater) {
269
- return {
270
- type: THEATER_MODE_CHANGE,
271
- isTheater: isTheater
272
- };
273
- }
274
- function handleQualityChange(quality) {
275
- return {
276
- type: QUALITY_CHANGE,
277
- quality: quality
278
- };
279
- }
280
-
281
- var videoActions = /*#__PURE__*/Object.freeze({
282
- LOAD_START: LOAD_START,
283
- CAN_PLAY: CAN_PLAY,
284
- WAITING: WAITING,
285
- CAN_PLAY_THROUGH: CAN_PLAY_THROUGH,
286
- PLAYING: PLAYING,
287
- PLAY: PLAY,
288
- PAUSE: PAUSE,
289
- END: END,
290
- SEEKING: SEEKING,
291
- SEEKED: SEEKED,
292
- SEEKING_TIME: SEEKING_TIME,
293
- END_SEEKING: END_SEEKING,
294
- DURATION_CHANGE: DURATION_CHANGE,
295
- TIME_UPDATE: TIME_UPDATE,
296
- VOLUME_CHANGE: VOLUME_CHANGE,
297
- PROGRESS_CHANGE: PROGRESS_CHANGE,
298
- RATE_CHANGE: RATE_CHANGE,
299
- SUSPEND: SUSPEND,
300
- ABORT: ABORT,
301
- EMPTIED: EMPTIED,
302
- STALLED: STALLED,
303
- LOADED_META_DATA: LOADED_META_DATA,
304
- LOADED_DATA: LOADED_DATA,
305
- RESIZE: RESIZE,
306
- ERROR: ERROR,
307
- ACTIVATE_TEXT_TRACK: ACTIVATE_TEXT_TRACK,
308
- PICTURE_IN_PICTURE_CHANGE: PICTURE_IN_PICTURE_CHANGE,
309
- LOOP_CHANGE: LOOP_CHANGE,
310
- THEATER_MODE_CHANGE: THEATER_MODE_CHANGE,
311
- QUALITY_CHANGE: QUALITY_CHANGE,
312
- handleLoadStart: handleLoadStart,
313
- handleCanPlay: handleCanPlay,
314
- handleWaiting: handleWaiting,
315
- handleCanPlayThrough: handleCanPlayThrough,
316
- handlePlaying: handlePlaying,
317
- handlePlay: handlePlay,
318
- handlePause: handlePause,
319
- handleEnd: handleEnd,
320
- handleSeeking: handleSeeking,
321
- handleSeeked: handleSeeked,
322
- handleDurationChange: handleDurationChange,
323
- handleTimeUpdate: handleTimeUpdate,
324
- handleVolumeChange: handleVolumeChange,
325
- handleProgressChange: handleProgressChange,
326
- handleRateChange: handleRateChange,
327
- handleSuspend: handleSuspend,
328
- handleAbort: handleAbort,
329
- handleEmptied: handleEmptied,
330
- handleStalled: handleStalled,
331
- handleLoadedMetaData: handleLoadedMetaData,
332
- handleLoadedData: handleLoadedData,
333
- handleResize: handleResize,
334
- handleError: handleError,
335
- handleSeekingTime: handleSeekingTime,
336
- handleEndSeeking: handleEndSeeking,
337
- activateTextTrack: activateTextTrack,
338
- handlePictureInPictureChange: handlePictureInPictureChange,
339
- handleLoopChange: handleLoopChange,
340
- handleTheaterModeChange: handleTheaterModeChange,
341
- handleQualityChange: handleQualityChange
342
- });
343
-
344
- // Lazily grab the document to avoid SSR "document is not defined" errors.
345
- var doc = typeof document !== 'undefined' ? document : null;
346
- var Fullscreen = /*#__PURE__*/function () {
347
- function Fullscreen() {}
348
- var _proto = Fullscreen.prototype;
349
- _proto.request = function request(elm) {
350
- if (elm.requestFullscreen) {
351
- elm.requestFullscreen();
352
- } else if (elm.webkitRequestFullscreen) {
353
- elm.webkitRequestFullscreen();
354
- } else if (elm.mozRequestFullScreen) {
355
- elm.mozRequestFullScreen();
356
- } else if (elm.msRequestFullscreen) {
357
- elm.msRequestFullscreen();
358
- }
359
- };
360
- _proto.exit = function exit() {
361
- if (!doc) {
362
- return;
363
- }
364
- if (doc.exitFullscreen) {
365
- doc.exitFullscreen();
366
- } else if (doc.webkitExitFullscreen) {
367
- doc.webkitExitFullscreen();
368
- } else if (doc.mozCancelFullScreen) {
369
- doc.mozCancelFullScreen();
370
- } else if (doc.msExitFullscreen) {
371
- doc.msExitFullscreen();
372
- }
373
- };
374
- _proto.addEventListener = function addEventListener(handler) {
375
- if (!doc) {
376
- return;
377
- }
378
- doc.addEventListener('fullscreenchange', handler);
379
- doc.addEventListener('webkitfullscreenchange', handler);
380
- doc.addEventListener('mozfullscreenchange', handler);
381
- doc.addEventListener('MSFullscreenChange', handler);
382
- };
383
- _proto.removeEventListener = function removeEventListener(handler) {
384
- if (!doc) {
385
- return;
386
- }
387
- doc.removeEventListener('fullscreenchange', handler);
388
- doc.removeEventListener('webkitfullscreenchange', handler);
389
- doc.removeEventListener('mozfullscreenchange', handler);
390
- doc.removeEventListener('MSFullscreenChange', handler);
391
- };
392
- _createClass(Fullscreen, [{
393
- key: "isFullscreen",
394
- get: function get() {
395
- if (!doc) {
396
- return null;
397
- }
398
- return doc.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement;
399
- }
400
- }, {
401
- key: "enabled",
402
- get: function get() {
403
- if (!doc) {
404
- return false;
405
- }
406
- return doc.fullscreenEnabled || doc.webkitFullscreenEnabled || doc.mozFullScreenEnabled || doc.msFullscreenEnabled;
407
- }
408
- }]);
409
- return Fullscreen;
410
- }();
411
- var fullscreen = new Fullscreen();
412
-
413
- /**
414
-
415
- * Copyright (c) 2016 Video-React contributors
416
- * Copyright (c) 2025 ZingMe.Vn
417
- *
418
- * This source code is licensed under the MIT license found in the
419
- * LICENSE file in the root directory of this source tree.
420
- */
421
- var OPERATE = 'video-react-player/OPERATE';
422
- var FULLSCREEN_CHANGE = 'video-react-player/FULLSCREEN_CHANGE';
423
- var PLAYER_ACTIVATE = 'video-react-player/PLAYER_ACTIVATE';
424
- var USER_ACTIVATE = 'video-react-player/USER_ACTIVATE';
425
- function handleFullscreenChange(isFullscreen) {
426
- return {
427
- type: FULLSCREEN_CHANGE,
428
- isFullscreen: isFullscreen
429
- };
430
- }
431
- function activate(activity) {
432
- return {
433
- type: PLAYER_ACTIVATE,
434
- activity: activity
435
- };
436
- }
437
- function userActivate(activity) {
438
- return {
439
- type: USER_ACTIVATE,
440
- activity: activity
441
- };
442
- }
443
- function play(operation) {
444
- var _this$video;
445
- if (operation === void 0) {
446
- operation = {
447
- action: 'play',
448
- source: ''
449
- };
450
- }
451
- (_this$video = this.video) === null || _this$video === void 0 ? void 0 : _this$video.play();
452
- return {
453
- type: OPERATE,
454
- operation: operation
455
- };
456
- }
457
- function pause(operation) {
458
- var _this$video2;
459
- if (operation === void 0) {
460
- operation = {
461
- action: 'pause',
462
- source: ''
463
- };
464
- }
465
- (_this$video2 = this.video) === null || _this$video2 === void 0 ? void 0 : _this$video2.pause();
466
- return {
467
- type: OPERATE,
468
- operation: operation
469
- };
470
- }
471
- function togglePlay(operation) {
472
- var _this$video3;
473
- if (operation === void 0) {
474
- operation = {
475
- action: 'toggle-play',
476
- source: ''
477
- };
478
- }
479
- (_this$video3 = this.video) === null || _this$video3 === void 0 ? void 0 : _this$video3.togglePlay();
480
- return {
481
- type: OPERATE,
482
- operation: operation
483
- };
484
- }
485
-
486
- // seek video by time
487
- function seek(time, operation) {
488
- var _this$video4;
489
- if (operation === void 0) {
490
- operation = {
491
- action: 'seek',
492
- source: ''
493
- };
494
- }
495
- (_this$video4 = this.video) === null || _this$video4 === void 0 ? void 0 : _this$video4.seek(time);
496
- return {
497
- type: OPERATE,
498
- operation: operation
499
- };
500
- }
501
-
502
- // jump forward x seconds
503
- function forward(seconds, operation) {
504
- var _this$video5;
505
- if (operation === void 0) {
506
- operation = {
507
- action: "forward-" + seconds,
508
- source: ''
509
- };
510
- }
511
- (_this$video5 = this.video) === null || _this$video5 === void 0 ? void 0 : _this$video5.forward(seconds);
512
- return {
513
- type: OPERATE,
514
- operation: operation
515
- };
516
- }
517
-
518
- // jump back x seconds
519
- function replay(seconds, operation) {
520
- var _this$video6;
521
- if (operation === void 0) {
522
- operation = {
523
- action: "replay-" + seconds,
524
- source: ''
525
- };
526
- }
527
- (_this$video6 = this.video) === null || _this$video6 === void 0 ? void 0 : _this$video6.replay(seconds);
528
- return {
529
- type: OPERATE,
530
- operation: operation
531
- };
532
- }
533
- function changeRate(rate, operation) {
534
- if (operation === void 0) {
535
- operation = {
536
- action: 'change-rate',
537
- source: ''
538
- };
539
- }
540
- if (this.video) {
541
- this.video.playbackRate = rate;
542
- }
543
- return {
544
- type: OPERATE,
545
- operation: operation
546
- };
547
- }
548
- function changeVolume(volume, operation) {
549
- if (operation === void 0) {
550
- operation = {
551
- action: 'change-volume',
552
- source: ''
553
- };
554
- }
555
- var v = volume;
556
- if (volume < 0) {
557
- v = 0;
558
- }
559
- if (volume > 1) {
560
- v = 1;
561
- }
562
- if (this.video) {
563
- this.video.volume = v;
564
- }
565
- return {
566
- type: OPERATE,
567
- operation: operation
568
- };
569
- }
570
- function mute(muted, operation) {
571
- if (operation === void 0) {
572
- operation = {
573
- action: muted ? 'muted' : 'unmuted',
574
- source: ''
575
- };
576
- }
577
- if (this.video) {
578
- this.video.muted = muted;
579
- }
580
- return {
581
- type: OPERATE,
582
- operation: operation
583
- };
584
- }
585
- function toggleFullscreen(player) {
586
- if (fullscreen.enabled) {
587
- if (fullscreen.isFullscreen) {
588
- fullscreen.exit();
589
- } else if (this.rootElement) {
590
- fullscreen.request(this.rootElement);
591
- }
592
- return {
593
- type: OPERATE,
594
- operation: {
595
- action: 'toggle-fullscreen',
596
- source: ''
597
- }
598
- };
599
- }
600
- return {
601
- type: FULLSCREEN_CHANGE,
602
- isFullscreen: !player.isFullscreen
603
- };
604
- }
605
- function togglePictureInPicture() {
606
- var next = !this.store.getState().player.isPictureInPicture;
607
- return handlePictureInPictureChange(next);
608
- }
609
- function changeQuality(quality) {
610
- return handleQualityChange(quality);
611
- }
612
- function takeScreenshot() {
613
- return {
614
- type: OPERATE,
615
- operation: {
616
- action: 'screenshot',
617
- source: 'control'
618
- }
619
- };
620
- }
621
- function toggleTheaterMode(isTheater) {
622
- return handleTheaterModeChange(isTheater);
623
- }
624
-
625
- var playerActions = /*#__PURE__*/Object.freeze({
626
- OPERATE: OPERATE,
627
- FULLSCREEN_CHANGE: FULLSCREEN_CHANGE,
628
- PLAYER_ACTIVATE: PLAYER_ACTIVATE,
629
- USER_ACTIVATE: USER_ACTIVATE,
630
- handleFullscreenChange: handleFullscreenChange,
631
- activate: activate,
632
- userActivate: userActivate,
633
- play: play,
634
- pause: pause,
635
- togglePlay: togglePlay,
636
- seek: seek,
637
- forward: forward,
638
- replay: replay,
639
- changeRate: changeRate,
640
- changeVolume: changeVolume,
641
- mute: mute,
642
- toggleFullscreen: toggleFullscreen,
643
- togglePictureInPicture: togglePictureInPicture,
644
- changeQuality: changeQuality,
645
- takeScreenshot: takeScreenshot,
646
- toggleTheaterMode: toggleTheaterMode
647
- });
648
-
649
- var initialState = {
650
- currentSrc: null,
651
- duration: 0,
652
- currentTime: 0,
653
- seekingTime: 0,
654
- buffered: null,
655
- textTracks: null,
656
- waiting: false,
657
- seeking: false,
658
- paused: true,
659
- autoPaused: false,
660
- ended: false,
661
- playbackRate: 1,
662
- muted: false,
663
- volume: 1,
664
- readyState: 0,
665
- networkState: 0,
666
- videoWidth: 0,
667
- videoHeight: 0,
668
- hasStarted: false,
669
- userActivity: true,
670
- isActive: false,
671
- isFullscreen: false,
672
- isPictureInPicture: false,
673
- loop: false,
674
- isTheater: false,
675
- quality: 'auto',
676
- activeTextTrack: null
677
- };
678
- function player(state, action) {
679
- if (state === void 0) {
680
- state = initialState;
681
- }
682
- switch (action.type) {
683
- case USER_ACTIVATE:
684
- return _extends({}, state, {
685
- userActivity: action.activity
686
- });
687
- case PLAYER_ACTIVATE:
688
- return _extends({}, state, {
689
- isActive: action.activity
690
- });
691
- case FULLSCREEN_CHANGE:
692
- return _extends({}, state, {
693
- isFullscreen: !!action.isFullscreen
694
- });
695
- case SEEKING_TIME:
696
- return _extends({}, state, {
697
- seekingTime: action.time
698
- });
699
- case END_SEEKING:
700
- return _extends({}, state, {
701
- seekingTime: 0
702
- });
703
- case LOAD_START:
704
- return _extends({}, state, action.videoProps, {
705
- hasStarted: false,
706
- ended: false
707
- });
708
- case CAN_PLAY:
709
- return _extends({}, state, action.videoProps, {
710
- waiting: false
711
- });
712
- case WAITING:
713
- return _extends({}, state, action.videoProps, {
714
- waiting: true
715
- });
716
- case CAN_PLAY_THROUGH:
717
- case PLAYING:
718
- return _extends({}, state, action.videoProps, {
719
- waiting: false
720
- });
721
- case PLAY:
722
- return _extends({}, state, action.videoProps, {
723
- ended: false,
724
- paused: false,
725
- autoPaused: false,
726
- waiting: false,
727
- hasStarted: true
728
- });
729
- case PAUSE:
730
- return _extends({}, state, action.videoProps, {
731
- paused: true
732
- });
733
- case END:
734
- return _extends({}, state, action.videoProps, {
735
- ended: true
736
- });
737
- case SEEKING:
738
- return _extends({}, state, action.videoProps, {
739
- seeking: true
740
- });
741
- case SEEKED:
742
- return _extends({}, state, action.videoProps, {
743
- seeking: false
744
- });
745
- case ERROR:
746
- return _extends({}, state, action.videoProps, {
747
- error: 'UNKNOWN ERROR',
748
- ended: true
749
- });
750
- case DURATION_CHANGE:
751
- case TIME_UPDATE:
752
- case VOLUME_CHANGE:
753
- case PROGRESS_CHANGE:
754
- case RATE_CHANGE:
755
- case SUSPEND:
756
- case ABORT:
757
- case EMPTIED:
758
- case STALLED:
759
- case LOADED_META_DATA:
760
- case LOADED_DATA:
761
- case RESIZE:
762
- return _extends({}, state, action.videoProps);
763
- case ACTIVATE_TEXT_TRACK:
764
- return _extends({}, state, {
765
- activeTextTrack: action.textTrack
766
- });
767
- case PICTURE_IN_PICTURE_CHANGE:
768
- return _extends({}, state, {
769
- isPictureInPicture: !!action.isPictureInPicture
770
- });
771
- case LOOP_CHANGE:
772
- return _extends({}, state, {
773
- loop: !!action.loop
774
- });
775
- case THEATER_MODE_CHANGE:
776
- return _extends({}, state, {
777
- isTheater: !!action.isTheater
778
- });
779
- case QUALITY_CHANGE:
780
- return _extends({}, state, {
781
- quality: action.quality || 'auto'
782
- });
783
- default:
784
- return state;
785
- }
786
- }
787
-
788
- var initialState$1 = {
789
- count: 0,
790
- operation: {
791
- action: '',
792
- source: ''
793
- }
794
- };
795
- function operation(state, action) {
796
- if (state === void 0) {
797
- state = initialState$1;
798
- }
799
- switch (action.type) {
800
- case OPERATE:
801
- return _extends({}, state, {
802
- count: state.count + 1,
803
- operation: _extends({}, state.operation, action.operation)
804
- });
805
- default:
806
- return state;
807
- }
808
- }
809
-
810
- function reducer(state, action) {
811
- return {
812
- player: player(state === null || state === void 0 ? void 0 : state.player, action),
813
- operation: operation(state === null || state === void 0 ? void 0 : state.operation, action)
814
- };
815
- }
816
- var playerReducer = player;
817
- var operationReducer = operation;
818
-
819
- var Manager = /*#__PURE__*/function () {
820
- function Manager(store) {
821
- this.store = void 0;
822
- this.video = void 0;
823
- this.rootElement = void 0;
824
- this.boundActions = void 0;
825
- this.store = store || createStore(reducer);
826
- this.video = null;
827
- this.rootElement = null;
828
- this.boundActions = undefined;
829
- }
830
- var _proto = Manager.prototype;
831
- _proto.getActions = function getActions() {
832
- var _this = this;
833
- if (this.boundActions) {
834
- return this.boundActions;
835
- }
836
- var actions = _extends({}, playerActions, videoActions);
837
- var bound = {};
838
- Object.keys(actions).forEach(function (key) {
839
- var creator = actions[key];
840
- if (typeof creator !== 'function') {
841
- return;
842
- }
843
- bound[key] = function () {
844
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
845
- args[_key] = arguments[_key];
846
- }
847
- var action = creator.apply(_this, args);
848
- if (typeof action !== 'undefined') {
849
- _this.store.dispatch(action);
850
- }
851
- };
852
- });
853
- this.boundActions = bound;
854
- return this.boundActions;
855
- };
856
- _proto.getState = function getState() {
857
- return this.store.getState();
858
- };
859
- _proto.subscribeToStateChange = function subscribeToStateChange(listener, getState) {
860
- if (getState === void 0) {
861
- getState = this.getState.bind(this);
862
- }
863
- var prevState = getState();
864
- var handleChange = function handleChange() {
865
- var state = getState();
866
- if (state === prevState) {
867
- return;
868
- }
869
- var prevStateCopy = prevState;
870
- prevState = state;
871
- listener(state, prevStateCopy);
872
- };
873
- return this.store.subscribe(handleChange);
874
- };
875
- _proto.subscribeToOperationStateChange = function subscribeToOperationStateChange(listener) {
876
- var _this2 = this;
877
- return this.subscribeToStateChange(listener, function () {
878
- return _this2.getState().operation;
879
- });
880
- };
881
- _proto.subscribeToPlayerStateChange = function subscribeToPlayerStateChange(listener) {
882
- var _this3 = this;
883
- return this.subscribeToStateChange(listener, function () {
884
- return _this3.getState().player;
885
- });
886
- };
887
- return Manager;
888
- }();
889
-
890
- // eslint-disable-next-line import/no-unresolved
891
- var BigPlayButton = /*#__PURE__*/function (_Component) {
892
- _inheritsLoose(BigPlayButton, _Component);
893
- function BigPlayButton(props, context) {
894
- var _this;
895
- _this = _Component.call(this, props, context) || this;
896
- _this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));
897
- return _this;
898
- }
899
- var _proto = BigPlayButton.prototype;
900
- _proto.componentDidMount = function componentDidMount() {};
901
- _proto.handleClick = function handleClick(event) {
902
- var _this$props$actions;
903
- event.preventDefault();
904
- (_this$props$actions = this.props.actions) === null || _this$props$actions === void 0 ? void 0 : _this$props$actions.play();
905
- };
906
- _proto.render = function render() {
907
- var _player$hasStarted;
908
- var _this$props = this.props,
909
- player = _this$props.player,
910
- position = _this$props.position;
911
- var positionClass = position === 'center' ? 'center' : 'left';
912
- var hasStarted = (_player$hasStarted = player === null || player === void 0 ? void 0 : player.hasStarted) !== null && _player$hasStarted !== void 0 ? _player$hasStarted : false;
913
- var hasSource = (player === null || player === void 0 ? void 0 : player.currentSrc) !== undefined && (player === null || player === void 0 ? void 0 : player.currentSrc) !== '';
914
- return React.createElement("button", {
915
- className: classNames('video-react-player-button', 'video-react-player-big-play-button', "video-react-player-big-play-button-" + positionClass, this.props.className, {
916
- // keep visible by default if player info is not provided
917
- 'big-play-button-hide': hasStarted || !hasSource
918
- }),
919
- type: "button",
920
- "aria-live": "polite",
921
- tabIndex: 0,
922
- onClick: this.handleClick
923
- }, React.createElement("span", {
924
- className: "video-react-player-control-text"
925
- }, "Play Video"));
926
- };
927
- return BigPlayButton;
928
- }(Component);
929
- BigPlayButton.defaultProps = {
930
- position: 'left'
931
- };
932
- BigPlayButton.displayName = 'BigPlayButton';
933
-
934
- function LoadingSpinner(_ref) {
935
- var player = _ref.player,
936
- className = _ref.className;
937
- if (player.error) {
938
- return null;
939
- }
940
- return React.createElement("div", {
941
- className: classNames('video-react-player-loading-spinner', className)
942
- });
943
- }
944
- LoadingSpinner.displayName = 'LoadingSpinner';
945
-
946
- function PosterImage(_ref) {
947
- var poster = _ref.poster,
948
- player = _ref.player,
949
- actions = _ref.actions,
950
- className = _ref.className;
951
- if (!poster || player.hasStarted) {
952
- return null;
953
- }
954
- return React.createElement("div", {
955
- className: classNames('video-react-player-poster', className),
956
- style: {
957
- backgroundImage: "url(\"" + poster + "\")"
958
- },
959
- onClick: function onClick() {
960
- if (player.paused) {
961
- actions.play();
962
- }
963
- }
964
- });
965
- }
966
- PosterImage.displayName = 'PosterImage';
967
-
968
- // NaN is the only value in javascript which is not equal to itself.
969
- // eslint-disable-next-line no-self-compare
970
- var isNaN = Number.isNaN || function (value) {
971
- return value !== value;
972
- };
973
-
974
- /**
975
- * @file format-time.js
976
- *
977
- * Format seconds as a time string, H:MM:SS or M:SS
978
- * Supplying a guide (in seconds) will force a number of leading zeros
979
- * to cover the length of the guide
980
- *
981
- * @param {Number} seconds Number of seconds to be turned into a string
982
- * @param {Number} guide Number (in seconds) to model the string after
983
- * @return {String} Time formatted as H:MM:SS or M:SS
984
- * @private
985
- * @function formatTime
986
- */
987
- function formatTime(seconds, guide) {
988
- if (seconds === void 0) {
989
- seconds = 0;
990
- }
991
- if (guide === void 0) {
992
- guide = seconds;
993
- }
994
- var s = Math.floor(seconds % 60);
995
- var m = Math.floor(seconds / 60 % 60);
996
- var h = Math.floor(seconds / 3600);
997
- var gm = Math.floor(guide / 60 % 60);
998
- var gh = Math.floor(guide / 3600);
999
-
1000
- // handle invalid times
1001
- if (isNaN(seconds) || seconds === Infinity) {
1002
- // '-' is false for all relational operators (e.g. <, >=) so this setting
1003
- // will add the minimum number of fields specified by the guide
1004
- h = 0;
1005
- m = 0;
1006
- s = 0;
1007
- }
1008
- var hasHours = h > 0 || gh > 0;
1009
- var hours = hasHours ? h + ":" : '';
1010
- var minutes = ((hasHours || gm >= 10) && m < 10 ? "0" + m : m) + ":";
1011
- var secondsString = s < 10 ? "0" + s : "" + s;
1012
- return "" + hours + minutes + secondsString;
1013
- }
1014
-
1015
- // Check if the element belongs to a video element
1016
- // only accept <source />, <track />,
1017
- // <MyComponent isVideoChild />
1018
- // elements
1019
- function isVideoChild(c) {
1020
- if (!React.isValidElement(c)) {
1021
- return false;
1022
- }
1023
- if (c.props && c.props.isVideoChild) {
1024
- return true;
1025
- }
1026
- return c.type === 'source' || c.type === 'track';
1027
- }
1028
- var find = function find(elements, func) {
1029
- return elements.find(func);
1030
- };
1031
-
1032
- // check if two components are the same type
1033
- var isTypeEqual = function isTypeEqual(component1, component2) {
1034
- var type1 = component1.type;
1035
- var type2 = component2.type;
1036
- if (typeof type1 === 'string' || typeof type2 === 'string') {
1037
- return type1 === type2;
1038
- }
1039
- if (typeof type1 === 'function' && typeof type2 === 'function') {
1040
- return type1.displayName === type2.displayName;
1041
- }
1042
- return false;
1043
- };
1044
-
1045
- // merge default children
1046
- // sort them by `order` property
1047
- // filter them by `disabled` property
1048
- function mergeAndSortChildren(defaultChildren, _children, _parentProps, defaultOrder) {
1049
- if (defaultOrder === void 0) {
1050
- defaultOrder = 1;
1051
- }
1052
- var children = React.Children.toArray(_children).filter(React.isValidElement);
1053
- var _order = _parentProps.order,
1054
- parentProps = _objectWithoutPropertiesLoose(_parentProps, ["order"]); // ignore order from parent
1055
- return children.filter(function (e) {
1056
- return !e.props.disabled;
1057
- }) // filter the disabled components
1058
- .concat(defaultChildren.filter(function (c) {
1059
- return !find(children, function (component) {
1060
- return isTypeEqual(component, c);
1061
- });
1062
- })).map(function (element) {
1063
- var defaultComponent = find(defaultChildren, function (c) {
1064
- return isTypeEqual(c, element);
1065
- });
1066
- var defaultProps = defaultComponent ? defaultComponent.props : {};
1067
- var props = _extends({}, parentProps, defaultProps, element.props);
1068
- return React.cloneElement(element, props, element.props.children);
1069
- }).sort(function (a, b) {
1070
- return (a.props.order || defaultOrder) - (b.props.order || defaultOrder);
1071
- });
1072
- }
1073
-
1074
- /**
1075
- * Temporary utility for generating the warnings
1076
- */
1077
- function deprecatedWarning(oldMethodCall, newMethodCall) {
1078
- // eslint-disable-next-line no-console
1079
- console.warn("WARNING: " + oldMethodCall + " will be deprecated soon! Please use " + newMethodCall + " instead.");
1080
- }
1081
- function throttle(callback, limit) {
1082
- var wait = false;
1083
- return function () {
1084
- if (!wait) {
1085
- callback.apply(void 0, arguments);
1086
- wait = true;
1087
- setTimeout(function () {
1088
- wait = false;
1089
- }, limit);
1090
- }
1091
- };
1092
- }
1093
- var mediaProperties = ['error', 'src', 'srcObject', 'currentSrc', 'crossOrigin', 'networkState', 'preload', 'buffered', 'readyState', 'seeking', 'currentTime', 'duration', 'paused', 'defaultPlaybackRate', 'playbackRate', 'played', 'seekable', 'ended', 'autoplay', 'loop', 'mediaGroup', 'controller', 'controls', 'volume', 'muted', 'defaultMuted', 'audioTracks', 'videoTracks', 'textTracks', 'width', 'height', 'videoWidth', 'videoHeight', 'poster'];
1094
-
1095
- var Video = forwardRef(function (props, ref) {
1096
- var actions = props.actions,
1097
- player = props.player,
1098
- children = props.children,
1099
- startTime = props.startTime,
1100
- loop = props.loop,
1101
- poster = props.poster,
1102
- preload = props.preload,
1103
- src = props.src,
1104
- autoPlay = props.autoPlay,
1105
- playsInline = props.playsInline,
1106
- muted = props.muted,
1107
- crossOrigin = props.crossOrigin,
1108
- videoId = props.videoId,
1109
- className = props.className,
1110
- onLoadStart = props.onLoadStart,
1111
- onWaiting = props.onWaiting,
1112
- onCanPlay = props.onCanPlay,
1113
- onCanPlayThrough = props.onCanPlayThrough,
1114
- onPlaying = props.onPlaying,
1115
- onEnded = props.onEnded,
1116
- onSeeking = props.onSeeking,
1117
- onSeeked = props.onSeeked,
1118
- onPlay = props.onPlay,
1119
- onPause = props.onPause,
1120
- onProgress = props.onProgress,
1121
- onDurationChange = props.onDurationChange,
1122
- onError = props.onError,
1123
- onSuspend = props.onSuspend,
1124
- onAbort = props.onAbort,
1125
- onEmptied = props.onEmptied,
1126
- onStalled = props.onStalled,
1127
- onLoadedMetadata = props.onLoadedMetadata,
1128
- onLoadedData = props.onLoadedData,
1129
- onTimeUpdate = props.onTimeUpdate,
1130
- onRateChange = props.onRateChange,
1131
- onVolumeChange = props.onVolumeChange,
1132
- onResize = props.onResize;
1133
- var videoRef = useRef(null);
1134
- var propsRef = useRef(props);
1135
- propsRef.current = props;
1136
- var _useReducer = useReducer(function (count) {
1137
- return count + 1;
1138
- }, 0),
1139
- forceRender = _useReducer[1];
1140
- useEffect(function () {
1141
- forceRender();
1142
- }, []);
1143
- var getVideoProperties = useCallback(function () {
1144
- var video = videoRef.current;
1145
- if (!video) {
1146
- return {};
1147
- }
1148
- return mediaProperties.reduce(function (acc, key) {
1149
- var videoKey = key;
1150
- acc[key] = video === null || video === void 0 ? void 0 : video[videoKey];
1151
- return acc;
1152
- }, {});
1153
- }, []);
1154
- var createVideoEventHandler = useCallback(function (dispatcher, callback) {
1155
- return function () {
1156
- dispatcher(getVideoProperties());
1157
- if (callback) {
1158
- callback.apply(void 0, arguments);
1159
- }
1160
- };
1161
- }, [getVideoProperties]);
1162
- var handleLoadStart = useMemo(function () {
1163
- return createVideoEventHandler(actions.handleLoadStart, onLoadStart);
1164
- }, [actions.handleLoadStart, onLoadStart, createVideoEventHandler]);
1165
- var handleWaiting = useMemo(function () {
1166
- return createVideoEventHandler(actions.handleWaiting, onWaiting);
1167
- }, [actions.handleWaiting, onWaiting, createVideoEventHandler]);
1168
- var handleCanPlay = useMemo(function () {
1169
- return createVideoEventHandler(actions.handleCanPlay, onCanPlay);
1170
- }, [actions.handleCanPlay, onCanPlay, createVideoEventHandler]);
1171
- var handleCanPlayThrough = useMemo(function () {
1172
- return createVideoEventHandler(actions.handleCanPlayThrough, onCanPlayThrough);
1173
- }, [actions.handleCanPlayThrough, onCanPlayThrough, createVideoEventHandler]);
1174
- var handlePlaying = useMemo(function () {
1175
- return createVideoEventHandler(actions.handlePlaying, onPlaying);
1176
- }, [actions.handlePlaying, onPlaying, createVideoEventHandler]);
1177
- var handlePlay = useMemo(function () {
1178
- return createVideoEventHandler(actions.handlePlay, onPlay);
1179
- }, [actions.handlePlay, onPlay, createVideoEventHandler]);
1180
- var handlePause = useMemo(function () {
1181
- return createVideoEventHandler(actions.handlePause, onPause);
1182
- }, [actions.handlePause, onPause, createVideoEventHandler]);
1183
- var handleDurationChange = useMemo(function () {
1184
- return createVideoEventHandler(actions.handleDurationChange, onDurationChange);
1185
- }, [actions.handleDurationChange, onDurationChange, createVideoEventHandler]);
1186
- var handleTimeUpdate = useMemo(function () {
1187
- return createVideoEventHandler(actions.handleTimeUpdate, onTimeUpdate);
1188
- }, [actions.handleTimeUpdate, onTimeUpdate, createVideoEventHandler]);
1189
- var handleRateChange = useMemo(function () {
1190
- return createVideoEventHandler(actions.handleRateChange, onRateChange);
1191
- }, [actions.handleRateChange, onRateChange, createVideoEventHandler]);
1192
- var handleVolumeChange = useMemo(function () {
1193
- return createVideoEventHandler(actions.handleVolumeChange, onVolumeChange);
1194
- }, [actions.handleVolumeChange, onVolumeChange, createVideoEventHandler]);
1195
- var handleSuspend = useMemo(function () {
1196
- return createVideoEventHandler(actions.handleSuspend, onSuspend);
1197
- }, [actions.handleSuspend, onSuspend, createVideoEventHandler]);
1198
- var handleAbort = useMemo(function () {
1199
- return createVideoEventHandler(actions.handleAbort, onAbort);
1200
- }, [actions.handleAbort, onAbort, createVideoEventHandler]);
1201
- var handleEmptied = useMemo(function () {
1202
- return createVideoEventHandler(actions.handleEmptied, onEmptied);
1203
- }, [actions.handleEmptied, onEmptied, createVideoEventHandler]);
1204
- var handleStalled = useMemo(function () {
1205
- return createVideoEventHandler(actions.handleStalled, onStalled);
1206
- }, [actions.handleStalled, onStalled, createVideoEventHandler]);
1207
- var handleResize = useMemo(function () {
1208
- return createVideoEventHandler(actions.handleResize, onResize);
1209
- }, [actions.handleResize, onResize, createVideoEventHandler]);
1210
- var throttledProgress = useMemo(function () {
1211
- return throttle(function () {
1212
- actions.handleProgressChange(getVideoProperties());
1213
- }, 250);
1214
- }, [actions, getVideoProperties]);
1215
- var handleProgress = useCallback(function (event) {
1216
- throttledProgress();
1217
- onProgress === null || onProgress === void 0 ? void 0 : onProgress(event);
1218
- }, [onProgress, throttledProgress]);
1219
- var handleError = useCallback(function (event) {
1220
- actions.handleError(getVideoProperties());
1221
- onError === null || onError === void 0 ? void 0 : onError(event);
1222
- }, [actions, getVideoProperties, onError]);
1223
- var handleSeeking = useCallback(function (event) {
1224
- actions.handleSeeking(getVideoProperties());
1225
- onSeeking === null || onSeeking === void 0 ? void 0 : onSeeking(event);
1226
- }, [actions, getVideoProperties, onSeeking]);
1227
- var handleSeeked = useCallback(function (event) {
1228
- actions.handleSeeked(getVideoProperties());
1229
- onSeeked === null || onSeeked === void 0 ? void 0 : onSeeked(event);
1230
- }, [actions, getVideoProperties, onSeeked]);
1231
- var handleEnd = useCallback(function (event) {
1232
- var video = videoRef.current;
1233
- if (loop && video) {
1234
- video.currentTime = 0;
1235
- var promise = video.play();
1236
- promise === null || promise === void 0 ? void 0 : promise.catch(function () {});
1237
- } else if (video && !player.paused) {
1238
- video.pause();
1239
- }
1240
- actions.handleEnd(getVideoProperties());
1241
- onEnded === null || onEnded === void 0 ? void 0 : onEnded(event);
1242
- }, [actions, getVideoProperties, loop, onEnded, player.paused]);
1243
- var handleLoadedMetadata = useCallback(function (event) {
1244
- var video = videoRef.current;
1245
- if (typeof startTime === 'number' && startTime > 0 && video) {
1246
- video.currentTime = startTime;
1247
- }
1248
- actions.handleLoadedMetaData(getVideoProperties());
1249
- onLoadedMetadata === null || onLoadedMetadata === void 0 ? void 0 : onLoadedMetadata(event);
1250
- }, [actions, getVideoProperties, onLoadedMetadata, startTime]);
1251
- var handleLoadedData = useCallback(function (event) {
1252
- actions.handleLoadedData(getVideoProperties());
1253
- onLoadedData === null || onLoadedData === void 0 ? void 0 : onLoadedData(event);
1254
- }, [actions, getVideoProperties, onLoadedData]);
1255
- var handleTextTrackChange = useCallback(function () {
1256
- var video = videoRef.current;
1257
- if (video && video.textTracks) {
1258
- var activeTextTrack = Array.from(video.textTracks).find(function (textTrack) {
1259
- return textTrack.mode === 'showing';
1260
- });
1261
- if (activeTextTrack !== player.activeTextTrack) {
1262
- actions.activateTextTrack(activeTextTrack !== null && activeTextTrack !== void 0 ? activeTextTrack : null);
1263
- }
1264
- }
1265
- }, [actions, player.activeTextTrack]);
1266
- useEffect(function () {
1267
- var video = videoRef.current;
1268
- if (!video) {
1269
- return undefined;
1270
- }
1271
- if (video.textTracks) {
1272
- video.textTracks.onaddtrack = handleTextTrackChange;
1273
- video.textTracks.onremovetrack = handleTextTrackChange;
1274
- }
1275
- var handleEnterPiP = function handleEnterPiP() {
1276
- return actions.handlePictureInPictureChange(true);
1277
- };
1278
- var handleLeavePiP = function handleLeavePiP() {
1279
- return actions.handlePictureInPictureChange(false);
1280
- };
1281
- video.addEventListener('enterpictureinpicture', handleEnterPiP);
1282
- video.addEventListener('leavepictureinpicture', handleLeavePiP);
1283
- return function () {
1284
- video.removeEventListener('enterpictureinpicture', handleEnterPiP);
1285
- video.removeEventListener('leavepictureinpicture', handleLeavePiP);
1286
- };
1287
- }, [actions, handleTextTrackChange]);
1288
- var apiRef = useRef();
1289
- if (!apiRef.current) {
1290
- var getVideo = function getVideo() {
1291
- return videoRef.current;
1292
- };
1293
- apiRef.current = {
1294
- play: function play() {
1295
- var _getVideo;
1296
- var promise = (_getVideo = getVideo()) === null || _getVideo === void 0 ? void 0 : _getVideo.play();
1297
- if (promise && typeof promise.catch === 'function') {
1298
- promise.catch(function () {});
1299
- }
1300
- },
1301
- pause: function pause() {
1302
- var video = getVideo();
1303
- var promiseLike = video === null || video === void 0 ? void 0 : video.pause();
1304
- if (typeof promiseLike === 'object' && promiseLike !== null && 'catch' in promiseLike && typeof promiseLike.catch === 'function') {
1305
- promiseLike.catch(function () {});
1306
- }
1307
- },
1308
- load: function load() {
1309
- var _getVideo2;
1310
- (_getVideo2 = getVideo()) === null || _getVideo2 === void 0 ? void 0 : _getVideo2.load();
1311
- },
1312
- addTextTrack: function addTextTrack(kind, label, language) {
1313
- var video = getVideo();
1314
- return video ? video.addTextTrack(kind, label, language) : {};
1315
- },
1316
- canPlayType: function canPlayType() {
1317
- var _getVideo$canPlayType, _getVideo3;
1318
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1319
- args[_key] = arguments[_key];
1320
- }
1321
- return (_getVideo$canPlayType = (_getVideo3 = getVideo()) === null || _getVideo3 === void 0 ? void 0 : _getVideo3.canPlayType.apply(_getVideo3, args)) !== null && _getVideo$canPlayType !== void 0 ? _getVideo$canPlayType : '';
1322
- },
1323
- togglePlay: function togglePlay() {
1324
- var video = getVideo();
1325
- if (!video) {
1326
- return;
1327
- }
1328
- if (video.paused) {
1329
- var promise = video.play();
1330
- if (promise && typeof promise.catch === 'function') {
1331
- promise.catch(function () {});
1332
- }
1333
- } else {
1334
- var promiseLike = video.pause();
1335
- if (typeof promiseLike === 'object' && promiseLike !== null && 'catch' in promiseLike && typeof promiseLike.catch === 'function') {
1336
- promiseLike.catch(function () {});
1337
- }
1338
- }
1339
- },
1340
- seek: function seek(time) {
1341
- var video = getVideo();
1342
- if (!video) {
1343
- return;
1344
- }
1345
- try {
1346
- video.currentTime = time;
1347
- } catch (err) {
1348
- // ignore
1349
- }
1350
- },
1351
- forward: function forward(seconds) {
1352
- var video = getVideo();
1353
- if (video) {
1354
- var _apiRef$current;
1355
- (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.seek(video.currentTime + seconds);
1356
- }
1357
- },
1358
- replay: function replay(seconds) {
1359
- var _apiRef$current2;
1360
- (_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 ? void 0 : _apiRef$current2.forward(-seconds);
1361
- },
1362
- toggleFullscreen: function toggleFullscreen() {
1363
- propsRef.current.actions.toggleFullscreen(propsRef.current.player);
1364
- },
1365
- get playbackRate() {
1366
- var _getVideo$playbackRat, _getVideo4;
1367
- return (_getVideo$playbackRat = (_getVideo4 = getVideo()) === null || _getVideo4 === void 0 ? void 0 : _getVideo4.playbackRate) !== null && _getVideo$playbackRat !== void 0 ? _getVideo$playbackRat : 1;
1368
- },
1369
- set playbackRate(rate) {
1370
- var video = getVideo();
1371
- if (video) {
1372
- video.playbackRate = rate;
1373
- }
1374
- },
1375
- get muted() {
1376
- var _getVideo$muted, _getVideo5;
1377
- return (_getVideo$muted = (_getVideo5 = getVideo()) === null || _getVideo5 === void 0 ? void 0 : _getVideo5.muted) !== null && _getVideo$muted !== void 0 ? _getVideo$muted : false;
1378
- },
1379
- set muted(value) {
1380
- var video = getVideo();
1381
- if (video) {
1382
- video.muted = value;
1383
- }
1384
- },
1385
- get volume() {
1386
- var _getVideo$volume, _getVideo6;
1387
- return (_getVideo$volume = (_getVideo6 = getVideo()) === null || _getVideo6 === void 0 ? void 0 : _getVideo6.volume) !== null && _getVideo$volume !== void 0 ? _getVideo$volume : 1;
1388
- },
1389
- set volume(value) {
1390
- var video = getVideo();
1391
- if (video) {
1392
- video.volume = Math.max(0, Math.min(1, value));
1393
- }
1394
- },
1395
- get videoWidth() {
1396
- var _getVideo$videoWidth, _getVideo7;
1397
- return (_getVideo$videoWidth = (_getVideo7 = getVideo()) === null || _getVideo7 === void 0 ? void 0 : _getVideo7.videoWidth) !== null && _getVideo$videoWidth !== void 0 ? _getVideo$videoWidth : 0;
1398
- },
1399
- get videoHeight() {
1400
- var _getVideo$videoHeight, _getVideo8;
1401
- return (_getVideo$videoHeight = (_getVideo8 = getVideo()) === null || _getVideo8 === void 0 ? void 0 : _getVideo8.videoHeight) !== null && _getVideo$videoHeight !== void 0 ? _getVideo$videoHeight : 0;
1402
- },
1403
- get video() {
1404
- return getVideo();
1405
- }
1406
- };
1407
- }
1408
- useImperativeHandle(ref, function () {
1409
- return apiRef.current;
1410
- }, []);
1411
- var renderedChildren = useMemo(function () {
1412
- if (!apiRef.current) {
1413
- return null;
1414
- }
1415
- var sharedProps = _extends({}, props, {
1416
- video: apiRef.current
1417
- });
1418
- return React.Children.toArray(children).filter(isVideoChild).map(function (child) {
1419
- var element = child;
1420
- if (typeof element.type === 'string') {
1421
- if (element.type === 'source') {
1422
- var childProps = _extends({}, element.props);
1423
- var originalOnError = childProps.onError;
1424
- childProps.onError = function () {
1425
- if (originalOnError) {
1426
- originalOnError.apply(void 0, arguments);
1427
- }
1428
- actions.handleError(getVideoProperties());
1429
- };
1430
- return React.cloneElement(element, childProps);
1431
- }
1432
- return element;
1433
- }
1434
- return React.cloneElement(element, sharedProps);
1435
- });
1436
- }, [actions, children, getVideoProperties, props]);
1437
- return React.createElement("video", {
1438
- className: classNames('video-react-player-video', className),
1439
- id: videoId,
1440
- crossOrigin: crossOrigin,
1441
- ref: videoRef,
1442
- muted: muted,
1443
- preload: preload,
1444
- loop: loop,
1445
- playsInline: playsInline,
1446
- autoPlay: autoPlay,
1447
- poster: poster,
1448
- src: src,
1449
- onLoadStart: handleLoadStart,
1450
- onWaiting: handleWaiting,
1451
- onCanPlay: handleCanPlay,
1452
- onCanPlayThrough: handleCanPlayThrough,
1453
- onPlaying: handlePlaying,
1454
- onEnded: handleEnd,
1455
- onSeeking: handleSeeking,
1456
- onSeeked: handleSeeked,
1457
- onPlay: handlePlay,
1458
- onPause: handlePause,
1459
- onProgress: handleProgress,
1460
- onDurationChange: handleDurationChange,
1461
- onError: handleError,
1462
- onSuspend: handleSuspend,
1463
- onAbort: handleAbort,
1464
- onEmptied: handleEmptied,
1465
- onStalled: handleStalled,
1466
- onLoadedMetadata: handleLoadedMetadata,
1467
- onLoadedData: handleLoadedData,
1468
- onTimeUpdate: handleTimeUpdate,
1469
- onRateChange: handleRateChange,
1470
- onVolumeChange: handleVolumeChange,
1471
- onResize: handleResize,
1472
- tabIndex: -1
1473
- }, renderedChildren);
1474
- });
1475
- Video.displayName = 'Video';
1476
-
1477
- var Bezel = /*#__PURE__*/function (_Component) {
1478
- _inheritsLoose(Bezel, _Component);
1479
- function Bezel(props, context) {
1480
- var _this;
1481
- _this = _Component.call(this, props, context) || this;
1482
- _this.timer = null;
1483
- props.manager.subscribeToOperationStateChange(_this.handleStateChange.bind(_assertThisInitialized(_this)));
1484
- _this.state = {
1485
- hidden: true,
1486
- operation: {
1487
- action: '',
1488
- source: ''
1489
- },
1490
- count: 0
1491
- };
1492
- return _this;
1493
- }
1494
- var _proto = Bezel.prototype;
1495
- _proto.handleStateChange = function handleStateChange(state, prevState) {
1496
- var _this2 = this;
1497
- if (state.count !== prevState.count && state.operation.source === 'shortcut') {
1498
- if (this.timer) {
1499
- // previous animation is not finished
1500
- clearTimeout(this.timer); // cancel it
1501
- this.timer = null;
1502
- }
1503
-
1504
- // show it
1505
- // update operation
1506
- this.setState({
1507
- hidden: false,
1508
- count: state.count,
1509
- operation: state.operation
1510
- });
1511
-
1512
- // hide it after 0.5s
1513
- this.timer = window.setTimeout(function () {
1514
- _this2.setState({
1515
- hidden: true
1516
- });
1517
- _this2.timer = null;
1518
- }, 500);
1519
- }
1520
- };
1521
- _proto.render = function render() {
1522
- // only displays for shortcut so far
1523
- if (this.state.operation.source !== 'shortcut') {
1524
- return null;
1525
- }
1526
- var style = this.state.hidden ? {
1527
- display: 'none'
1528
- } : null;
1529
- return React.createElement("div", {
1530
- className: classNames({
1531
- 'video-react-player-bezel': true,
1532
- 'video-react-player-bezel-animation': this.state.count % 2 === 0,
1533
- 'video-react-player-bezel-animation-alt': this.state.count % 2 === 1
1534
- }, this.props.className),
1535
- style: style,
1536
- role: "status",
1537
- "aria-label": this.state.operation.action
1538
- }, React.createElement("div", {
1539
- className: classNames('video-react-player-bezel-icon', "video-react-player-bezel-icon-" + this.state.operation.action)
1540
- }));
1541
- };
1542
- return Bezel;
1543
- }(Component);
1544
- Bezel.displayName = 'Bezel';
1545
-
1546
- /**
1547
- * Offset Left
1548
- * getBoundingClientRect technique from
1549
- * John Resig http://ejohn.org/blog/getboundingclientrect-is-awesome/
1550
- *
1551
- * @function findElPosition
1552
- * @param {ReactNodeRef} el React Node ref from which to get offset
1553
- * @return {Object}
1554
- */
1555
- function findElPosition(el) {
1556
- var box;
1557
- if (el.getBoundingClientRect && el.parentNode) {
1558
- box = el.getBoundingClientRect();
1559
- }
1560
- if (!box) {
1561
- return {
1562
- left: 0,
1563
- top: 0
1564
- };
1565
- }
1566
- var _document = document,
1567
- body = _document.body,
1568
- docEl = _document.documentElement;
1569
- var clientLeft = docEl.clientLeft || body.clientLeft || 0;
1570
- var scrollLeft = window.pageXOffset || body.scrollLeft;
1571
- var left = box.left + scrollLeft - clientLeft;
1572
- var clientTop = docEl.clientTop || body.clientTop || 0;
1573
- var scrollTop = window.pageYOffset || body.scrollTop;
1574
- var top = box.top + scrollTop - clientTop;
1575
-
1576
- // Android sometimes returns slightly off decimal values, so need to round
1577
- return {
1578
- left: Math.round(left),
1579
- top: Math.round(top)
1580
- };
1581
- }
1582
-
1583
- /**
1584
- * Get pointer position in a React Node ref
1585
- * Returns an object with x and y coordinates.
1586
- * The base on the coordinates are the bottom left of the element.
1587
- *
1588
- * @function getPointerPosition
1589
- * @param {ReactNodeRef} el React Node ref on which to get the pointer position on
1590
- * @param {Event} event Event object
1591
- * @return {Object} This object will have x and y coordinates corresponding to the mouse position
1592
- */
1593
- function getPointerPosition(el, event) {
1594
- var position = {};
1595
- var box = findElPosition(el);
1596
- var boxW = el.offsetWidth;
1597
- var boxH = el.offsetHeight;
1598
- var boxY = box.top;
1599
- var boxX = box.left;
1600
- var evtPageY = event.pageY;
1601
- var evtPageX = event.pageX;
1602
- if ('changedTouches' in event && event.changedTouches.length) {
1603
- evtPageX = event.changedTouches[0].pageX;
1604
- evtPageY = event.changedTouches[0].pageY;
1605
- }
1606
- position.y = Math.max(0, Math.min(1, (boxY - evtPageY + boxH) / boxH));
1607
- position.x = Math.max(0, Math.min(1, (evtPageX - boxX) / boxW));
1608
- return position;
1609
- }
1610
-
1611
- // focus an element
1612
- function focusNode(reactNode) {
1613
- if (reactNode && reactNode.focus) {
1614
- reactNode.focus();
1615
- }
1616
- }
1617
-
1618
- // check if an element has a class name
1619
- function hasClass(elm, cls) {
1620
- var classes = elm.className.split(' ');
1621
- for (var i = 0; i < classes.length; i += 1) {
1622
- if (classes[i].toLowerCase() === cls.toLowerCase()) {
1623
- return true;
1624
- }
1625
- }
1626
- return false;
1627
- }
1628
-
1629
- var Shortcut = /*#__PURE__*/function (_Component) {
1630
- _inheritsLoose(Shortcut, _Component);
1631
- function Shortcut(props, context) {
1632
- var _this;
1633
- _this = _Component.call(this, props, context) || this;
1634
- _this.defaultShortcuts = void 0;
1635
- _this.shortcuts = [];
1636
- _this.defaultShortcuts = [{
1637
- keyCode: 32,
1638
- // spacebar
1639
- handle: _this.togglePlay
1640
- }, {
1641
- keyCode: 75,
1642
- // k
1643
- handle: _this.togglePlay
1644
- }, {
1645
- keyCode: 70,
1646
- // f
1647
- handle: _this.toggleFullscreen
1648
- }, {
1649
- keyCode: 37,
1650
- // Left arrow
1651
- handle: function handle(player, actions) {
1652
- if (!player.hasStarted) {
1653
- return;
1654
- }
1655
- actions.replay(5, {
1656
- action: 'replay-5',
1657
- source: 'shortcut'
1658
- }); // Go back 5 seconds
1659
- }
1660
- }, {
1661
- keyCode: 74,
1662
- // j
1663
- handle: function handle(player, actions) {
1664
- if (!player.hasStarted) {
1665
- return;
1666
- }
1667
- actions.replay(10, {
1668
- action: 'replay-10',
1669
- source: 'shortcut'
1670
- }); // Go back 10 seconds
1671
- }
1672
- }, {
1673
- keyCode: 39,
1674
- // Right arrow
1675
- handle: function handle(player, actions) {
1676
- if (!player.hasStarted) {
1677
- return;
1678
- }
1679
- actions.forward(5, {
1680
- action: 'forward-5',
1681
- source: 'shortcut'
1682
- }); // Go forward 5 seconds
1683
- }
1684
- }, {
1685
- keyCode: 76,
1686
- // l
1687
- handle: function handle(player, actions) {
1688
- if (!player.hasStarted) {
1689
- return;
1690
- }
1691
- actions.forward(10, {
1692
- action: 'forward-10',
1693
- source: 'shortcut'
1694
- }); // Go forward 10 seconds
1695
- }
1696
- }, {
1697
- keyCode: 36,
1698
- // Home
1699
- handle: function handle(player, actions) {
1700
- if (!player.hasStarted) {
1701
- return;
1702
- }
1703
- actions.seek(0); // Go to beginning of video
1704
- }
1705
- }, {
1706
- keyCode: 35,
1707
- // End
1708
- handle: function handle(player, actions) {
1709
- if (!player.hasStarted) {
1710
- return;
1711
- }
1712
- // Go to end of video
1713
- actions.seek(player.duration);
1714
- }
1715
- }, {
1716
- keyCode: 38,
1717
- // Up arrow
1718
- handle: function handle(player, actions) {
1719
- // Increase volume 5%
1720
- var v = player.volume + 0.05;
1721
- if (v > 1) {
1722
- v = 1;
1723
- }
1724
- actions.changeVolume(v, {
1725
- action: 'volume-up',
1726
- source: 'shortcut'
1727
- });
1728
- }
1729
- }, {
1730
- keyCode: 40,
1731
- // Down arrow
1732
- handle: function handle(player, actions) {
1733
- // Decrease volume 5%
1734
- var v = player.volume - 0.05;
1735
- if (v < 0) {
1736
- v = 0;
1737
- }
1738
- var action = v > 0 ? 'volume-down' : 'volume-off';
1739
- actions.changeVolume(v, {
1740
- action: action,
1741
- source: 'shortcut'
1742
- });
1743
- }
1744
- }, {
1745
- keyCode: 190,
1746
- // Shift + >
1747
- shift: true,
1748
- handle: function handle(player, actions) {
1749
- // Increase speed
1750
- var playbackRate = player.playbackRate;
1751
- if (playbackRate >= 1.5) {
1752
- playbackRate = 2;
1753
- } else if (playbackRate >= 1.25) {
1754
- playbackRate = 1.5;
1755
- } else if (playbackRate >= 1.0) {
1756
- playbackRate = 1.25;
1757
- } else if (playbackRate >= 0.5) {
1758
- playbackRate = 1.0;
1759
- } else if (playbackRate >= 0.25) {
1760
- playbackRate = 0.5;
1761
- } else if (playbackRate >= 0) {
1762
- playbackRate = 0.25;
1763
- }
1764
- actions.changeRate(playbackRate, {
1765
- action: 'fast-forward',
1766
- source: 'shortcut'
1767
- });
1768
- }
1769
- }, {
1770
- keyCode: 188,
1771
- // Shift + <
1772
- shift: true,
1773
- handle: function handle(player, actions) {
1774
- // Decrease speed
1775
- var playbackRate = player.playbackRate;
1776
- if (playbackRate <= 0.5) {
1777
- playbackRate = 0.25;
1778
- } else if (playbackRate <= 1.0) {
1779
- playbackRate = 0.5;
1780
- } else if (playbackRate <= 1.25) {
1781
- playbackRate = 1.0;
1782
- } else if (playbackRate <= 1.5) {
1783
- playbackRate = 1.25;
1784
- } else if (playbackRate <= 2) {
1785
- playbackRate = 1.5;
1786
- }
1787
- actions.changeRate(playbackRate, {
1788
- action: 'fast-rewind',
1789
- source: 'shortcut'
1790
- });
1791
- }
1792
- }];
1793
- _this.shortcuts = [].concat(_this.defaultShortcuts);
1794
- _this.mergeShortcuts = _this.mergeShortcuts.bind(_assertThisInitialized(_this));
1795
- _this.handleKeyPress = _this.handleKeyPress.bind(_assertThisInitialized(_this));
1796
- _this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));
1797
- _this.handleDoubleClick = _this.handleDoubleClick.bind(_assertThisInitialized(_this));
1798
- return _this;
1799
- }
1800
- var _proto = Shortcut.prototype;
1801
- _proto.componentDidMount = function componentDidMount() {
1802
- this.mergeShortcuts();
1803
- document.addEventListener('keydown', this.handleKeyPress);
1804
- document.addEventListener('click', this.handleClick);
1805
- document.addEventListener('dblclick', this.handleDoubleClick);
1806
- };
1807
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
1808
- if (prevProps.shortcuts !== this.props.shortcuts) {
1809
- this.mergeShortcuts();
1810
- }
1811
- };
1812
- _proto.componentWillUnmount = function componentWillUnmount() {
1813
- document.removeEventListener('keydown', this.handleKeyPress);
1814
- document.removeEventListener('click', this.handleClick);
1815
- document.removeEventListener('dblclick', this.handleDoubleClick);
1816
- }
1817
-
1818
- // merge the shortcuts from props
1819
- ;
1820
- _proto.mergeShortcuts = function mergeShortcuts() {
1821
- var getShortcutKey = function getShortcutKey(_ref) {
1822
- var _ref$keyCode = _ref.keyCode,
1823
- keyCode = _ref$keyCode === void 0 ? 0 : _ref$keyCode,
1824
- _ref$ctrl = _ref.ctrl,
1825
- ctrl = _ref$ctrl === void 0 ? false : _ref$ctrl,
1826
- _ref$shift = _ref.shift,
1827
- shift = _ref$shift === void 0 ? false : _ref$shift,
1828
- _ref$alt = _ref.alt,
1829
- alt = _ref$alt === void 0 ? false : _ref$alt;
1830
- return keyCode + ":" + ctrl + ":" + shift + ":" + alt;
1831
- };
1832
- var defaultShortcuts = this.defaultShortcuts.reduce(function (shortcuts, shortcut) {
1833
- var _extends2;
1834
- return _extends({}, shortcuts, (_extends2 = {}, _extends2[getShortcutKey(shortcut)] = shortcut, _extends2));
1835
- }, {});
1836
- var mergedShortcuts = (this.props.shortcuts || []).reduce(function (shortcuts, shortcut) {
1837
- var keyCode = shortcut.keyCode,
1838
- handle = shortcut.handle;
1839
- if (keyCode && typeof handle === 'function') {
1840
- var _extends3;
1841
- return _extends({}, shortcuts, (_extends3 = {}, _extends3[getShortcutKey(shortcut)] = shortcut, _extends3));
1842
- }
1843
- return shortcuts;
1844
- }, defaultShortcuts);
1845
- var gradeShortcut = function gradeShortcut(shortcut) {
1846
- var score = 0;
1847
- ['ctrl', 'shift', 'alt'].forEach(function (key) {
1848
- if (shortcut[key]) {
1849
- score += 1;
1850
- }
1851
- });
1852
- return score;
1853
- };
1854
- this.shortcuts = Object.values(mergedShortcuts).sort(function (a, b) {
1855
- return gradeShortcut(b) - gradeShortcut(a);
1856
- });
1857
- };
1858
- _proto.togglePlay = function togglePlay(player, actions) {
1859
- if (player.paused) {
1860
- actions.play({
1861
- action: 'play',
1862
- source: 'shortcut'
1863
- });
1864
- } else {
1865
- actions.pause({
1866
- action: 'pause',
1867
- source: 'shortcut'
1868
- });
1869
- }
1870
- };
1871
- _proto.toggleFullscreen = function toggleFullscreen(player, actions) {
1872
- actions.toggleFullscreen(player);
1873
- };
1874
- _proto.handleKeyPress = function handleKeyPress(e) {
1875
- var _this$props = this.props,
1876
- player = _this$props.player,
1877
- actions = _this$props.actions;
1878
- if (!player.isActive) {
1879
- return;
1880
- }
1881
- var activeElement = document.activeElement;
1882
- if (activeElement && activeElement instanceof HTMLElement && (hasClass(activeElement, 'video-react-player-control') || hasClass(activeElement, 'video-react-player-menu-button-active') || hasClass(activeElement, 'video-react-player-big-play-button'))) {
1883
- return;
1884
- }
1885
- var keyCode = e.keyCode || e.which;
1886
- var ctrl = e.ctrlKey || e.metaKey;
1887
- var shift = e.shiftKey;
1888
- var alt = e.altKey;
1889
- var shortcut = this.shortcuts.find(function (s) {
1890
- if (!s.keyCode || s.keyCode - keyCode !== 0) {
1891
- return false;
1892
- }
1893
- if (s.ctrl !== undefined && s.ctrl !== ctrl || s.shift !== undefined && s.shift !== shift || s.alt !== undefined && s.alt !== alt) {
1894
- return false;
1895
- }
1896
- return true;
1897
- });
1898
- if (shortcut) {
1899
- shortcut.handle(player, actions);
1900
- e.preventDefault();
1901
- }
1902
- }
1903
-
1904
- // only if player is active and player is ready
1905
- ;
1906
- _proto.canBeClicked = function canBeClicked(player, e) {
1907
- if (!player.isActive || player.readyState !== 4 || !(e.target instanceof HTMLVideoElement)) {
1908
- return false;
1909
- }
1910
- return true;
1911
- };
1912
- _proto.handleClick = function handleClick(e) {
1913
- var _this$props2 = this.props,
1914
- player = _this$props2.player,
1915
- actions = _this$props2.actions,
1916
- clickable = _this$props2.clickable;
1917
- if (!this.canBeClicked(player, e) || !clickable) {
1918
- return;
1919
- }
1920
- this.togglePlay(player, actions);
1921
- // e.preventDefault();
1922
- };
1923
- _proto.handleDoubleClick = function handleDoubleClick(e) {
1924
- var _this$props3 = this.props,
1925
- player = _this$props3.player,
1926
- actions = _this$props3.actions,
1927
- dblclickable = _this$props3.dblclickable;
1928
- if (!this.canBeClicked(player, e) || !dblclickable) {
1929
- return;
1930
- }
1931
- this.toggleFullscreen(player, actions);
1932
- // e.preventDefault();
1933
- }
1934
-
1935
- // this component dose not render anything
1936
- // it's just for the key down event
1937
- ;
1938
- _proto.render = function render() {
1939
- return null;
1940
- };
1941
- return Shortcut;
1942
- }(Component);
1943
- Shortcut.defaultProps = {
1944
- clickable: true,
1945
- dblclickable: true
1946
- };
1947
- Shortcut.displayName = 'Shortcut';
1948
-
1949
- /**
1950
-
1951
- * Copyright (c) 2016 Video-React contributors
1952
- * Copyright (c) 2025 ZingMe.Vn
1953
- *
1954
- * This source code is licensed under the MIT license found in the
1955
- * LICENSE file in the root directory of this source tree.
1956
- */
1957
- var propTypes = {
1958
- player: PropTypes.object,
1959
- className: PropTypes.string
1960
- };
1961
- function CurrentTimeDisplay(_ref) {
1962
- var player = _ref.player,
1963
- className = _ref.className;
1964
- var formattedTime = formatTime(player.currentTime, player.duration);
1965
- return React.createElement("div", {
1966
- className: classNames('video-react-player-current-time video-react-player-time-control video-react-player-control', className)
1967
- }, React.createElement("div", {
1968
- className: "video-react-player-current-time-display",
1969
- "aria-live": "off"
1970
- }, React.createElement("span", {
1971
- className: "video-react-player-control-text"
1972
- }, "Current Time "), formattedTime));
1973
- }
1974
- CurrentTimeDisplay.propTypes = propTypes;
1975
- CurrentTimeDisplay.displayName = 'CurrentTimeDisplay';
1976
-
1977
- /**
1978
-
1979
- * Copyright (c) 2016 Video-React contributors
1980
- * Copyright (c) 2025 ZingMe.Vn
1981
- *
1982
- * This source code is licensed under the MIT license found in the
1983
- * LICENSE file in the root directory of this source tree.
1984
- */
1985
- function DurationDisplay(_ref) {
1986
- var player = _ref.player,
1987
- className = _ref.className;
1988
- var formattedTime = formatTime(player.duration);
1989
- return React.createElement("div", {
1990
- className: classNames(className, 'video-react-player-duration video-react-player-time-control video-react-player-control')
1991
- }, React.createElement("div", {
1992
- className: "video-react-player-duration-display",
1993
- "aria-live": "off"
1994
- }, React.createElement("span", {
1995
- className: "video-react-player-control-text"
1996
- }, "Duration Time "), formattedTime));
1997
- }
1998
- DurationDisplay.displayName = 'DurationDisplay';
1999
-
2000
- /**
2001
-
2002
- * Copyright (c) 2016 Video-React contributors
2003
- * Copyright (c) 2025 ZingMe.Vn
2004
- *
2005
- * This source code is licensed under the MIT license found in the
2006
- * LICENSE file in the root directory of this source tree.
2007
- */
2008
- function TimeDivider(_ref) {
2009
- var separator = _ref.separator,
2010
- className = _ref.className;
2011
- var separatorText = separator || '/';
2012
- return React.createElement("div", {
2013
- className: classNames('video-react-player-time-control video-react-player-time-divider', className),
2014
- dir: "ltr"
2015
- }, React.createElement("div", null, React.createElement("span", null, separatorText)));
2016
- }
2017
- TimeDivider.displayName = 'TimeDivider';
2018
-
2019
- /**
2020
-
2021
- * Copyright (c) 2016 Video-React contributors
2022
- * Copyright (c) 2025 ZingMe.Vn
2023
- *
2024
- * This source code is licensed under the MIT license found in the
2025
- * LICENSE file in the root directory of this source tree.
2026
- */
2027
- var FullscreenToggle = forwardRef(function (_ref, ref) {
2028
- var actions = _ref.actions,
2029
- player = _ref.player,
2030
- className = _ref.className;
2031
- var handleClick = useCallback(function () {
2032
- actions.toggleFullscreen(player);
2033
- }, [actions, player]);
2034
- return React.createElement("button", {
2035
- className: classNames(className, {
2036
- 'video-react-player-icon-fullscreen-exit': player.isFullscreen,
2037
- 'video-react-player-icon-fullscreen': !player.isFullscreen
2038
- }, 'video-react-player-fullscreen-control video-react-player-control video-react-player-button video-react-player-icon'),
2039
- ref: ref,
2040
- type: "button",
2041
- tabIndex: 0,
2042
- onClick: handleClick
2043
- }, React.createElement("span", {
2044
- className: "video-react-player-control-text"
2045
- }, "Non-Fullscreen"));
2046
- });
2047
- FullscreenToggle.displayName = 'FullscreenToggle';
2048
-
2049
- var PlayToggle = forwardRef(function (_ref, ref) {
2050
- var _player$paused;
2051
- var actions = _ref.actions,
2052
- player = _ref.player,
2053
- className = _ref.className;
2054
- var paused = (_player$paused = player === null || player === void 0 ? void 0 : player.paused) !== null && _player$paused !== void 0 ? _player$paused : true;
2055
- var handleClick = useCallback(function () {
2056
- if (!actions) return;
2057
- if (paused) {
2058
- actions.play();
2059
- } else {
2060
- actions.pause();
2061
- }
2062
- }, [actions, paused]);
2063
- var controlText = paused ? 'Play' : 'Pause';
2064
- return React.createElement("button", {
2065
- ref: ref,
2066
- className: classNames(className, {
2067
- 'video-react-player-play-control': true,
2068
- 'video-react-player-control': true,
2069
- 'video-react-player-button': true,
2070
- 'video-react-player-paused': paused,
2071
- 'video-react-player-playing': !paused
2072
- }),
2073
- type: "button",
2074
- tabIndex: 0,
2075
- onClick: handleClick
2076
- }, React.createElement("span", {
2077
- className: "video-react-player-control-text"
2078
- }, controlText));
2079
- });
2080
- PlayToggle.displayName = 'PlayToggle';
2081
-
2082
- var Slider = /*#__PURE__*/function (_Component) {
2083
- _inheritsLoose(Slider, _Component);
2084
- function Slider() {
2085
- var _this;
2086
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2087
- args[_key] = arguments[_key];
2088
- }
2089
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
2090
- _this.slider = null;
2091
- _this.state = {
2092
- active: false
2093
- };
2094
- _this.getProgress = function () {
2095
- var getPercent = _this.props.getPercent;
2096
- if (!getPercent) {
2097
- return 0;
2098
- }
2099
- var progress = getPercent();
2100
- if (typeof progress !== 'number' || progress < 0 || progress === Infinity) {
2101
- progress = 0;
2102
- }
2103
- return progress;
2104
- };
2105
- _this.handleMouseDown = function (event) {
2106
- var _this$props$sliderAct, _this$props;
2107
- var onMouseDown = _this.props.onMouseDown;
2108
- document.addEventListener('mousemove', _this.handleMouseMove, true);
2109
- document.addEventListener('mouseup', _this.handleMouseUp, true);
2110
- document.addEventListener('touchmove', _this.handleMouseMove, true);
2111
- document.addEventListener('touchend', _this.handleMouseUp, true);
2112
- _this.setState({
2113
- active: true
2114
- });
2115
- (_this$props$sliderAct = (_this$props = _this.props).sliderActive) === null || _this$props$sliderAct === void 0 ? void 0 : _this$props$sliderAct.call(_this$props, event);
2116
- _this.handleMouseMove(event);
2117
- if (onMouseDown) {
2118
- onMouseDown(event);
2119
- }
2120
- };
2121
- _this.handleMouseMove = function (event) {
2122
- var onMouseMove = _this.props.onMouseMove;
2123
- if (onMouseMove) {
2124
- onMouseMove(event);
2125
- }
2126
- };
2127
- _this.handleMouseUp = function (event) {
2128
- var _this$props$sliderIna, _this$props2;
2129
- event.preventDefault();
2130
- var onMouseUp = _this.props.onMouseUp;
2131
- document.removeEventListener('mousemove', _this.handleMouseMove, true);
2132
- document.removeEventListener('mouseup', _this.handleMouseUp, true);
2133
- document.removeEventListener('touchmove', _this.handleMouseMove, true);
2134
- document.removeEventListener('touchend', _this.handleMouseUp, true);
2135
- _this.setState({
2136
- active: false
2137
- });
2138
- (_this$props$sliderIna = (_this$props2 = _this.props).sliderInactive) === null || _this$props$sliderIna === void 0 ? void 0 : _this$props$sliderIna.call(_this$props2, event);
2139
- if (onMouseUp) {
2140
- onMouseUp(event);
2141
- }
2142
- };
2143
- _this.handleFocus = function (event) {
2144
- var _this$props$onFocus, _this$props3;
2145
- document.addEventListener('keydown', _this.handleKeyPress, true);
2146
- (_this$props$onFocus = (_this$props3 = _this.props).onFocus) === null || _this$props$onFocus === void 0 ? void 0 : _this$props$onFocus.call(_this$props3, event);
2147
- };
2148
- _this.handleBlur = function (event) {
2149
- document.removeEventListener('keydown', _this.handleKeyPress, true);
2150
- if (event) {
2151
- var _this$props$onBlur, _this$props4;
2152
- (_this$props$onBlur = (_this$props4 = _this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props4, event);
2153
- }
2154
- };
2155
- _this.handleClick = function (event) {
2156
- var _this$props$onClick, _this$props5;
2157
- event.preventDefault();
2158
- (_this$props$onClick = (_this$props5 = _this.props).onClick) === null || _this$props$onClick === void 0 ? void 0 : _this$props$onClick.call(_this$props5, event);
2159
- };
2160
- _this.handleKeyPress = function (event) {
2161
- if (event.which === 37 || event.which === 40) {
2162
- event.preventDefault();
2163
- event.stopPropagation();
2164
- _this.stepBack();
2165
- } else if (event.which === 38 || event.which === 39) {
2166
- event.preventDefault();
2167
- event.stopPropagation();
2168
- _this.stepForward();
2169
- }
2170
- };
2171
- _this.stepForward = function () {
2172
- var _this$props$stepForwa, _this$props6;
2173
- (_this$props$stepForwa = (_this$props6 = _this.props).stepForward) === null || _this$props$stepForwa === void 0 ? void 0 : _this$props$stepForwa.call(_this$props6);
2174
- };
2175
- _this.stepBack = function () {
2176
- var _this$props$stepBack, _this$props7;
2177
- (_this$props$stepBack = (_this$props7 = _this.props).stepBack) === null || _this$props$stepBack === void 0 ? void 0 : _this$props$stepBack.call(_this$props7);
2178
- };
2179
- _this.renderChildren = function () {
2180
- var _this$props$onPercent, _this$props8;
2181
- var progress = _this.getProgress();
2182
- var percentage = (progress * 100).toFixed(2) + "%";
2183
- (_this$props$onPercent = (_this$props8 = _this.props).onPercentageChange) === null || _this$props$onPercent === void 0 ? void 0 : _this$props$onPercent.call(_this$props8, percentage);
2184
- return React.Children.map(_this.props.children, function (child) {
2185
- return React.isValidElement(child) ? React.cloneElement(child, {
2186
- progress: progress,
2187
- percentage: percentage
2188
- }) : child;
2189
- });
2190
- };
2191
- return _this;
2192
- }
2193
- var _proto = Slider.prototype;
2194
- _proto.componentWillUnmount = function componentWillUnmount() {
2195
- document.removeEventListener('mousemove', this.handleMouseMove, true);
2196
- document.removeEventListener('mouseup', this.handleMouseUp, true);
2197
- document.removeEventListener('touchmove', this.handleMouseMove, true);
2198
- document.removeEventListener('touchend', this.handleMouseUp, true);
2199
- document.removeEventListener('keydown', this.handleKeyPress, true);
2200
- };
2201
- _proto.calculateDistance = function calculateDistance(event) {
2202
- var _position$x;
2203
- if (!this.slider) {
2204
- return 0;
2205
- }
2206
- var position = getPointerPosition(this.slider, event);
2207
- if (this.props.vertical) {
2208
- var _position$y;
2209
- return (_position$y = position.y) !== null && _position$y !== void 0 ? _position$y : 0;
2210
- }
2211
- return (_position$x = position.x) !== null && _position$x !== void 0 ? _position$x : 0;
2212
- };
2213
- _proto.render = function render() {
2214
- var _this2 = this;
2215
- var _this$props9 = this.props,
2216
- vertical = _this$props9.vertical,
2217
- label = _this$props9.label,
2218
- valuenow = _this$props9.valuenow,
2219
- valuetext = _this$props9.valuetext;
2220
- var ariaValueNow = typeof valuenow === 'number' ? valuenow : Number(valuenow !== null && valuenow !== void 0 ? valuenow : 0);
2221
- return React.createElement("div", {
2222
- className: classNames(this.props.className, {
2223
- 'video-react-player-slider-vertical': vertical,
2224
- 'video-react-player-slider-horizontal': !vertical,
2225
- 'video-react-player-sliding': this.state.active
2226
- }, 'video-react-player-slider'),
2227
- ref: function ref(node) {
2228
- _this2.slider = node;
2229
- },
2230
- tabIndex: 0,
2231
- role: "slider",
2232
- onMouseDown: this.handleMouseDown,
2233
- onTouchStart: this.handleMouseDown,
2234
- onFocus: this.handleFocus,
2235
- onBlur: this.handleBlur,
2236
- onClick: this.handleClick,
2237
- "aria-label": label || '',
2238
- "aria-valuenow": ariaValueNow,
2239
- "aria-valuetext": valuetext || '',
2240
- "aria-valuemin": 0,
2241
- "aria-valuemax": 100
2242
- }, this.renderChildren());
2243
- };
2244
- return Slider;
2245
- }(Component);
2246
- Slider.displayName = 'Slider';
2247
-
2248
- /**
2249
-
2250
- * Copyright (c) 2016 Video-React contributors
2251
- * Copyright (c) 2025 ZingMe.Vn
2252
- *
2253
- * This source code is licensed under the MIT license found in the
2254
- * LICENSE file in the root directory of this source tree.
2255
- */
2256
- // Shows play progress
2257
- function PlayProgressBar(_ref) {
2258
- var currentTime = _ref.currentTime,
2259
- duration = _ref.duration,
2260
- percentage = _ref.percentage,
2261
- className = _ref.className;
2262
- return React.createElement("div", {
2263
- "data-current-time": formatTime(currentTime, duration),
2264
- className: classNames('video-react-player-play-progress video-react-player-slider-bar', className),
2265
- style: {
2266
- width: percentage
2267
- }
2268
- }, React.createElement("span", {
2269
- className: "video-react-player-control-text"
2270
- }, "Progress: " + percentage));
2271
- }
2272
- PlayProgressBar.displayName = 'PlayProgressBar';
2273
-
2274
- /**
2275
-
2276
- * Copyright (c) 2016 Video-React contributors
2277
- * Copyright (c) 2025 ZingMe.Vn
2278
- *
2279
- * This source code is licensed under the MIT license found in the
2280
- * LICENSE file in the root directory of this source tree.
2281
- */
2282
- var percentify = function percentify(time, end) {
2283
- var percent = time / end || 0;
2284
- return (percent >= 1 ? 1 : percent) * 100 + "%";
2285
- };
2286
- var LoadProgressBar = function LoadProgressBar(_ref) {
2287
- var buffered = _ref.buffered,
2288
- duration = _ref.duration,
2289
- className = _ref.className;
2290
- if (!buffered || buffered.length === 0) {
2291
- return null;
2292
- }
2293
- var bufferedEnd = buffered.end(buffered.length - 1);
2294
- if (bufferedEnd > duration) {
2295
- bufferedEnd = duration;
2296
- }
2297
- var style = {
2298
- width: percentify(bufferedEnd, duration)
2299
- };
2300
- var parts = [];
2301
- for (var i = 0; i < buffered.length; i += 1) {
2302
- var start = buffered.start(i);
2303
- var end = buffered.end(i);
2304
- parts.push(React.createElement("div", {
2305
- style: {
2306
- left: percentify(start, bufferedEnd),
2307
- width: percentify(end - start, bufferedEnd)
2308
- },
2309
- key: "part-" + i
2310
- }));
2311
- }
2312
- return React.createElement("div", {
2313
- style: style,
2314
- className: classNames('video-react-player-load-progress', className)
2315
- }, React.createElement("span", {
2316
- className: "video-react-player-control-text"
2317
- }, "Loaded: 0%"), parts);
2318
- };
2319
- LoadProgressBar.displayName = 'LoadProgressBar';
2320
-
2321
- /**
2322
-
2323
- * Copyright (c) 2016 Video-React contributors
2324
- * Copyright (c) 2025 ZingMe.Vn
2325
- *
2326
- * This source code is licensed under the MIT license found in the
2327
- * LICENSE file in the root directory of this source tree.
2328
- */
2329
- var MouseTimeDisplay = function MouseTimeDisplay(_ref) {
2330
- var duration = _ref.duration,
2331
- mouseTime = _ref.mouseTime,
2332
- className = _ref.className,
2333
- text = _ref.text;
2334
- if (!mouseTime.time) {
2335
- return null;
2336
- }
2337
- var time = text || formatTime(mouseTime.time, duration);
2338
- return React.createElement("div", {
2339
- className: classNames('video-react-player-mouse-display', className),
2340
- style: {
2341
- left: mouseTime.position + "px"
2342
- },
2343
- "data-current-time": time
2344
- });
2345
- };
2346
- MouseTimeDisplay.displayName = 'MouseTimeDisplay';
2347
-
2348
- /**
2349
-
2350
- * Copyright (c) 2016 Video-React contributors
2351
- * Copyright (c) 2025 ZingMe.Vn
2352
- *
2353
- * This source code is licensed under the MIT license found in the
2354
- * LICENSE file in the root directory of this source tree.
2355
- */
2356
- var SeekBar = function SeekBar(_ref) {
2357
- var player = _ref.player,
2358
- actions = _ref.actions,
2359
- mouseTime = _ref.mouseTime,
2360
- className = _ref.className;
2361
- var sliderRef = useRef(null);
2362
- var getPercent = useCallback(function () {
2363
- var currentTime = player.currentTime,
2364
- seekingTime = player.seekingTime,
2365
- duration = player.duration;
2366
- var time = seekingTime || currentTime;
2367
- if (!duration) {
2368
- return 0;
2369
- }
2370
- var percent = time / duration;
2371
- return percent >= 1 ? 1 : percent;
2372
- }, [player]);
2373
- var getNewTime = useCallback(function (event) {
2374
- var duration = player.duration || 0;
2375
- var distance = sliderRef.current ? sliderRef.current.calculateDistance(event) : 0;
2376
- var newTime = distance * duration;
2377
- return newTime === duration ? newTime - 0.1 : newTime;
2378
- }, [player.duration]);
2379
- var handleMouseMove = useCallback(function (event) {
2380
- var newTime = getNewTime(event);
2381
- actions.handleSeekingTime(newTime);
2382
- }, [actions, getNewTime]);
2383
- var handleMouseUp = useCallback(function (event) {
2384
- var newTime = getNewTime(event);
2385
- actions.seek(newTime);
2386
- actions.handleEndSeeking(newTime);
2387
- }, [actions, getNewTime]);
2388
- var stepForward = useCallback(function () {
2389
- actions.forward(5);
2390
- }, [actions]);
2391
- var stepBack = useCallback(function () {
2392
- actions.replay(5);
2393
- }, [actions]);
2394
- var time = player.seekingTime || player.currentTime;
2395
- var percent = getPercent();
2396
- var valueText = useMemo(function () {
2397
- return formatTime(time, player.duration);
2398
- }, [player.duration, time]);
2399
- return React.createElement(Slider, {
2400
- ref: function ref(instance) {
2401
- sliderRef.current = instance;
2402
- },
2403
- label: "video progress bar",
2404
- className: classNames('video-react-player-progress-holder', className),
2405
- valuenow: Number((percent * 100).toFixed(2)),
2406
- valuetext: valueText,
2407
- onMouseMove: handleMouseMove,
2408
- onMouseUp: handleMouseUp,
2409
- getPercent: getPercent,
2410
- stepForward: stepForward,
2411
- stepBack: stepBack
2412
- }, React.createElement(LoadProgressBar, {
2413
- buffered: player.buffered,
2414
- currentTime: time,
2415
- duration: player.duration
2416
- }), React.createElement(MouseTimeDisplay, {
2417
- duration: player.duration,
2418
- mouseTime: mouseTime
2419
- }), React.createElement(PlayProgressBar, {
2420
- percentage: (percent * 100).toFixed(2) + "%",
2421
- currentTime: time,
2422
- duration: player.duration
2423
- }));
2424
- };
2425
- SeekBar.displayName = 'SeekBar';
2426
-
2427
- var ProgressControl = function ProgressControl(_ref) {
2428
- var className = _ref.className,
2429
- playerProps = _objectWithoutPropertiesLoose(_ref, ["className"]);
2430
- var _useState = useState({
2431
- time: null,
2432
- position: 0
2433
- }),
2434
- mouseTime = _useState[0],
2435
- setMouseTime = _useState[1];
2436
- var handleMouseMove = useCallback(function (event) {
2437
- if (!event.pageX) {
2438
- return;
2439
- }
2440
- var target = event.currentTarget;
2441
- if (!target) {
2442
- return;
2443
- }
2444
- var _Dom$getPointerPositi = getPointerPosition(target, event.nativeEvent),
2445
- _Dom$getPointerPositi2 = _Dom$getPointerPositi.x,
2446
- x = _Dom$getPointerPositi2 === void 0 ? 0 : _Dom$getPointerPositi2;
2447
- var newTime = x * playerProps.player.duration;
2448
- var position = event.pageX - findElPosition(target).left;
2449
- setMouseTime({
2450
- time: newTime,
2451
- position: position
2452
- });
2453
- }, [playerProps.player.duration]);
2454
- return React.createElement("div", {
2455
- onMouseMove: handleMouseMove,
2456
- className: classNames('video-react-player-progress-control video-react-player-control', className)
2457
- }, React.createElement(SeekBar, _extends({
2458
- mouseTime: mouseTime
2459
- }, playerProps)));
2460
- };
2461
- ProgressControl.displayName = 'ProgressControl';
2462
-
2463
- var ClickableComponent = /*#__PURE__*/function (_Component) {
2464
- _inheritsLoose(ClickableComponent, _Component);
2465
- function ClickableComponent() {
2466
- var _this;
2467
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2468
- args[_key] = arguments[_key];
2469
- }
2470
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
2471
- _this.handleKeypress = function (event) {
2472
- if (event.which === 32 || event.which === 13) {
2473
- event.preventDefault();
2474
- _this.handleClick(event);
2475
- }
2476
- };
2477
- _this.handleClick = function (event) {
2478
- _this.props.onClick(event);
2479
- };
2480
- _this.handleFocus = function (event) {
2481
- var _this$props$onFocus, _this$props;
2482
- document.addEventListener('keydown', _this.handleKeypress);
2483
- (_this$props$onFocus = (_this$props = _this.props).onFocus) === null || _this$props$onFocus === void 0 ? void 0 : _this$props$onFocus.call(_this$props, event);
2484
- };
2485
- _this.handleBlur = function (event) {
2486
- document.removeEventListener('keydown', _this.handleKeypress);
2487
- if (event) {
2488
- var _this$props$onBlur, _this$props2;
2489
- (_this$props$onBlur = (_this$props2 = _this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props2, event);
2490
- }
2491
- };
2492
- return _this;
2493
- }
2494
- var _proto = ClickableComponent.prototype;
2495
- _proto.componentWillUnmount = function componentWillUnmount() {
2496
- this.handleBlur();
2497
- };
2498
- _proto.render = function render() {
2499
- var _this$props3 = this.props,
2500
- _this$props3$tagName = _this$props3.tagName,
2501
- tagName = _this$props3$tagName === void 0 ? 'div' : _this$props3$tagName,
2502
- className = _this$props3.className,
2503
- children = _this$props3.children,
2504
- onClick = _this$props3.onClick,
2505
- onFocus = _this$props3.onFocus,
2506
- onBlur = _this$props3.onBlur,
2507
- rest = _objectWithoutPropertiesLoose(_this$props3, ["tagName", "className", "children", "onClick", "onFocus", "onBlur"]);
2508
- var Tag = tagName;
2509
- return React.createElement(Tag, _extends({}, rest, {
2510
- className: classNames(className),
2511
- role: "button",
2512
- tabIndex: 0,
2513
- onClick: this.handleClick,
2514
- onFocus: this.handleFocus,
2515
- onBlur: this.handleBlur
2516
- }), children);
2517
- };
2518
- return ClickableComponent;
2519
- }(Component);
2520
- ClickableComponent.defaultProps = {
2521
- tagName: 'div'
2522
- };
2523
- ClickableComponent.displayName = 'ClickableComponent';
2524
-
2525
- /**
2526
-
2527
- * Copyright (c) 2016 Video-React contributors
2528
- * Copyright (c) 2025 ZingMe.Vn
2529
- *
2530
- * This source code is licensed under the MIT license found in the
2531
- * LICENSE file in the root directory of this source tree.
2532
- */
2533
- var Popup = function Popup(_ref) {
2534
- var children = _ref.children;
2535
- var handleClick = function handleClick(event) {
2536
- event.preventDefault();
2537
- };
2538
- return React.createElement("div", {
2539
- className: "video-react-player-menu",
2540
- onClick: handleClick
2541
- }, React.createElement("div", {
2542
- className: "video-react-player-menu-content"
2543
- }, children));
2544
- };
2545
- Popup.displayName = 'Popup';
2546
-
2547
- var PopupButton = function PopupButton(_ref) {
2548
- var _ref$inline = _ref.inline,
2549
- inline = _ref$inline === void 0 ? true : _ref$inline,
2550
- className = _ref.className,
2551
- children = _ref.children,
2552
- rest = _objectWithoutPropertiesLoose(_ref, ["inline", "className", "children"]);
2553
- return React.createElement(ClickableComponent, _extends({}, rest, {
2554
- className: classNames(className, {
2555
- 'video-react-player-menu-button-inline': !!inline,
2556
- 'video-react-player-menu-button-popup': !inline
2557
- }, 'video-react-player-control video-react-player-button video-react-player-menu-button')
2558
- }), React.createElement(Popup, null, children));
2559
- };
2560
- PopupButton.displayName = 'PopupButton';
2561
-
2562
- var VolumeLevel = function VolumeLevel(_ref) {
2563
- var _ref$percentage = _ref.percentage,
2564
- percentage = _ref$percentage === void 0 ? '100%' : _ref$percentage,
2565
- _ref$vertical = _ref.vertical,
2566
- vertical = _ref$vertical === void 0 ? false : _ref$vertical,
2567
- className = _ref.className;
2568
- var style = {};
2569
- if (vertical) {
2570
- style.height = percentage;
2571
- } else {
2572
- style.width = percentage;
2573
- }
2574
- return React.createElement("div", {
2575
- className: classNames(className, 'video-react-player-volume-level'),
2576
- style: style
2577
- }, React.createElement("span", {
2578
- className: "video-react-player-control-text"
2579
- }));
2580
- };
2581
- VolumeLevel.displayName = 'VolumeLevel';
2582
-
2583
- var VolumeBar = /*#__PURE__*/function (_Component) {
2584
- _inheritsLoose(VolumeBar, _Component);
2585
- function VolumeBar() {
2586
- var _this;
2587
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2588
- args[_key] = arguments[_key];
2589
- }
2590
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
2591
- _this.slider = null;
2592
- _this.state = {
2593
- percentage: '0%'
2594
- };
2595
- _this.getPercent = function () {
2596
- var player = _this.props.player;
2597
- return player.muted ? 0 : player.volume;
2598
- };
2599
- _this.checkMuted = function () {
2600
- var _this$props = _this.props,
2601
- player = _this$props.player,
2602
- actions = _this$props.actions;
2603
- if (player.muted) {
2604
- actions.mute(false);
2605
- }
2606
- };
2607
- _this.handleMouseMove = function (event) {
2608
- var actions = _this.props.actions;
2609
- _this.checkMuted();
2610
- var distance = _this.slider ? _this.slider.calculateDistance(event) : 0;
2611
- actions.changeVolume(distance);
2612
- };
2613
- _this.stepForward = function () {
2614
- var _this$props2 = _this.props,
2615
- player = _this$props2.player,
2616
- actions = _this$props2.actions;
2617
- _this.checkMuted();
2618
- actions.changeVolume(player.volume + 0.1);
2619
- };
2620
- _this.stepBack = function () {
2621
- var _this$props3 = _this.props,
2622
- player = _this$props3.player,
2623
- actions = _this$props3.actions;
2624
- _this.checkMuted();
2625
- actions.changeVolume(player.volume - 0.1);
2626
- };
2627
- _this.handleFocus = function (event) {
2628
- var _this$props$onFocus, _this$props4;
2629
- (_this$props$onFocus = (_this$props4 = _this.props).onFocus) === null || _this$props$onFocus === void 0 ? void 0 : _this$props$onFocus.call(_this$props4, event);
2630
- };
2631
- _this.handleBlur = function (event) {
2632
- var _this$props$onBlur, _this$props5;
2633
- (_this$props$onBlur = (_this$props5 = _this.props).onBlur) === null || _this$props$onBlur === void 0 ? void 0 : _this$props$onBlur.call(_this$props5, event);
2634
- };
2635
- _this.handleSliderActivate = function (event) {
2636
- if (event.type === 'focus') {
2637
- _this.handleFocus(event);
2638
- }
2639
- };
2640
- _this.handleSliderDeactivate = function (event) {
2641
- if (event.type === 'blur') {
2642
- _this.handleBlur(event);
2643
- }
2644
- };
2645
- _this.handlePercentageChange = function (percentage) {
2646
- if (percentage !== _this.state.percentage) {
2647
- _this.setState({
2648
- percentage: percentage
2649
- });
2650
- }
2651
- };
2652
- _this.handleClick = function (event) {
2653
- event.stopPropagation();
2654
- };
2655
- return _this;
2656
- }
2657
- var _proto = VolumeBar.prototype;
2658
- _proto.render = function render() {
2659
- var _this2 = this;
2660
- var _this$props6 = this.props,
2661
- player = _this$props6.player,
2662
- className = _this$props6.className,
2663
- vertical = _this$props6.vertical;
2664
- var volume = Number((player.volume * 100).toFixed(2));
2665
- return React.createElement(Slider, {
2666
- order: 1,
2667
- ref: function ref(instance) {
2668
- _this2.slider = instance;
2669
- },
2670
- label: "volume level",
2671
- valuenow: volume,
2672
- valuetext: volume + "%",
2673
- onMouseMove: this.handleMouseMove,
2674
- onFocus: this.handleFocus,
2675
- onBlur: this.handleBlur,
2676
- onClick: this.handleClick,
2677
- sliderActive: this.handleSliderActivate,
2678
- sliderInactive: this.handleSliderDeactivate,
2679
- getPercent: this.getPercent,
2680
- onPercentageChange: this.handlePercentageChange,
2681
- stepForward: this.stepForward,
2682
- stepBack: this.stepBack,
2683
- vertical: vertical,
2684
- className: classNames(className, 'video-react-player-volume-bar', 'video-react-player-slider-bar')
2685
- }, React.createElement(VolumeLevel, {
2686
- className: "video-react-player-volume-level"
2687
- }));
2688
- };
2689
- return VolumeBar;
2690
- }(Component);
2691
- VolumeBar.displayName = 'VolumeBar';
2692
-
2693
- var VolumeMenuButton = function VolumeMenuButton(_ref) {
2694
- var player = _ref.player,
2695
- actions = _ref.actions,
2696
- _ref$vertical = _ref.vertical,
2697
- vertical = _ref$vertical === void 0 ? false : _ref$vertical,
2698
- className = _ref.className,
2699
- alwaysShowVolume = _ref.alwaysShowVolume,
2700
- buttonProps = _objectWithoutPropertiesLoose(_ref, ["player", "actions", "vertical", "className", "alwaysShowVolume"]);
2701
- var _useState = useState(false),
2702
- active = _useState[0],
2703
- setActive = _useState[1];
2704
- var volumeLevel = useMemo(function () {
2705
- if (player.muted || player.volume === 0) {
2706
- return 0;
2707
- }
2708
- if (player.volume < 0.33) {
2709
- return 1;
2710
- }
2711
- if (player.volume < 0.67) {
2712
- return 2;
2713
- }
2714
- return 3;
2715
- }, [player.muted, player.volume]);
2716
- var handleClick = useCallback(function () {
2717
- actions.mute(!player.muted);
2718
- }, [actions, player.muted]);
2719
- var handleFocus = useCallback(function () {
2720
- setActive(true);
2721
- }, []);
2722
- var handleBlur = useCallback(function () {
2723
- setActive(false);
2724
- }, []);
2725
- var inline = !vertical;
2726
- return React.createElement(PopupButton, _extends({}, buttonProps, {
2727
- className: classNames(className, {
2728
- 'video-react-player-volume-menu-button-vertical': vertical,
2729
- 'video-react-player-volume-menu-button-horizontal': !vertical,
2730
- 'video-react-player-vol-muted': player.muted,
2731
- 'video-react-player-vol-0': volumeLevel === 0 && !player.muted,
2732
- 'video-react-player-vol-1': volumeLevel === 1,
2733
- 'video-react-player-vol-2': volumeLevel === 2,
2734
- 'video-react-player-vol-3': volumeLevel === 3,
2735
- 'video-react-player-slider-active': alwaysShowVolume || active,
2736
- 'video-react-player-lock-showing': alwaysShowVolume || active
2737
- }, 'video-react-player-volume-menu-button'),
2738
- onClick: handleClick,
2739
- inline: inline
2740
- }), React.createElement(VolumeBar, {
2741
- onFocus: handleFocus,
2742
- onBlur: handleBlur,
2743
- player: player,
2744
- actions: actions,
2745
- vertical: vertical
2746
- }));
2747
- };
2748
- VolumeMenuButton.displayName = 'VolumeMenuButton';
2749
-
2750
- var asDefaultChild = function asDefaultChild(element) {
2751
- return element;
2752
- };
2753
- var getDefaultChildren = function getDefaultChildren() {
2754
- return [asDefaultChild(React.createElement(PlayToggle, {
2755
- key: 'play-toggle',
2756
- order: 1
2757
- })), asDefaultChild(React.createElement(VolumeMenuButton, {
2758
- key: 'volume-menu-button',
2759
- order: 4
2760
- })), asDefaultChild(React.createElement(CurrentTimeDisplay, {
2761
- key: 'current-time-display',
2762
- order: 5.1
2763
- })), asDefaultChild(React.createElement(TimeDivider, {
2764
- key: 'time-divider',
2765
- order: 5.2
2766
- })), asDefaultChild(React.createElement(DurationDisplay, {
2767
- key: 'duration-display',
2768
- order: 5.3
2769
- })), asDefaultChild(React.createElement(ProgressControl, {
2770
- key: 'progress-control',
2771
- order: 6
2772
- })), asDefaultChild(React.createElement(FullscreenToggle, {
2773
- key: 'fullscreen-toggle',
2774
- order: 8
2775
- }))];
2776
- };
2777
- var ControlBar = function ControlBar(_ref) {
2778
- var _ref$autoHide = _ref.autoHide,
2779
- autoHide = _ref$autoHide === void 0 ? true : _ref$autoHide,
2780
- className = _ref.className,
2781
- _ref$disableCompletel = _ref.disableCompletely,
2782
- disableCompletely = _ref$disableCompletel === void 0 ? false : _ref$disableCompletel,
2783
- disableDefaultControls = _ref.disableDefaultControls,
2784
- children = _ref.children,
2785
- parentProps = _objectWithoutPropertiesLoose(_ref, ["autoHide", "className", "disableCompletely", "disableDefaultControls", "children"]);
2786
- if (disableCompletely || !parentProps.actions || !parentProps.player) {
2787
- return null;
2788
- }
2789
- var hasCoreProps = Boolean(parentProps.actions && parentProps.player);
2790
- var defaultChildren = disableDefaultControls || !hasCoreProps ? [] : getDefaultChildren();
2791
- var mergedChildren = mergeAndSortChildren(defaultChildren, children, parentProps);
2792
- return React.createElement("div", {
2793
- className: classNames('video-react-player-control-bar', {
2794
- 'video-react-player-control-bar-auto-hide': autoHide
2795
- }, className)
2796
- }, mergedChildren);
2797
- };
2798
- ControlBar.displayName = 'ControlBar';
2799
-
2800
- var USER_AGENT = typeof window !== 'undefined' && window.navigator ? window.navigator.userAgent : '';
2801
- // const webkitVersionMap = (/AppleWebKit\/([\d.]+)/i).exec(USER_AGENT);
2802
- // const appleWebkitVersion = webkitVersionMap ? parseFloat(webkitVersionMap.pop()) : null;
2803
-
2804
- /*
2805
- * Device is an iPhone
2806
- *
2807
- * @type {Boolean}
2808
- * @constant
2809
- * @private
2810
- */
2811
- var IS_IPAD = /iPad/i.test(USER_AGENT);
2812
-
2813
- // The Facebook app's UIWebView identifies as both an iPhone and iPad, so
2814
- // to identify iPhones, we need to exclude iPads.
2815
- // http://artsy.github.io/blog/2012/10/18/the-perils-of-ios-user-agent-sniffing/
2816
- var IS_IPHONE = /iPhone/i.test(USER_AGENT) && !IS_IPAD;
2817
- var IS_IPOD = /iPod/i.test(USER_AGENT);
2818
- var IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD;
2819
-
2820
- var defaultProps = {
2821
- fluid: true,
2822
- muted: false,
2823
- playsInline: false,
2824
- preload: 'auto',
2825
- aspectRatio: 'auto'
2826
- };
2827
- var Player = forwardRef(function (incomingProps, ref) {
2828
- var props = _extends({}, defaultProps, incomingProps);
2829
- var children = props.children,
2830
- width = props.width,
2831
- height = props.height,
2832
- fluid = props.fluid,
2833
- bigPlayButtonPosition = props.bigPlayButtonPosition,
2834
- hideDefaultBigPlayButton = props.hideDefaultBigPlayButton,
2835
- aspectRatio = props.aspectRatio,
2836
- className = props.className,
2837
- store = props.store,
2838
- passThroughProps = _objectWithoutPropertiesLoose(props, ["children", "width", "height", "fluid", "bigPlayButtonPosition", "hideDefaultBigPlayButton", "aspectRatio", "className", "store"]);
2839
- var managerRef = useRef();
2840
- if (!managerRef.current) {
2841
- managerRef.current = new Manager(store);
2842
- }
2843
- var manager = managerRef.current;
2844
- var actionsRef = useRef(manager.getActions());
2845
- var actions = actionsRef.current;
2846
- var videoComponentRef = useRef(null);
2847
- var controlsHideTimerRef = useRef(null);
2848
- var _useState = useState(manager.getState().player),
2849
- playerState = _useState[0],
2850
- setPlayerState = _useState[1];
2851
- var handleResize = useCallback(function () {}, []);
2852
- useEffect(function () {
2853
- var unsubscribe = manager.subscribeToPlayerStateChange(function (state, prevState) {
2854
- if (state.isFullscreen !== prevState.isFullscreen) {
2855
- handleResize();
2856
- focusNode(manager.rootElement);
2857
- }
2858
- setPlayerState(state);
2859
- });
2860
- return unsubscribe;
2861
- }, [handleResize, manager]);
2862
- useEffect(function () {
2863
- handleResize();
2864
- window.addEventListener('resize', handleResize);
2865
- return function () {
2866
- window.removeEventListener('resize', handleResize);
2867
- };
2868
- }, [handleResize]);
2869
- var handleFullScreenChange = useCallback(function (event) {
2870
- if (event.target === manager.rootElement) {
2871
- actions.handleFullscreenChange(Boolean(fullscreen.isFullscreen));
2872
- }
2873
- }, [actions, manager]);
2874
- useEffect(function () {
2875
- fullscreen.addEventListener(handleFullScreenChange);
2876
- return function () {
2877
- return fullscreen.removeEventListener(handleFullScreenChange);
2878
- };
2879
- }, [handleFullScreenChange]);
2880
- useEffect(function () {
2881
- return function () {
2882
- if (controlsHideTimerRef.current) {
2883
- clearTimeout(controlsHideTimerRef.current);
2884
- }
2885
- };
2886
- }, []);
2887
- var handleVideoRef = useCallback(function (instance) {
2888
- videoComponentRef.current = instance;
2889
- manager.video = instance;
2890
- }, [manager]);
2891
- var getDefaultChildren = useCallback(function (originalChildren, includeBigPlayButton, bigPlayPos) {
2892
- if (includeBigPlayButton === void 0) {
2893
- includeBigPlayButton = true;
2894
- }
2895
- return [React.createElement(Video, {
2896
- ref: handleVideoRef,
2897
- key: "video",
2898
- order: 0,
2899
- actions: actions,
2900
- player: playerState
2901
- }, originalChildren), React.createElement(PosterImage, {
2902
- key: "poster-image",
2903
- order: 1,
2904
- actions: actions,
2905
- player: playerState
2906
- }), React.createElement(LoadingSpinner, {
2907
- key: "loading-spinner",
2908
- order: 2,
2909
- actions: actions,
2910
- player: playerState
2911
- }), React.createElement(Bezel, {
2912
- key: "bezel",
2913
- order: 3,
2914
- manager: manager
2915
- }), includeBigPlayButton && React.createElement(BigPlayButton, {
2916
- key: "big-play-button",
2917
- order: 4,
2918
- actions: actions,
2919
- player: playerState,
2920
- position: bigPlayPos
2921
- }), React.createElement(ControlBar, {
2922
- key: "control-bar",
2923
- order: 5,
2924
- actions: actions,
2925
- player: playerState
2926
- }), React.createElement(Shortcut, {
2927
- key: "shortcut",
2928
- order: 99,
2929
- actions: actions,
2930
- player: playerState,
2931
- manager: manager
2932
- })];
2933
- }, [actions, handleVideoRef, manager, playerState]);
2934
- var containsBigPlayButton = useCallback(function (nodes) {
2935
- var found = false;
2936
- React.Children.forEach(nodes, function (child) {
2937
- if (found) {
2938
- return;
2939
- }
2940
- if (!React.isValidElement(child)) {
2941
- return;
2942
- }
2943
- var t = child.type;
2944
- var name = t.displayName || t.name;
2945
- if (child.type === BigPlayButton || name === 'BigPlayButton' || child.props['data-big-play-button'] === true) {
2946
- found = true;
2947
- return;
2948
- }
2949
- if (child.props && child.props.children) {
2950
- if (containsBigPlayButton(child.props.children)) {
2951
- found = true;
2952
- }
2953
- }
2954
- });
2955
- return found;
2956
- }, []);
2957
- var getChildren = useCallback(function (propsForChildren) {
2958
- // Do not forward layout-only props like `fluid` to children to avoid DOM attribute warnings.
2959
- var _ignored = propsForChildren.className,
2960
- originalChildren = propsForChildren.children,
2961
- _fluid = propsForChildren.fluid,
2962
- _bp = propsForChildren.bigPlayButtonPosition,
2963
- _hide = propsForChildren.hideDefaultBigPlayButton,
2964
- rest = _objectWithoutPropertiesLoose(propsForChildren, ["className", "children", "fluid", "bigPlayButtonPosition", "hideDefaultBigPlayButton"]);
2965
- var userChildren = React.Children.toArray(children).filter(function (child) {
2966
- return !isVideoChild(child);
2967
- });
2968
- var hasUserBigPlayButton = containsBigPlayButton(children);
2969
- var includeDefaultBigPlay = !hideDefaultBigPlayButton && !hasUserBigPlayButton;
2970
- var defaultChildren = getDefaultChildren(originalChildren, includeDefaultBigPlay, bigPlayButtonPosition);
2971
- var parentProps = _extends({}, rest, {
2972
- actions: actions,
2973
- player: playerState,
2974
- manager: manager
2975
- });
2976
- return mergeAndSortChildren(defaultChildren, userChildren, parentProps);
2977
- }, [actions, bigPlayButtonPosition, children, containsBigPlayButton, getDefaultChildren, hideDefaultBigPlayButton, manager, playerState]);
2978
- var setWidthOrHeight = useCallback(function (style, name, value) {
2979
- var styleVal;
2980
- if (typeof value === 'string') {
2981
- if (value === 'auto') {
2982
- styleVal = 'auto';
2983
- } else if (/\d+%/.test(value)) {
2984
- styleVal = value;
2985
- }
2986
- } else if (typeof value === 'number') {
2987
- styleVal = value + "px";
2988
- }
2989
- if (styleVal) {
2990
- style[name] = styleVal;
2991
- }
2992
- }, []);
2993
- var playerStyle = useMemo(function () {
2994
- var style = {};
2995
- var resolvedAspectRatio = aspectRatio;
2996
- if (resolvedAspectRatio === undefined || resolvedAspectRatio === 'auto') {
2997
- if (playerState.videoWidth) {
2998
- resolvedAspectRatio = playerState.videoWidth + ":" + playerState.videoHeight;
2999
- } else {
3000
- resolvedAspectRatio = '16:9';
3001
- }
3002
- }
3003
- var _resolvedAspectRatio$ = resolvedAspectRatio.split(':').map(Number),
3004
- ratioWidth = _resolvedAspectRatio$[0],
3005
- ratioHeight = _resolvedAspectRatio$[1];
3006
- var ratioMultiplier = ratioHeight / ratioWidth;
3007
- var resolvedWidth = width;
3008
- if (resolvedWidth === undefined) {
3009
- if (typeof height === 'number') {
3010
- resolvedWidth = height / ratioMultiplier;
3011
- } else if (typeof height === 'string' && height !== 'auto') {
3012
- resolvedWidth = parseFloat(height) / ratioMultiplier;
3013
- } else {
3014
- resolvedWidth = playerState.videoWidth || 400;
3015
- }
3016
- }
3017
- var resolvedHeight = height;
3018
- if (resolvedHeight === undefined) {
3019
- if (typeof resolvedWidth === 'number') {
3020
- resolvedHeight = resolvedWidth * ratioMultiplier;
3021
- } else if (typeof resolvedWidth === 'string' && resolvedWidth !== 'auto') {
3022
- resolvedHeight = parseFloat(resolvedWidth) * ratioMultiplier;
3023
- }
3024
- }
3025
- if (fluid) {
3026
- style.paddingTop = ratioMultiplier * 100 + "%";
3027
- } else {
3028
- if (resolvedWidth !== undefined) {
3029
- setWidthOrHeight(style, 'width', resolvedWidth);
3030
- }
3031
- if (resolvedHeight !== undefined) {
3032
- setWidthOrHeight(style, 'height', resolvedHeight);
3033
- }
3034
- }
3035
- return style;
3036
- }, [aspectRatio, fluid, height, playerState.videoHeight, playerState.videoWidth, setWidthOrHeight, width]);
3037
- var startControlsTimer = useCallback(function () {
3038
- var controlBarActiveTime = 3000;
3039
- React.Children.forEach(children, function (element) {
3040
- if (!React.isValidElement(element) || element.type !== ControlBar) {
3041
- return;
3042
- }
3043
- var _ref = element.props,
3044
- autoHideTime = _ref.autoHideTime;
3045
- if (typeof autoHideTime === 'number') {
3046
- controlBarActiveTime = autoHideTime;
3047
- }
3048
- });
3049
- actions.userActivate(true);
3050
- if (controlsHideTimerRef.current) {
3051
- clearTimeout(controlsHideTimerRef.current);
3052
- }
3053
- controlsHideTimerRef.current = window.setTimeout(function () {
3054
- actions.userActivate(false);
3055
- }, controlBarActiveTime);
3056
- }, [actions, children]);
3057
- var throttledMouseMove = useMemo(function () {
3058
- return throttle(function () {
3059
- startControlsTimer();
3060
- }, 250);
3061
- }, [startControlsTimer]);
3062
- var handleMouseDown = useCallback(function () {
3063
- startControlsTimer();
3064
- }, [startControlsTimer]);
3065
- var handleMouseMove = useCallback(function () {
3066
- throttledMouseMove();
3067
- }, [throttledMouseMove]);
3068
- var handleKeyDown = useCallback(function () {
3069
- startControlsTimer();
3070
- }, [startControlsTimer]);
3071
- var handleFocus = useCallback(function () {
3072
- actions.activate(true);
3073
- }, [actions]);
3074
- var handleBlur = useCallback(function () {
3075
- actions.activate(false);
3076
- }, [actions]);
3077
- var rootRef = useCallback(function (node) {
3078
- manager.rootElement = node;
3079
- }, [manager]);
3080
- var childProps = useMemo(function () {
3081
- var _videoComponentRef$cu, _videoComponentRef$cu2;
3082
- return _extends({}, passThroughProps, {
3083
- fluid: fluid,
3084
- bigPlayButtonPosition: bigPlayButtonPosition,
3085
- hideDefaultBigPlayButton: hideDefaultBigPlayButton,
3086
- player: playerState,
3087
- actions: actions,
3088
- manager: manager,
3089
- store: manager.store,
3090
- video: (_videoComponentRef$cu = (_videoComponentRef$cu2 = videoComponentRef.current) === null || _videoComponentRef$cu2 === void 0 ? void 0 : _videoComponentRef$cu2.video) !== null && _videoComponentRef$cu !== void 0 ? _videoComponentRef$cu : null
3091
- });
3092
- }, [actions, bigPlayButtonPosition, fluid, hideDefaultBigPlayButton, manager, passThroughProps, playerState]);
3093
- var childElements = useMemo(function () {
3094
- return getChildren(childProps);
3095
- }, [childProps, getChildren]);
3096
- useImperativeHandle(ref, function () {
3097
- return {
3098
- manager: manager,
3099
- actions: actions,
3100
- video: videoComponentRef.current,
3101
- getState: function getState() {
3102
- return manager.getState();
3103
- },
3104
- get playbackRate() {
3105
- var _videoComponentRef$cu3, _videoComponentRef$cu4;
3106
- return (_videoComponentRef$cu3 = (_videoComponentRef$cu4 = videoComponentRef.current) === null || _videoComponentRef$cu4 === void 0 ? void 0 : _videoComponentRef$cu4.playbackRate) !== null && _videoComponentRef$cu3 !== void 0 ? _videoComponentRef$cu3 : 1;
3107
- },
3108
- set playbackRate(rate) {
3109
- if (videoComponentRef.current) {
3110
- videoComponentRef.current.playbackRate = rate;
3111
- }
3112
- },
3113
- get muted() {
3114
- var _videoComponentRef$cu5, _videoComponentRef$cu6;
3115
- return (_videoComponentRef$cu5 = (_videoComponentRef$cu6 = videoComponentRef.current) === null || _videoComponentRef$cu6 === void 0 ? void 0 : _videoComponentRef$cu6.muted) !== null && _videoComponentRef$cu5 !== void 0 ? _videoComponentRef$cu5 : false;
3116
- },
3117
- set muted(value) {
3118
- if (videoComponentRef.current) {
3119
- videoComponentRef.current.muted = value;
3120
- }
3121
- },
3122
- get volume() {
3123
- var _videoComponentRef$cu7, _videoComponentRef$cu8;
3124
- return (_videoComponentRef$cu7 = (_videoComponentRef$cu8 = videoComponentRef.current) === null || _videoComponentRef$cu8 === void 0 ? void 0 : _videoComponentRef$cu8.volume) !== null && _videoComponentRef$cu7 !== void 0 ? _videoComponentRef$cu7 : 1;
3125
- },
3126
- set volume(value) {
3127
- if (videoComponentRef.current) {
3128
- videoComponentRef.current.volume = value;
3129
- }
3130
- },
3131
- get videoWidth() {
3132
- var _videoComponentRef$cu9, _videoComponentRef$cu0;
3133
- return (_videoComponentRef$cu9 = (_videoComponentRef$cu0 = videoComponentRef.current) === null || _videoComponentRef$cu0 === void 0 ? void 0 : _videoComponentRef$cu0.videoWidth) !== null && _videoComponentRef$cu9 !== void 0 ? _videoComponentRef$cu9 : 0;
3134
- },
3135
- get videoHeight() {
3136
- var _videoComponentRef$cu1, _videoComponentRef$cu10;
3137
- return (_videoComponentRef$cu1 = (_videoComponentRef$cu10 = videoComponentRef.current) === null || _videoComponentRef$cu10 === void 0 ? void 0 : _videoComponentRef$cu10.videoHeight) !== null && _videoComponentRef$cu1 !== void 0 ? _videoComponentRef$cu1 : 0;
3138
- },
3139
- play: function play() {
3140
- var _videoComponentRef$cu11;
3141
- (_videoComponentRef$cu11 = videoComponentRef.current) === null || _videoComponentRef$cu11 === void 0 ? void 0 : _videoComponentRef$cu11.play();
3142
- },
3143
- pause: function pause() {
3144
- var _videoComponentRef$cu12;
3145
- (_videoComponentRef$cu12 = videoComponentRef.current) === null || _videoComponentRef$cu12 === void 0 ? void 0 : _videoComponentRef$cu12.pause();
3146
- },
3147
- load: function load() {
3148
- var _videoComponentRef$cu13;
3149
- (_videoComponentRef$cu13 = videoComponentRef.current) === null || _videoComponentRef$cu13 === void 0 ? void 0 : _videoComponentRef$cu13.load();
3150
- },
3151
- addTextTrack: function addTextTrack() {
3152
- var _videoComponentRef$cu14, _videoComponentRef$cu15;
3153
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3154
- args[_key] = arguments[_key];
3155
- }
3156
- return (_videoComponentRef$cu14 = (_videoComponentRef$cu15 = videoComponentRef.current) === null || _videoComponentRef$cu15 === void 0 ? void 0 : _videoComponentRef$cu15.addTextTrack.apply(_videoComponentRef$cu15, args)) !== null && _videoComponentRef$cu14 !== void 0 ? _videoComponentRef$cu14 : {};
3157
- },
3158
- canPlayType: function canPlayType() {
3159
- var _videoComponentRef$cu16, _videoComponentRef$cu17;
3160
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
3161
- args[_key2] = arguments[_key2];
3162
- }
3163
- return (_videoComponentRef$cu16 = (_videoComponentRef$cu17 = videoComponentRef.current) === null || _videoComponentRef$cu17 === void 0 ? void 0 : _videoComponentRef$cu17.canPlayType.apply(_videoComponentRef$cu17, args)) !== null && _videoComponentRef$cu16 !== void 0 ? _videoComponentRef$cu16 : '';
3164
- },
3165
- seek: function seek(time) {
3166
- var _videoComponentRef$cu18;
3167
- (_videoComponentRef$cu18 = videoComponentRef.current) === null || _videoComponentRef$cu18 === void 0 ? void 0 : _videoComponentRef$cu18.seek(time);
3168
- },
3169
- forward: function forward(seconds) {
3170
- var _videoComponentRef$cu19;
3171
- (_videoComponentRef$cu19 = videoComponentRef.current) === null || _videoComponentRef$cu19 === void 0 ? void 0 : _videoComponentRef$cu19.forward(seconds);
3172
- },
3173
- replay: function replay(seconds) {
3174
- var _videoComponentRef$cu20;
3175
- (_videoComponentRef$cu20 = videoComponentRef.current) === null || _videoComponentRef$cu20 === void 0 ? void 0 : _videoComponentRef$cu20.replay(seconds);
3176
- },
3177
- toggleFullscreen: function toggleFullscreen() {
3178
- var _videoComponentRef$cu21;
3179
- (_videoComponentRef$cu21 = videoComponentRef.current) === null || _videoComponentRef$cu21 === void 0 ? void 0 : _videoComponentRef$cu21.toggleFullscreen();
3180
- },
3181
- subscribeToStateChange: function subscribeToStateChange(listener) {
3182
- return manager.subscribeToPlayerStateChange(listener);
3183
- }
3184
- };
3185
- }, [actions, manager]);
3186
- var paused = playerState.paused,
3187
- hasStarted = playerState.hasStarted,
3188
- waiting = playerState.waiting,
3189
- seeking = playerState.seeking,
3190
- isFullscreen = playerState.isFullscreen,
3191
- userActivity = playerState.userActivity;
3192
- return React.createElement("div", {
3193
- className: classNames({
3194
- 'video-react-player-controls-enabled': true,
3195
- 'video-react-player-has-started': hasStarted,
3196
- 'video-react-player-paused': paused,
3197
- 'video-react-player-playing': !paused,
3198
- 'video-react-player-waiting': waiting,
3199
- 'video-react-player-seeking': seeking,
3200
- 'video-react-player-fluid': fluid,
3201
- 'video-react-player-fullscreen': isFullscreen,
3202
- 'video-react-player-user-inactive': !userActivity,
3203
- 'video-react-player-user-active': userActivity,
3204
- 'video-react-player-workinghover': !IS_IOS
3205
- }, 'video-react-player', className),
3206
- style: playerStyle,
3207
- ref: rootRef,
3208
- role: "region",
3209
- onTouchStart: handleMouseDown,
3210
- onMouseDown: handleMouseDown,
3211
- onTouchMove: handleMouseMove,
3212
- onMouseMove: handleMouseMove,
3213
- onKeyDown: handleKeyDown,
3214
- onFocus: handleFocus,
3215
- onBlur: handleBlur,
3216
- tabIndex: -1
3217
- }, childElements);
3218
- });
3219
- Player.displayName = 'Player';
3220
-
3221
- /**
3222
-
3223
- * Copyright (c) 2016 Video-React contributors
3224
- * Copyright (c) 2025 ZingMe.Vn
3225
- *
3226
- * This source code is licensed under the MIT license found in the
3227
- * LICENSE file in the root directory of this source tree.
3228
- */
3229
- var createForwardReplayControl = function createForwardReplayControl(mode) {
3230
- var ForwardReplayControl = forwardRef(function (_ref, ref) {
3231
- var actions = _ref.actions,
3232
- _ref$seconds = _ref.seconds,
3233
- seconds = _ref$seconds === void 0 ? 10 : _ref$seconds,
3234
- className = _ref.className;
3235
- var handleClick = useCallback(function () {
3236
- if (mode === 'forward') {
3237
- actions.forward(seconds);
3238
- } else {
3239
- actions.replay(seconds);
3240
- }
3241
- }, [actions, seconds]);
3242
- var classNames = ['video-react-player-control', 'video-react-player-button', 'video-react-player-icon', "video-react-player-icon-" + mode + "-" + seconds, "video-react-player-" + mode + "-control"];
3243
- if (className) {
3244
- classNames.push(className);
3245
- }
3246
- return React.createElement("button", {
3247
- ref: ref,
3248
- className: classNames.join(' '),
3249
- type: "button",
3250
- onClick: handleClick
3251
- }, React.createElement("span", {
3252
- className: "video-react-player-control-text"
3253
- }, mode + " " + seconds + " seconds"));
3254
- });
3255
- ForwardReplayControl.displayName = "ForwardReplayControl(" + mode + ")";
3256
- return ForwardReplayControl;
3257
- };
3258
-
3259
- /**
3260
-
3261
- * Copyright (c) 2016 Video-React contributors
3262
- * Copyright (c) 2025 ZingMe.Vn
3263
- *
3264
- * This source code is licensed under the MIT license found in the
3265
- * LICENSE file in the root directory of this source tree.
3266
- */
3267
-
3268
- // Pass mode into parent function
3269
- var ForwardControl = createForwardReplayControl('forward');
3270
- ForwardControl.displayName = 'ForwardControl';
3271
-
3272
- /**
3273
-
3274
- * Copyright (c) 2016 Video-React contributors
3275
- * Copyright (c) 2025 ZingMe.Vn
3276
- *
3277
- * This source code is licensed under the MIT license found in the
3278
- * LICENSE file in the root directory of this source tree.
3279
- */
3280
-
3281
- // Pass mode into parent function
3282
- var ReplayControl = createForwardReplayControl('replay');
3283
- ReplayControl.displayName = 'ReplayControl';
3284
-
3285
- /**
3286
-
3287
- * Copyright (c) 2016 Video-React contributors
3288
- * Copyright (c) 2025 ZingMe.Vn
3289
- *
3290
- * This source code is licensed under the MIT license found in the
3291
- * LICENSE file in the root directory of this source tree.
3292
- */
3293
- var Menu = function Menu(_ref) {
3294
- var children = _ref.children;
3295
- var handleClick = function handleClick(event) {
3296
- event.preventDefault();
3297
- };
3298
- return React.createElement("div", {
3299
- className: "video-react-player-menu video-react-player-lock-showing",
3300
- role: "presentation",
3301
- onClick: handleClick
3302
- }, React.createElement("ul", {
3303
- className: "video-react-player-menu-content"
3304
- }, children));
3305
- };
3306
- Menu.displayName = 'Menu';
3307
-
3308
- /**
3309
-
3310
- * Copyright (c) 2016 Video-React contributors
3311
- * Copyright (c) 2025 ZingMe.Vn
3312
- *
3313
- * This source code is licensed under the MIT license found in the
3314
- * LICENSE file in the root directory of this source tree.
3315
- */
3316
- var MenuItem = function MenuItem(_ref) {
3317
- var item = _ref.item,
3318
- index = _ref.index,
3319
- activateIndex = _ref.activateIndex,
3320
- onSelectItem = _ref.onSelectItem;
3321
- var handleClick = function handleClick() {
3322
- onSelectItem(index);
3323
- };
3324
- return React.createElement("li", {
3325
- className: classNames({
3326
- 'video-react-player-menu-item': true,
3327
- 'video-react-player-selected': index === activateIndex
3328
- }),
3329
- role: "menuitem",
3330
- onClick: handleClick
3331
- }, item.label, React.createElement("span", {
3332
- className: "video-react-player-control-text"
3333
- }));
3334
- };
3335
- MenuItem.displayName = 'MenuItem';
3336
-
3337
- var MenuButton = /*#__PURE__*/function (_Component) {
3338
- _inheritsLoose(MenuButton, _Component);
3339
- function MenuButton() {
3340
- var _this$props$selectedI;
3341
- var _this;
3342
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3343
- args[_key] = arguments[_key];
3344
- }
3345
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
3346
- _this.state = {
3347
- active: false,
3348
- activateIndex: (_this$props$selectedI = _this.props.selectedIndex) !== null && _this$props$selectedI !== void 0 ? _this$props$selectedI : 0
3349
- };
3350
- _this.commitSelection = function (index) {
3351
- _this.setState({
3352
- activateIndex: index
3353
- });
3354
- _this.handleIndexChange(index);
3355
- };
3356
- _this.activateMenuItem = function (index) {
3357
- if (index === void 0) {
3358
- index = 0;
3359
- }
3360
- _this.setState({
3361
- activateIndex: index
3362
- });
3363
- _this.handleIndexChange(index);
3364
- };
3365
- _this.handleIndexChange = function (index) {
3366
- _this.props.onSelectItem(index);
3367
- };
3368
- _this.handleClick = function () {
3369
- _this.setState(function (prevState) {
3370
- return {
3371
- active: !prevState.active
3372
- };
3373
- });
3374
- };
3375
- _this.handleFocus = function () {
3376
- document.addEventListener('keydown', _this.handleKeyPress);
3377
- };
3378
- _this.handleBlur = function () {
3379
- _this.setState({
3380
- active: false
3381
- });
3382
- document.removeEventListener('keydown', _this.handleKeyPress);
3383
- };
3384
- _this.handleUpArrow = function (event) {
3385
- var _this$props$items;
3386
- var items = (_this$props$items = _this.props.items) !== null && _this$props$items !== void 0 ? _this$props$items : [];
3387
- if (_this.state.active && items.length) {
3388
- event.preventDefault();
3389
- var newIndex = (_this.state.activateIndex - 1 + items.length) % items.length;
3390
- _this.activateMenuItem(newIndex);
3391
- }
3392
- };
3393
- _this.handleDownArrow = function (event) {
3394
- var _this$props$items2;
3395
- var items = (_this$props$items2 = _this.props.items) !== null && _this$props$items2 !== void 0 ? _this$props$items2 : [];
3396
- if (_this.state.active && items.length) {
3397
- event.preventDefault();
3398
- var newIndex = (_this.state.activateIndex + 1) % items.length;
3399
- _this.activateMenuItem(newIndex);
3400
- }
3401
- };
3402
- _this.handleTab = function (event) {
3403
- if (_this.state.active) {
3404
- event.preventDefault();
3405
- _this.commitSelection(_this.state.activateIndex);
3406
- }
3407
- };
3408
- _this.handleReturn = function (event) {
3409
- event.preventDefault();
3410
- if (_this.state.active) {
3411
- _this.commitSelection(_this.state.activateIndex);
3412
- } else {
3413
- _this.setState({
3414
- active: true
3415
- });
3416
- }
3417
- };
3418
- _this.handleEscape = function () {
3419
- _this.setState({
3420
- active: false,
3421
- activateIndex: 0
3422
- });
3423
- };
3424
- _this.handleKeyPress = function (event) {
3425
- if (event.which === 27) {
3426
- _this.handleEscape();
3427
- } else if (event.which === 9) {
3428
- _this.handleTab(event);
3429
- } else if (event.which === 13) {
3430
- _this.handleReturn(event);
3431
- } else if (event.which === 38) {
3432
- _this.handleUpArrow(event);
3433
- } else if (event.which === 40) {
3434
- _this.handleDownArrow(event);
3435
- }
3436
- };
3437
- _this.handleSelectItem = function (index) {
3438
- _this.commitSelection(index);
3439
- };
3440
- return _this;
3441
- }
3442
- var _proto = MenuButton.prototype;
3443
- _proto.componentWillUnmount = function componentWillUnmount() {
3444
- document.removeEventListener('keydown', this.handleKeyPress);
3445
- };
3446
- _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
3447
- if (prevProps.selectedIndex !== this.props.selectedIndex && typeof this.props.selectedIndex === 'number') {
3448
- this.activateMenuItem(this.props.selectedIndex);
3449
- }
3450
- };
3451
- _proto.renderMenu = function renderMenu() {
3452
- var _this$props$items3,
3453
- _this2 = this;
3454
- if (!this.state.active) {
3455
- return null;
3456
- }
3457
- var items = (_this$props$items3 = this.props.items) !== null && _this$props$items3 !== void 0 ? _this$props$items3 : [];
3458
- return React.createElement(Menu, null, items.map(function (item, index) {
3459
- return React.createElement(MenuItem, {
3460
- item: item,
3461
- index: index,
3462
- onSelectItem: _this2.handleSelectItem,
3463
- activateIndex: _this2.state.activateIndex,
3464
- key: "item-" + index
3465
- });
3466
- }));
3467
- };
3468
- _proto.render = function render() {
3469
- var _this$props = this.props,
3470
- inline = _this$props.inline,
3471
- className = _this$props.className,
3472
- children = _this$props.children;
3473
- return React.createElement(ClickableComponent, {
3474
- className: classNames(className, {
3475
- 'video-react-player-menu-button-inline': !!inline,
3476
- 'video-react-player-menu-button-popup': !inline,
3477
- 'video-react-player-menu-button-active': this.state.active
3478
- }, 'video-react-player-control video-react-player-button video-react-player-menu-button'),
3479
- onClick: this.handleClick,
3480
- onFocus: this.handleFocus,
3481
- onBlur: this.handleBlur
3482
- }, children, this.renderMenu());
3483
- };
3484
- return MenuButton;
3485
- }(Component);
3486
- MenuButton.displayName = 'MenuButton';
3487
- MenuButton.defaultProps = {
3488
- items: [],
3489
- selectedIndex: 0
3490
- };
3491
-
3492
- /**
3493
-
3494
- * Copyright (c) 2016 Video-React contributors
3495
- * Copyright (c) 2025 ZingMe.Vn
3496
- *
3497
- * This source code is licensed under the MIT license found in the
3498
- * LICENSE file in the root directory of this source tree.
3499
- */
3500
- var DEFAULT_RATES = [2, 1.5, 1.25, 1, 0.5, 0.25];
3501
- var PlaybackRateMenuButton = function PlaybackRateMenuButton(_ref) {
3502
- var actions = _ref.actions,
3503
- player = _ref.player,
3504
- _ref$rates = _ref.rates,
3505
- rates = _ref$rates === void 0 ? DEFAULT_RATES : _ref$rates,
3506
- className = _ref.className;
3507
- var items = useMemo(function () {
3508
- return rates.map(function (rate) {
3509
- return {
3510
- label: rate + "x",
3511
- value: rate
3512
- };
3513
- });
3514
- }, [rates]);
3515
- var selectedIndex = useMemo(function () {
3516
- var index = rates.indexOf(player.playbackRate);
3517
- if (index >= 0) {
3518
- return index;
3519
- }
3520
- var fallback = rates.indexOf(1);
3521
- return fallback >= 0 ? fallback : 0;
3522
- }, [player.playbackRate, rates]);
3523
- var handleSelectItem = useCallback(function (index) {
3524
- if (index >= 0 && index < rates.length) {
3525
- actions.changeRate(rates[index]);
3526
- }
3527
- }, [actions, rates]);
3528
- return React.createElement(MenuButton, {
3529
- className: classNames('video-react-player-playback-rate', className),
3530
- onSelectItem: handleSelectItem,
3531
- items: items,
3532
- selectedIndex: selectedIndex
3533
- }, React.createElement("span", {
3534
- className: "video-react-player-control-text"
3535
- }, "Playback Rate"), React.createElement("div", {
3536
- className: "video-react-player-playback-rate-value"
3537
- }, player.playbackRate.toFixed(2) + "x"));
3538
- };
3539
- PlaybackRateMenuButton.displayName = 'PlaybackRateMenuButton';
3540
-
3541
- /**
3542
-
3543
- * Copyright (c) 2016 Video-React contributors
3544
- * Copyright (c) 2025 ZingMe.Vn
3545
- *
3546
- * This source code is licensed under the MIT license found in the
3547
- * LICENSE file in the root directory of this source tree.
3548
- */
3549
- var PlaybackRate = function PlaybackRate(props) {
3550
- useEffect(function () {
3551
- deprecatedWarning('PlaybackRate', 'PlaybackRateMenuButton');
3552
- }, []);
3553
- return React.createElement(PlaybackRateMenuButton, props);
3554
- };
3555
- PlaybackRate.displayName = 'PlaybackRate';
3556
-
3557
- /**
3558
-
3559
- * Copyright (c) 2016 Video-React contributors
3560
- * Copyright (c) 2025 ZingMe.Vn
3561
- *
3562
- * This source code is licensed under the MIT license found in the
3563
- * LICENSE file in the root directory of this source tree.
3564
- */
3565
- var DEFAULT_KINDS = ['captions', 'subtitles'];
3566
- var ClosedCaptionButton = function ClosedCaptionButton(_ref) {
3567
- var player = _ref.player,
3568
- actions = _ref.actions,
3569
- className = _ref.className,
3570
- _ref$offMenuText = _ref.offMenuText,
3571
- offMenuText = _ref$offMenuText === void 0 ? 'Off' : _ref$offMenuText,
3572
- _ref$showOffMenu = _ref.showOffMenu,
3573
- showOffMenu = _ref$showOffMenu === void 0 ? true : _ref$showOffMenu,
3574
- _ref$kinds = _ref.kinds,
3575
- kinds = _ref$kinds === void 0 ? DEFAULT_KINDS : _ref$kinds;
3576
- var textTrackItems = useMemo(function () {
3577
- var items = [];
3578
- var tracks = Array.from(player.textTracks || []);
3579
- if (showOffMenu) {
3580
- items.push({
3581
- label: offMenuText,
3582
- value: null
3583
- });
3584
- }
3585
- tracks.forEach(function (textTrack) {
3586
- if (kinds.length && !kinds.includes(textTrack.kind)) {
3587
- return;
3588
- }
3589
- items.push({
3590
- label: textTrack.label || textTrack.language || 'Unknown',
3591
- value: textTrack.language || null
3592
- });
3593
- });
3594
- var selectedIndex = items.findIndex(function (item) {
3595
- return player.activeTextTrack && item.value !== null && player.activeTextTrack.language === item.value;
3596
- });
3597
- return {
3598
- items: items,
3599
- selectedIndex: selectedIndex >= 0 ? selectedIndex : 0
3600
- };
3601
- }, [kinds, offMenuText, player.activeTextTrack, player.textTracks, showOffMenu]);
3602
- var handleSelectItem = useCallback(function (index) {
3603
- Array.from(player.textTracks || []).forEach(function (textTrack, trackIndex) {
3604
- var normalizedIndex = showOffMenu ? trackIndex + 1 : trackIndex;
3605
- if (index === normalizedIndex) {
3606
- textTrack.mode = 'showing';
3607
- actions.activateTextTrack(textTrack);
3608
- } else {
3609
- textTrack.mode = 'hidden';
3610
- }
3611
- });
3612
- if (showOffMenu && index === 0) {
3613
- actions.activateTextTrack(null);
3614
- }
3615
- }, [actions, player.textTracks, showOffMenu]);
3616
- return React.createElement(MenuButton, {
3617
- className: classNames('video-react-player-closed-caption', className),
3618
- onSelectItem: handleSelectItem,
3619
- items: textTrackItems.items,
3620
- selectedIndex: textTrackItems.selectedIndex
3621
- }, React.createElement("span", {
3622
- className: "video-react-player-control-text"
3623
- }, "Closed Caption"));
3624
- };
3625
- ClosedCaptionButton.displayName = 'ClosedCaptionButton';
3626
-
3627
- /**
3628
-
3629
- * Copyright (c) 2016 Video-React contributors
3630
- * Copyright (c) 2025 ZingMe.Vn
3631
- *
3632
- * This source code is licensed under the MIT license found in the
3633
- * LICENSE file in the root directory of this source tree.
3634
- */
3635
- var PictureInPictureToggle = function PictureInPictureToggle(_ref) {
3636
- var _player$isPictureInPi;
3637
- var actions = _ref.actions,
3638
- player = _ref.player,
3639
- className = _ref.className;
3640
- var handleClick = useCallback(function () {
3641
- actions.togglePictureInPicture();
3642
- }, [actions]);
3643
- var isPip = (_player$isPictureInPi = player.isPictureInPicture) !== null && _player$isPictureInPi !== void 0 ? _player$isPictureInPi : false;
3644
- return React.createElement("button", {
3645
- className: classNames(className, {
3646
- 'video-react-player-icon-picture-in-picture-exit': isPip,
3647
- 'video-react-player-icon-picture-in-picture': !isPip
3648
- }, 'video-react-player-picture-in-picture-control video-react-player-control video-react-player-button video-react-player-icon'),
3649
- type: "button",
3650
- tabIndex: 0,
3651
- onClick: handleClick
3652
- }, React.createElement("span", {
3653
- className: "video-react-player-control-text"
3654
- }, "Picture-in-Picture"));
3655
- };
3656
- PictureInPictureToggle.displayName = 'PictureInPictureToggle';
3657
-
3658
- /**
3659
-
3660
- * Copyright (c) 2016 Video-React contributors
3661
- * Copyright (c) 2025 ZingMe.Vn
3662
- *
3663
- * This source code is licensed under the MIT license found in the
3664
- * LICENSE file in the root directory of this source tree.
3665
- */
3666
- var LoopToggle = forwardRef(function (_ref, ref) {
3667
- var actions = _ref.actions,
3668
- player = _ref.player,
3669
- className = _ref.className;
3670
- var isLoop = !!player.loop;
3671
- var handleClick = useCallback(function () {
3672
- actions.handleLoopChange(!isLoop);
3673
- }, [actions, isLoop]);
3674
- return React.createElement("button", {
3675
- className: classNames(className, {
3676
- 'video-react-player-icon-loop-active': isLoop,
3677
- 'video-react-player-icon-loop': !isLoop
3678
- }, 'video-react-player-loop-control video-react-player-control video-react-player-button video-react-player-icon'),
3679
- ref: ref,
3680
- type: "button",
3681
- tabIndex: 0,
3682
- onClick: handleClick
3683
- }, React.createElement("span", {
3684
- className: "video-react-player-control-text"
3685
- }, isLoop ? 'Loop On' : 'Loop Off'));
3686
- });
3687
- LoopToggle.displayName = 'LoopToggle';
3688
-
3689
- /**
3690
-
3691
- * Copyright (c) 2016 Video-React contributors
3692
- * Copyright (c) 2025 ZingMe.Vn
3693
- *
3694
- * This source code is licensed under the MIT license found in the
3695
- * LICENSE file in the root directory of this source tree.
3696
- */
3697
- var TheaterModeToggle = function TheaterModeToggle(_ref) {
3698
- var _player$isTheater;
3699
- var actions = _ref.actions,
3700
- player = _ref.player,
3701
- className = _ref.className;
3702
- var handleClick = useCallback(function () {
3703
- actions.toggleTheaterMode(!player.isTheater);
3704
- }, [actions, player.isTheater]);
3705
- var isTheater = (_player$isTheater = player.isTheater) !== null && _player$isTheater !== void 0 ? _player$isTheater : false;
3706
- return React.createElement("button", {
3707
- className: classNames(className, {
3708
- 'video-react-player-icon-theater-exit': isTheater,
3709
- 'video-react-player-icon-theater': !isTheater
3710
- }, 'video-react-player-theater-control video-react-player-control video-react-player-button video-react-player-icon'),
3711
- type: "button",
3712
- tabIndex: 0,
3713
- onClick: handleClick
3714
- }, React.createElement("span", {
3715
- className: "video-react-player-control-text"
3716
- }, isTheater ? 'Exit Theater Mode' : 'Theater Mode'));
3717
- };
3718
- TheaterModeToggle.displayName = 'TheaterModeToggle';
3719
-
3720
- /**
3721
-
3722
- * Copyright (c) 2016 Video-React contributors
3723
- * Copyright (c) 2025 ZingMe.Vn
3724
- *
3725
- * This source code is licensed under the MIT license found in the
3726
- * LICENSE file in the root directory of this source tree.
3727
- */
3728
- var DownloadButton = function DownloadButton(_ref) {
3729
- var player = _ref.player,
3730
- className = _ref.className,
3731
- _ref$filename = _ref.filename,
3732
- filename = _ref$filename === void 0 ? 'video' : _ref$filename;
3733
- var handleClick = useCallback(function () {
3734
- if (!player.currentSrc) {
3735
- return;
3736
- }
3737
- var link = document.createElement('a');
3738
- link.href = player.currentSrc;
3739
- link.download = filename;
3740
- link.click();
3741
- }, [filename, player.currentSrc]);
3742
- return React.createElement("button", {
3743
- className: classNames(className, 'video-react-player-icon-download', 'video-react-player-download-control video-react-player-control video-react-player-button video-react-player-icon'),
3744
- type: "button",
3745
- tabIndex: 0,
3746
- onClick: handleClick
3747
- }, React.createElement("span", {
3748
- className: "video-react-player-control-text"
3749
- }, "Download"));
3750
- };
3751
- DownloadButton.displayName = 'DownloadButton';
3752
-
3753
- /**
3754
-
3755
- * Copyright (c) 2016 Video-React contributors
3756
- * Copyright (c) 2025 ZingMe.Vn
3757
- *
3758
- * This source code is licensed under the MIT license found in the
3759
- * LICENSE file in the root directory of this source tree.
3760
- */
3761
- var ScreenshotButton = function ScreenshotButton(_ref) {
3762
- var actions = _ref.actions,
3763
- className = _ref.className;
3764
- var handleClick = useCallback(function () {
3765
- actions.takeScreenshot();
3766
- }, [actions]);
3767
- return React.createElement("button", {
3768
- className: classNames(className, 'video-react-player-icon-camera', 'video-react-player-screenshot-control video-react-player-control video-react-player-button video-react-player-icon'),
3769
- type: "button",
3770
- tabIndex: 0,
3771
- onClick: handleClick
3772
- }, React.createElement("span", {
3773
- className: "video-react-player-control-text"
3774
- }, "Screenshot"));
3775
- };
3776
- ScreenshotButton.displayName = 'ScreenshotButton';
3777
-
3778
- /**
3779
-
3780
- * Copyright (c) 2016 Video-React contributors
3781
- * Copyright (c) 2025 ZingMe.Vn
3782
- *
3783
- * This source code is licensed under the MIT license found in the
3784
- * LICENSE file in the root directory of this source tree.
3785
- */
3786
- var DEFAULT_QUALITIES = ['auto', '1080p', '720p', '480p', '360p', '240p'];
3787
- var QualityMenuButton = function QualityMenuButton(_ref) {
3788
- var _ref$qualities = _ref.qualities,
3789
- qualities = _ref$qualities === void 0 ? DEFAULT_QUALITIES : _ref$qualities,
3790
- actions = _ref.actions,
3791
- player = _ref.player,
3792
- className = _ref.className;
3793
- var items = useMemo(function () {
3794
- return qualities.map(function (quality) {
3795
- return {
3796
- label: quality,
3797
- value: quality
3798
- };
3799
- });
3800
- }, [qualities]);
3801
- var currentQuality = player.quality || 'auto';
3802
- var selectedIndex = useMemo(function () {
3803
- var index = qualities.indexOf(currentQuality);
3804
- return index >= 0 ? index : 0;
3805
- }, [currentQuality, qualities]);
3806
- var handleSelectItem = useCallback(function (index) {
3807
- if (index >= 0 && index < qualities.length) {
3808
- actions.changeQuality(qualities[index]);
3809
- }
3810
- }, [actions, qualities]);
3811
- return React.createElement(MenuButton, {
3812
- className: classNames('video-react-player-quality-menu', className),
3813
- onSelectItem: handleSelectItem,
3814
- items: items,
3815
- selectedIndex: selectedIndex
3816
- }, React.createElement("span", {
3817
- className: "video-react-player-control-text"
3818
- }, "Quality"), React.createElement("div", {
3819
- className: "video-react-player-quality-value"
3820
- }, currentQuality));
3821
- };
3822
- QualityMenuButton.displayName = 'QualityMenuButton';
3823
-
3824
- function RemainingTimeDisplay(_ref) {
3825
- var _ref$player = _ref.player,
3826
- currentTime = _ref$player.currentTime,
3827
- duration = _ref$player.duration,
3828
- className = _ref.className;
3829
- var remainingTime = duration - currentTime;
3830
- var formattedTime = formatTime(remainingTime);
3831
- return React.createElement("div", {
3832
- className: classNames('video-react-player-remaining-time video-react-player-time-control video-react-player-control', className)
3833
- }, React.createElement("div", {
3834
- className: "video-react-player-remaining-time-display",
3835
- "aria-live": "off"
3836
- }, React.createElement("span", {
3837
- className: "video-react-player-control-text"
3838
- }, "Remaining Time "), "-" + formattedTime));
3839
- }
3840
- RemainingTimeDisplay.displayName = 'RemainingTimeDisplay';
3841
-
3842
- /**
3843
-
3844
- * Copyright (c) 2016 Video-React contributors
3845
- * Copyright (c) 2025 ZingMe.Vn
3846
- *
3847
- * This source code is licensed under the MIT license found in the
3848
- * LICENSE file in the root directory of this source tree.
3849
- */
3850
-
3851
- /**
3852
-
3853
- * Copyright (c) 2016 Video-React contributors
3854
- * Copyright (c) 2025 ZingMe.Vn
3855
- *
3856
- * This source code is licensed under the MIT license found in the
3857
- * LICENSE file in the root directory of this source tree.
3858
- */
3859
-
3860
- export { Bezel, BigPlayButton, ClosedCaptionButton, ControlBar, CurrentTimeDisplay, DownloadButton, DurationDisplay, ForwardControl, FullscreenToggle, LoadProgressBar, LoadingSpinner, LoopToggle, MenuButton, MouseTimeDisplay, PictureInPictureToggle, PlayProgressBar, PlayToggle, PlaybackRate, PlaybackRateMenuButton, Player, PosterImage, ProgressControl, QualityMenuButton, RemainingTimeDisplay, ReplayControl, ScreenshotButton, SeekBar, Shortcut, Slider, TheaterModeToggle, TimeDivider, Video, VolumeMenuButton, operationReducer, playerActions, playerReducer, videoActions };
3861
- //# sourceMappingURL=video-react-player.es.js.map