@capgo/capacitor-video-player 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CapgoCapacitorVideoPlayer.podspec +17 -0
  2. package/Package.swift +28 -0
  3. package/README.md +431 -0
  4. package/android/build.gradle +72 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/java/com/capgo/videoplayer/FullscreenExoPlayerFragment.java +1406 -0
  7. package/android/src/main/java/com/capgo/videoplayer/Notifications/MyRunnable.java +21 -0
  8. package/android/src/main/java/com/capgo/videoplayer/Notifications/NotificationCenter.java +61 -0
  9. package/android/src/main/java/com/capgo/videoplayer/PickerVideo/AdapterVideoList.java +47 -0
  10. package/android/src/main/java/com/capgo/videoplayer/PickerVideo/ModelVideo.java +49 -0
  11. package/android/src/main/java/com/capgo/videoplayer/PickerVideo/PickerVideoFragment.java +116 -0
  12. package/android/src/main/java/com/capgo/videoplayer/PickerVideo/VideoRecyclerViewHolder.java +65 -0
  13. package/android/src/main/java/com/capgo/videoplayer/Utilities/FilesUtils.java +38 -0
  14. package/android/src/main/java/com/capgo/videoplayer/Utilities/FragmentUtils.java +32 -0
  15. package/android/src/main/java/com/capgo/videoplayer/VideoPlayer.java +71 -0
  16. package/android/src/main/java/com/capgo/videoplayer/VideoPlayerPlugin.java +1239 -0
  17. package/android/src/main/res/.gitkeep +0 -0
  18. package/android/src/main/res/drawable/bg_round_rect_white_50.xml +9 -0
  19. package/android/src/main/res/drawable/bg_rounded_rectangle_white_corner_rounded.xml +10 -0
  20. package/android/src/main/res/drawable/exo_close_btn.xml +12 -0
  21. package/android/src/main/res/drawable/gradient_transparent_middle.xml +12 -0
  22. package/android/src/main/res/drawable/ic_arrow_left.xml +5 -0
  23. package/android/src/main/res/drawable/ic_baseline_lq.xml +7 -0
  24. package/android/src/main/res/drawable/ic_exo_icon_fastforward.xml +35 -0
  25. package/android/src/main/res/drawable/ic_exo_icon_pause.xml +26 -0
  26. package/android/src/main/res/drawable/ic_exo_icon_play.xml +36 -0
  27. package/android/src/main/res/drawable/ic_exo_icon_rewind.xml +35 -0
  28. package/android/src/main/res/drawable/ic_expand.xml +5 -0
  29. package/android/src/main/res/drawable/ic_fit.xml +5 -0
  30. package/android/src/main/res/drawable/ic_image_background.xml +12 -0
  31. package/android/src/main/res/drawable/ic_img_16_9_background.xml +10 -0
  32. package/android/src/main/res/drawable/ic_img_9_16_background.xml +10 -0
  33. package/android/src/main/res/drawable/ic_outline_lock.xml +5 -0
  34. package/android/src/main/res/drawable/ic_outline_lock_open.xml +5 -0
  35. package/android/src/main/res/drawable/ic_pip_white.xml +5 -0
  36. package/android/src/main/res/drawable/ic_views.xml +18 -0
  37. package/android/src/main/res/drawable/ic_zoom.xml +5 -0
  38. package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
  39. package/android/src/main/res/layout/exo_playback_control_view.xml +287 -0
  40. package/android/src/main/res/layout/exoplayer_layout_youtube.xml +361 -0
  41. package/android/src/main/res/layout/fragment_fs_exoplayer.xml +50 -0
  42. package/android/src/main/res/layout/fragment_picker_video.xml +21 -0
  43. package/android/src/main/res/layout/row_video.xml +76 -0
  44. package/android/src/main/res/values/colors.xml +14 -0
  45. package/android/src/main/res/values/strings.xml +3 -0
  46. package/android/src/main/res/values/styles.xml +3 -0
  47. package/dist/docs.json +686 -0
  48. package/dist/esm/definitions.d.ts +307 -0
  49. package/dist/esm/definitions.js +2 -0
  50. package/dist/esm/definitions.js.map +1 -0
  51. package/dist/esm/index.d.ts +4 -0
  52. package/dist/esm/index.js +7 -0
  53. package/dist/esm/index.js.map +1 -0
  54. package/dist/esm/web-utils/video-types.d.ts +4 -0
  55. package/dist/esm/web-utils/video-types.js +9 -0
  56. package/dist/esm/web-utils/video-types.js.map +1 -0
  57. package/dist/esm/web-utils/videoplayer.d.ts +30 -0
  58. package/dist/esm/web-utils/videoplayer.js +323 -0
  59. package/dist/esm/web-utils/videoplayer.js.map +1 -0
  60. package/dist/esm/web.d.ts +121 -0
  61. package/dist/esm/web.js +675 -0
  62. package/dist/esm/web.js.map +1 -0
  63. package/dist/plugin.cjs.js +1019 -0
  64. package/dist/plugin.cjs.js.map +1 -0
  65. package/dist/plugin.js +1021 -0
  66. package/dist/plugin.js.map +1 -0
  67. package/ios/Sources/VideoPlayerPlugin/VideoPlayer.swift +8 -0
  68. package/ios/Sources/VideoPlayerPlugin/VideoPlayerPlugin.swift +23 -0
  69. package/ios/Tests/VideoPlayerPluginTests/VideoPlayerPluginTests.swift +15 -0
  70. package/package.json +85 -0
@@ -0,0 +1,1019 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+ var Hls = require('hls.js');
5
+
6
+ const VideoPlayer$1 = core.registerPlugin('VideoPlayer', {
7
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.VideoPlayerWeb()),
8
+ });
9
+
10
+ const possibleQueryParameterExtensions = ['file', 'extension', 'filetype', 'type', 'ext'];
11
+ const videoTypes = {
12
+ mp4: 'video/mp4',
13
+ webm: 'video/mp4',
14
+ cmaf: 'video/mp4',
15
+ cmfv: 'video/mp4',
16
+ m3u8: 'application/x-mpegURL',
17
+ };
18
+
19
+ class VideoPlayer {
20
+ constructor(mode, url, playerId, rate, exitOnEnd, loopOnEnd, container, zIndex, width, height) {
21
+ this.pipMode = false;
22
+ this._videoType = null;
23
+ this._videoContainer = null;
24
+ this._firstReadyToPlay = true;
25
+ this._isEnded = false;
26
+ this._videoRate = 1.0;
27
+ this._videoExitOnEnd = true;
28
+ this._videoLoopOnEnd = false;
29
+ this._url = url;
30
+ this._container = container;
31
+ this._mode = mode;
32
+ this._width = width ? width : 320;
33
+ this._height = height ? height : 180;
34
+ this._mode = mode;
35
+ this._videoRate = rate;
36
+ this._zIndex = zIndex ? zIndex : 1;
37
+ this._playerId = playerId;
38
+ this._videoExitOnEnd = exitOnEnd;
39
+ this._videoLoopOnEnd = loopOnEnd;
40
+ }
41
+ async initialize() {
42
+ // get the video type
43
+ const urlVideoType = this._getVideoType();
44
+ if (urlVideoType) {
45
+ // style the container
46
+ if (this._mode === 'fullscreen') {
47
+ this._container.style.position = 'absolute';
48
+ this._container.style.width = '100vw';
49
+ this._container.style.height = '100vh';
50
+ }
51
+ if (this._mode === 'embedded') {
52
+ this._container.style.position = 'relative';
53
+ this._container.style.width = this._width.toString() + 'px';
54
+ this._container.style.height = this._height.toString() + 'px';
55
+ }
56
+ this._container.style.left = '0';
57
+ this._container.style.top = '0';
58
+ this._container.style.display = 'flex';
59
+ this._container.style.alignItems = 'center';
60
+ this._container.style.justifyContent = 'center';
61
+ this._container.style.backgroundColor = '#000000';
62
+ this._container.style.zIndex = this._zIndex.toString();
63
+ const width = this._mode === 'fullscreen' ? window.innerWidth /*this._container.offsetWidth*/ : this._width;
64
+ const height = this._mode === 'fullscreen' ? window.innerHeight /*this._container.offsetHeight*/ : this._height;
65
+ const xmlns = 'http://www.w3.org/2000/svg';
66
+ const svg = document.createElementNS(xmlns, 'svg');
67
+ svg.setAttributeNS(null, 'width', width.toString());
68
+ svg.setAttributeNS(null, 'height', height.toString());
69
+ const viewbox = '0 0 ' + width.toString() + ' ' + height.toString();
70
+ svg.setAttributeNS(null, 'viewBox', viewbox);
71
+ svg.style.zIndex = (this._zIndex + 1).toString();
72
+ const rect = document.createElementNS(xmlns, 'rect');
73
+ rect.setAttributeNS(null, 'x', '0');
74
+ rect.setAttributeNS(null, 'y', '0');
75
+ rect.setAttributeNS(null, 'width', width.toString());
76
+ rect.setAttributeNS(null, 'height', height.toString());
77
+ rect.setAttributeNS(null, 'fill', '#000000');
78
+ svg.appendChild(rect);
79
+ this._container.appendChild(svg);
80
+ const heightVideo = (width * this._height) / this._width;
81
+ this._videoContainer = document.createElement('div');
82
+ this._videoContainer.style.position = 'absolute';
83
+ this._videoContainer.style.left = '0';
84
+ this._videoContainer.style.width = width.toString() + 'px';
85
+ this._videoContainer.style.height = heightVideo.toString() + 'px';
86
+ this._videoContainer.style.zIndex = (this._zIndex + 2).toString();
87
+ this._container.appendChild(this._videoContainer);
88
+ /* Create Video Element */
89
+ const isCreated = await this.createVideoElement(width, heightVideo);
90
+ if (!isCreated) {
91
+ this._createEvent('Exit', this._playerId, 'Video Error: failed to create the Video Element');
92
+ }
93
+ }
94
+ else {
95
+ this._createEvent('Exit', this._playerId, 'Url Error: type not supported');
96
+ }
97
+ return;
98
+ }
99
+ async createVideoElement(width, height) {
100
+ this.videoEl = document.createElement('video');
101
+ this.videoEl.controls = true;
102
+ this.videoEl.style.zIndex = (this._zIndex + 3).toString();
103
+ this.videoEl.style.width = `${width.toString()}px`;
104
+ this.videoEl.style.height = `${height.toString()}px`;
105
+ this.videoEl.playbackRate = this._videoRate;
106
+ this._videoContainer.appendChild(this.videoEl);
107
+ // set the player
108
+ const isSet = await this._setPlayer();
109
+ if (isSet) {
110
+ this.videoEl.onended = async () => {
111
+ this._isEnded = true;
112
+ this.isPlaying = false;
113
+ if (this.videoEl) {
114
+ this.videoEl.currentTime = 0;
115
+ }
116
+ if (this._videoExitOnEnd) {
117
+ if (this._mode === 'fullscreen') {
118
+ this._closeFullscreen();
119
+ }
120
+ this._createEvent('Ended', this._playerId);
121
+ }
122
+ else {
123
+ if (this._videoLoopOnEnd && this.videoEl != null) {
124
+ await this.videoEl.play();
125
+ }
126
+ }
127
+ };
128
+ this.videoEl.oncanplay = async () => {
129
+ if (this._firstReadyToPlay) {
130
+ this._createEvent('Ready', this._playerId);
131
+ if (this.videoEl != null) {
132
+ this.videoEl.muted = false;
133
+ if (this._mode === 'fullscreen')
134
+ await this.videoEl.play();
135
+ this._firstReadyToPlay = false;
136
+ }
137
+ }
138
+ };
139
+ this.videoEl.onplay = () => {
140
+ this.isPlaying = true;
141
+ if (this._firstReadyToPlay)
142
+ this._firstReadyToPlay = false;
143
+ this._createEvent('Play', this._playerId);
144
+ };
145
+ this.videoEl.onplaying = () => {
146
+ this._createEvent('Playing', this._playerId);
147
+ };
148
+ this.videoEl.onpause = () => {
149
+ this.isPlaying = false;
150
+ this._createEvent('Pause', this._playerId);
151
+ };
152
+ if (this._mode === 'fullscreen') {
153
+ // create the video player exit button
154
+ const exitEl = document.createElement('button');
155
+ exitEl.textContent = 'X';
156
+ exitEl.style.position = 'absolute';
157
+ exitEl.style.left = '1%';
158
+ exitEl.style.top = '5%';
159
+ exitEl.style.width = '5vmin';
160
+ exitEl.style.padding = '0.5%';
161
+ exitEl.style.fontSize = '1.2rem';
162
+ exitEl.style.background = 'rgba(51,51,51,.4)';
163
+ exitEl.style.color = '#fff';
164
+ exitEl.style.visibility = 'hidden';
165
+ exitEl.style.zIndex = (this._zIndex + 4).toString();
166
+ exitEl.style.border = '1px solid rgba(51,51,51,.4)';
167
+ exitEl.style.borderRadius = '20px';
168
+ this._videoContainer.onclick = async () => {
169
+ this._initial = await this._doHide(exitEl, 3000);
170
+ };
171
+ this._videoContainer.ontouchstart = async () => {
172
+ this._initial = await this._doHide(exitEl, 3000);
173
+ };
174
+ this._videoContainer.onmousemove = async () => {
175
+ this._initial = await this._doHide(exitEl, 3000);
176
+ };
177
+ exitEl.onclick = () => {
178
+ this._createEvent('Exit', this._playerId);
179
+ };
180
+ exitEl.ontouchstart = () => {
181
+ this._createEvent('Exit', this._playerId);
182
+ };
183
+ this._videoContainer.appendChild(exitEl);
184
+ this._initial = await this._doHide(exitEl, 3000);
185
+ this._goFullscreen();
186
+ }
187
+ }
188
+ return isSet;
189
+ }
190
+ async _goFullscreen() {
191
+ if (this._container.mozRequestFullScreen) {
192
+ /* Firefox */
193
+ this._container.mozRequestFullScreen();
194
+ }
195
+ else if (this._container.webkitRequestFullscreen) {
196
+ /* Chrome, Safari & Opera */
197
+ this._container.webkitRequestFullscreen();
198
+ }
199
+ else if (this._container.msRequestFullscreen) {
200
+ /* IE/Edge */
201
+ this._container.msRequestFullscreen();
202
+ }
203
+ else if (this._container.requestFullscreen) {
204
+ this._container.requestFullscreen();
205
+ }
206
+ return;
207
+ }
208
+ async _setPlayer() {
209
+ return new Promise((resolve) => {
210
+ if (this.videoEl != null) {
211
+ if (Hls.isSupported() && this._videoType === 'application/x-mpegURL') {
212
+ const hls = new Hls();
213
+ hls.loadSource(this._url);
214
+ hls.attachMedia(this.videoEl);
215
+ hls.once(Hls.Events.FRAG_PARSED, () => {
216
+ if (this.videoEl != null) {
217
+ this.videoEl.muted = true;
218
+ this.videoEl.crossOrigin = 'anonymous';
219
+ resolve(true);
220
+ }
221
+ else {
222
+ resolve(false);
223
+ }
224
+ });
225
+ }
226
+ else if (this._videoType === 'video/mp4') {
227
+ // CMAF (fMP4) && MP4
228
+ this.videoEl.src = this._url;
229
+ if (this._url.substring(0, 5) != 'https' && this._url.substring(0, 4) === 'http')
230
+ this.videoEl.crossOrigin = 'anonymous';
231
+ if (this._url.substring(0, 5) === 'https' || this._url.substring(0, 4) === 'http')
232
+ this.videoEl.muted = true;
233
+ resolve(true);
234
+ }
235
+ else {
236
+ // Not Supported
237
+ resolve(false);
238
+ }
239
+ this.videoEl.addEventListener('enterpictureinpicture', (event) => {
240
+ this.pipWindow = event.pictureInPictureWindow;
241
+ this.pipMode = true;
242
+ this._closeFullscreen();
243
+ });
244
+ this.videoEl.addEventListener('leavepictureinpicture', () => {
245
+ this.pipMode = false;
246
+ if (!this._isEnded) {
247
+ this._goFullscreen();
248
+ if (this.videoEl != null)
249
+ this.videoEl.play();
250
+ }
251
+ });
252
+ }
253
+ else {
254
+ resolve(false);
255
+ }
256
+ });
257
+ }
258
+ _getVideoType() {
259
+ const sUrl = this._url ? this._url : '';
260
+ if (sUrl != null && sUrl.length > 0) {
261
+ Object.entries(videoTypes).forEach(([extension, mimeType]) => {
262
+ // we search for dot + extension (e.g. `.mp4`) for URLs that have the extension in the filename
263
+ // e.g. https://vimeo.com/?file=my-video.mp4
264
+ const hasDotExtension = sUrl.match(new RegExp(`.(${extension})`, 'i'));
265
+ if (hasDotExtension) {
266
+ return (this._videoType = mimeType);
267
+ }
268
+ // we search for the extension (e.g. `m3u8`) for URLs that might have the extension as a query parameter
269
+ // e.g. https://youtube.com/?v=7894289374&type=m3u8
270
+ const hasExtensionInUrl = sUrl.match(new RegExp(`(${extension})`, 'i'));
271
+ if (hasExtensionInUrl) {
272
+ return (this._videoType = mimeType);
273
+ }
274
+ });
275
+ // we check for not supported extensions for URLs that have the extension in the filename
276
+ // e.g. https://vimeo.com/?file=not-supported-extension-video.mkv
277
+ const hasNotSupportedDotExtension = sUrl.match(/\.(.*)/i);
278
+ if (hasNotSupportedDotExtension) {
279
+ return (this._videoType = null);
280
+ }
281
+ // we check for not supported extensions for URLs that might have the extension as a query parameter
282
+ // e.g. https://youtube.com/?v=3982748927&filetype=mkv
283
+ const hasNotSupportedExtensionInUrl = sUrl.match(new RegExp(`(${possibleQueryParameterExtensions.join('|')})=+(.*)&?(?=&|$))`, 'i'));
284
+ if (hasNotSupportedExtensionInUrl) {
285
+ return (this._videoType = null);
286
+ }
287
+ // No extension found, then we assume it's 'mp4' (Match case for '')
288
+ return 'video/mp4';
289
+ }
290
+ // URL was not defined, we return null
291
+ return null;
292
+ }
293
+ async _doHide(exitEl, duration) {
294
+ clearTimeout(this._initial);
295
+ exitEl.style.visibility = 'visible';
296
+ const initial = setTimeout(() => {
297
+ exitEl.style.visibility = 'hidden';
298
+ }, duration);
299
+ return initial;
300
+ }
301
+ _createEvent(ev, playerId, msg) {
302
+ const message = msg ? msg : null;
303
+ let event;
304
+ if (message != null) {
305
+ event = new CustomEvent(`videoPlayer${ev}`, {
306
+ detail: { fromPlayerId: playerId, message: message },
307
+ });
308
+ }
309
+ else {
310
+ const currentTime = this.videoEl ? this.videoEl.currentTime : 0;
311
+ event = new CustomEvent(`videoPlayer${ev}`, {
312
+ detail: { fromPlayerId: playerId, currentTime: currentTime },
313
+ });
314
+ }
315
+ document.dispatchEvent(event);
316
+ }
317
+ _closeFullscreen() {
318
+ const mydoc = document;
319
+ const isInFullScreen = (mydoc.fullscreenElement && mydoc.fullscreenElement !== null) ||
320
+ (mydoc.webkitFullscreenElement && mydoc.webkitFullscreenElement !== null) ||
321
+ (mydoc.mozFullScreenElement && mydoc.mozFullScreenElement !== null) ||
322
+ (mydoc.msFullscreenElement && mydoc.msFullscreenElement !== null);
323
+ if (isInFullScreen) {
324
+ if (mydoc.mozCancelFullScreen) {
325
+ mydoc.mozCancelFullScreen();
326
+ }
327
+ else if (mydoc.webkitExitFullscreen) {
328
+ mydoc.webkitExitFullscreen();
329
+ }
330
+ else if (mydoc.msExitFullscreen) {
331
+ mydoc.msExitFullscreen();
332
+ }
333
+ else if (mydoc.exitFullscreen) {
334
+ mydoc.exitFullscreen();
335
+ }
336
+ }
337
+ }
338
+ }
339
+
340
+ class VideoPlayerWeb extends core.WebPlugin {
341
+ constructor() {
342
+ super();
343
+ this._players = [];
344
+ this.addListeners();
345
+ }
346
+ async echo(options) {
347
+ return Promise.resolve({ result: true, method: 'echo', value: options });
348
+ }
349
+ /**
350
+ * Player initialization
351
+ *
352
+ * @param options
353
+ */
354
+ async initPlayer(options) {
355
+ if (options == null) {
356
+ return Promise.resolve({
357
+ result: false,
358
+ method: 'initPlayer',
359
+ message: 'Must provide a capVideoPlayerOptions object',
360
+ });
361
+ }
362
+ this.mode = options.mode ? options.mode : '';
363
+ if (this.mode == null || this.mode.length === 0) {
364
+ return Promise.resolve({
365
+ result: false,
366
+ method: 'initPlayer',
367
+ message: 'Must provide a Mode (fullscreen/embedded)',
368
+ });
369
+ }
370
+ if (this.mode === 'fullscreen' || this.mode === 'embedded') {
371
+ const url = options.url ? options.url : '';
372
+ if (url == null || url.length === 0) {
373
+ return Promise.resolve({
374
+ result: false,
375
+ method: 'initPlayer',
376
+ message: 'Must provide a Video Url',
377
+ });
378
+ }
379
+ if (url == 'internal') {
380
+ return Promise.resolve({
381
+ result: false,
382
+ method: 'initPlayer',
383
+ message: 'Internal Videos not supported on Web Platform',
384
+ });
385
+ }
386
+ const playerId = options.playerId ? options.playerId : '';
387
+ if (playerId == null || playerId.length === 0) {
388
+ return Promise.resolve({
389
+ result: false,
390
+ method: 'initPlayer',
391
+ message: 'Must provide a Player Id',
392
+ });
393
+ }
394
+ const rate = options.rate ? options.rate : 1.0;
395
+ let exitOnEnd = true;
396
+ if (Object.keys(options).includes('exitOnEnd')) {
397
+ const exitRet = options.exitOnEnd;
398
+ exitOnEnd = exitRet != null ? exitRet : true;
399
+ }
400
+ let loopOnEnd = false;
401
+ if (Object.keys(options).includes('loopOnEnd') && !exitOnEnd) {
402
+ const loopRet = options.loopOnEnd;
403
+ loopOnEnd = loopRet != null ? loopRet : false;
404
+ }
405
+ const componentTag = options.componentTag ? options.componentTag : '';
406
+ if (componentTag == null || componentTag.length === 0) {
407
+ return Promise.resolve({
408
+ result: false,
409
+ method: 'initPlayer',
410
+ message: 'Must provide a Component Tag',
411
+ });
412
+ }
413
+ let playerSize = null;
414
+ if (this.mode === 'embedded') {
415
+ playerSize = this.checkSize(options);
416
+ }
417
+ const result = await this._initializeVideoPlayer(url, playerId, this.mode, rate, exitOnEnd, loopOnEnd, componentTag, playerSize);
418
+ return Promise.resolve({ result: result });
419
+ }
420
+ else {
421
+ return Promise.resolve({
422
+ result: false,
423
+ method: 'initPlayer',
424
+ message: 'Must provide a Mode either fullscreen or embedded)',
425
+ });
426
+ }
427
+ }
428
+ /**
429
+ * Return if a given playerId is playing
430
+ *
431
+ * @param options
432
+ */
433
+ async isPlaying(options) {
434
+ if (options == null) {
435
+ return Promise.resolve({
436
+ result: false,
437
+ method: 'isPlaying',
438
+ message: 'Must provide a capVideoPlayerIdOptions object',
439
+ });
440
+ }
441
+ let playerId = options.playerId ? options.playerId : '';
442
+ if (playerId == null || playerId.length === 0) {
443
+ playerId = 'fullscreen';
444
+ }
445
+ if (this._players[playerId]) {
446
+ const playing = this._players[playerId].isPlaying;
447
+ return Promise.resolve({
448
+ method: 'isPlaying',
449
+ result: true,
450
+ value: playing,
451
+ });
452
+ }
453
+ else {
454
+ return Promise.resolve({
455
+ method: 'isPlaying',
456
+ result: false,
457
+ message: 'Given PlayerId does not exist)',
458
+ });
459
+ }
460
+ }
461
+ /**
462
+ * Play the current video from a given playerId
463
+ *
464
+ * @param options
465
+ */
466
+ async play(options) {
467
+ if (options == null) {
468
+ return Promise.resolve({
469
+ result: false,
470
+ method: 'play',
471
+ message: 'Must provide a capVideoPlayerIdOptions object',
472
+ });
473
+ }
474
+ let playerId = options.playerId ? options.playerId : '';
475
+ if (playerId == null || playerId.length === 0) {
476
+ playerId = 'fullscreen';
477
+ }
478
+ if (this._players[playerId]) {
479
+ await this._players[playerId].videoEl.play();
480
+ return Promise.resolve({ method: 'play', result: true, value: true });
481
+ }
482
+ else {
483
+ return Promise.resolve({
484
+ method: 'play',
485
+ result: false,
486
+ message: 'Given PlayerId does not exist)',
487
+ });
488
+ }
489
+ }
490
+ /**
491
+ * Pause the current video from a given playerId
492
+ *
493
+ * @param options
494
+ */
495
+ async pause(options) {
496
+ if (options == null) {
497
+ return Promise.resolve({
498
+ result: false,
499
+ method: 'pause',
500
+ message: 'Must provide a capVideoPlayerIdOptions object',
501
+ });
502
+ }
503
+ let playerId = options.playerId ? options.playerId : '';
504
+ if (playerId == null || playerId.length === 0) {
505
+ playerId = 'fullscreen';
506
+ }
507
+ if (this._players[playerId]) {
508
+ if (this._players[playerId].isPlaying)
509
+ await this._players[playerId].videoEl.pause();
510
+ return Promise.resolve({ method: 'pause', result: true, value: true });
511
+ }
512
+ else {
513
+ return Promise.resolve({
514
+ method: 'pause',
515
+ result: false,
516
+ message: 'Given PlayerId does not exist)',
517
+ });
518
+ }
519
+ }
520
+ /**
521
+ * Get the duration of the current video from a given playerId
522
+ *
523
+ * @param options
524
+ */
525
+ async getDuration(options) {
526
+ if (options == null) {
527
+ return Promise.resolve({
528
+ result: false,
529
+ method: 'getDuration',
530
+ message: 'Must provide a capVideoPlayerIdOptions object',
531
+ });
532
+ }
533
+ let playerId = options.playerId ? options.playerId : '';
534
+ if (playerId == null || playerId.length === 0) {
535
+ playerId = 'fullscreen';
536
+ }
537
+ if (this._players[playerId]) {
538
+ const duration = this._players[playerId].videoEl.duration;
539
+ return Promise.resolve({
540
+ method: 'getDuration',
541
+ result: true,
542
+ value: duration,
543
+ });
544
+ }
545
+ else {
546
+ return Promise.resolve({
547
+ method: 'getDuration',
548
+ result: false,
549
+ message: 'Given PlayerId does not exist)',
550
+ });
551
+ }
552
+ }
553
+ /**
554
+ * Set the rate of the current video from a given playerId
555
+ *
556
+ * @param options
557
+ */
558
+ async setRate(options) {
559
+ if (options == null) {
560
+ return Promise.resolve({
561
+ result: false,
562
+ method: 'setRate',
563
+ message: 'Must provide a capVideoRateOptions object',
564
+ });
565
+ }
566
+ let playerId = options.playerId ? options.playerId : '';
567
+ if (playerId == null || playerId.length === 0) {
568
+ playerId = 'fullscreen';
569
+ }
570
+ const rateList = [0.25, 0.5, 0.75, 1.0, 2.0, 4.0];
571
+ const rate = options.rate && rateList.includes(options.rate) ? options.rate : 1.0;
572
+ if (this._players[playerId]) {
573
+ this._players[playerId].videoEl.playbackRate = rate;
574
+ return Promise.resolve({
575
+ method: 'setRate',
576
+ result: true,
577
+ value: rate,
578
+ });
579
+ }
580
+ else {
581
+ return Promise.resolve({
582
+ method: 'setRate',
583
+ result: false,
584
+ message: 'Given PlayerId does not exist)',
585
+ });
586
+ }
587
+ }
588
+ /**
589
+ * Get the volume of the current video from a given playerId
590
+ *
591
+ * @param options
592
+ */
593
+ async getRate(options) {
594
+ if (options == null) {
595
+ return Promise.resolve({
596
+ result: false,
597
+ method: 'getRate',
598
+ message: 'Must provide a capVideoPlayerIdOptions object',
599
+ });
600
+ }
601
+ let playerId = options.playerId ? options.playerId : '';
602
+ if (playerId == null || playerId.length === 0) {
603
+ playerId = 'fullscreen';
604
+ }
605
+ if (this._players[playerId]) {
606
+ const rate = this._players[playerId].videoEl.playbackRate;
607
+ return Promise.resolve({
608
+ method: 'getRate',
609
+ result: true,
610
+ value: rate,
611
+ });
612
+ }
613
+ else {
614
+ return Promise.resolve({
615
+ method: 'getRate',
616
+ result: false,
617
+ message: 'Given PlayerId does not exist)',
618
+ });
619
+ }
620
+ }
621
+ /**
622
+ * Set the volume of the current video from a given playerId
623
+ *
624
+ * @param options
625
+ */
626
+ async setVolume(options) {
627
+ if (options == null) {
628
+ return Promise.resolve({
629
+ result: false,
630
+ method: 'setVolume',
631
+ message: 'Must provide a capVideoVolumeOptions object',
632
+ });
633
+ }
634
+ let playerId = options.playerId ? options.playerId : '';
635
+ if (playerId == null || playerId.length === 0) {
636
+ playerId = 'fullscreen';
637
+ }
638
+ const volume = options.volume ? options.volume : 0.5;
639
+ if (this._players[playerId]) {
640
+ this._players[playerId].videoEl.volume = volume;
641
+ return Promise.resolve({
642
+ method: 'setVolume',
643
+ result: true,
644
+ value: volume,
645
+ });
646
+ }
647
+ else {
648
+ return Promise.resolve({
649
+ method: 'setVolume',
650
+ result: false,
651
+ message: 'Given PlayerId does not exist)',
652
+ });
653
+ }
654
+ }
655
+ /**
656
+ * Get the volume of the current video from a given playerId
657
+ *
658
+ * @param options
659
+ */
660
+ async getVolume(options) {
661
+ if (options == null) {
662
+ return Promise.resolve({
663
+ result: false,
664
+ method: 'getVolume',
665
+ message: 'Must provide a capVideoPlayerIdOptions object',
666
+ });
667
+ }
668
+ let playerId = options.playerId ? options.playerId : '';
669
+ if (playerId == null || playerId.length === 0) {
670
+ playerId = 'fullscreen';
671
+ }
672
+ if (this._players[playerId]) {
673
+ const volume = this._players[playerId].videoEl.volume;
674
+ return Promise.resolve({
675
+ method: 'getVolume',
676
+ result: true,
677
+ value: volume,
678
+ });
679
+ }
680
+ else {
681
+ return Promise.resolve({
682
+ method: 'getVolume',
683
+ result: false,
684
+ message: 'Given PlayerId does not exist)',
685
+ });
686
+ }
687
+ }
688
+ /**
689
+ * Set the muted property of the current video from a given playerId
690
+ *
691
+ * @param options
692
+ */
693
+ async setMuted(options) {
694
+ if (options == null) {
695
+ return Promise.resolve({
696
+ result: false,
697
+ method: 'setMuted',
698
+ message: 'Must provide a capVideoMutedOptions object',
699
+ });
700
+ }
701
+ let playerId = options.playerId ? options.playerId : '';
702
+ if (playerId == null || playerId.length === 0) {
703
+ playerId = 'fullscreen';
704
+ }
705
+ const muted = options.muted ? options.muted : false;
706
+ if (this._players[playerId]) {
707
+ this._players[playerId].videoEl.muted = muted;
708
+ return Promise.resolve({
709
+ method: 'setMuted',
710
+ result: true,
711
+ value: muted,
712
+ });
713
+ }
714
+ else {
715
+ return Promise.resolve({
716
+ method: 'setMuted',
717
+ result: false,
718
+ message: 'Given PlayerId does not exist)',
719
+ });
720
+ }
721
+ }
722
+ /**
723
+ * Get the muted property of the current video from a given playerId
724
+ *
725
+ * @param options
726
+ */
727
+ async getMuted(options) {
728
+ if (options == null) {
729
+ return Promise.resolve({
730
+ result: false,
731
+ method: 'getMuted',
732
+ message: 'Must provide a capVideoPlayerIdOptions object',
733
+ });
734
+ }
735
+ let playerId = options.playerId ? options.playerId : '';
736
+ if (playerId == null || playerId.length === 0) {
737
+ playerId = 'fullscreen';
738
+ }
739
+ if (this._players[playerId]) {
740
+ const muted = this._players[playerId].videoEl.muted;
741
+ return Promise.resolve({
742
+ method: 'getMuted',
743
+ result: true,
744
+ value: muted,
745
+ });
746
+ }
747
+ else {
748
+ return Promise.resolve({
749
+ method: 'getMuted',
750
+ result: false,
751
+ message: 'Given PlayerId does not exist)',
752
+ });
753
+ }
754
+ }
755
+ /**
756
+ * Set the current time of the current video from a given playerId
757
+ *
758
+ * @param options
759
+ */
760
+ async setCurrentTime(options) {
761
+ if (options == null) {
762
+ return Promise.resolve({
763
+ result: false,
764
+ method: 'setCurrentTime',
765
+ message: 'Must provide a capVideoTimeOptions object',
766
+ });
767
+ }
768
+ let playerId = options.playerId ? options.playerId : '';
769
+ if (playerId == null || playerId.length === 0) {
770
+ playerId = 'fullscreen';
771
+ }
772
+ let seekTime = options.seektime ? options.seektime : 0;
773
+ if (this._players[playerId]) {
774
+ const duration = this._players[playerId].videoEl.duration;
775
+ seekTime = seekTime <= duration && seekTime >= 0 ? seekTime : duration / 2;
776
+ this._players[playerId].videoEl.currentTime = seekTime;
777
+ return Promise.resolve({
778
+ method: 'setCurrentTime',
779
+ result: true,
780
+ value: seekTime,
781
+ });
782
+ }
783
+ else {
784
+ return Promise.resolve({
785
+ method: 'setCurrentTime',
786
+ result: false,
787
+ message: 'Given PlayerId does not exist)',
788
+ });
789
+ }
790
+ }
791
+ /**
792
+ * Get the current time of the current video from a given playerId
793
+ *
794
+ * @param options
795
+ */
796
+ async getCurrentTime(options) {
797
+ if (options == null) {
798
+ return Promise.resolve({
799
+ result: false,
800
+ method: 'getCurrentTime',
801
+ message: 'Must provide a capVideoPlayerIdOptions object',
802
+ });
803
+ }
804
+ let playerId = options.playerId ? options.playerId : '';
805
+ if (playerId == null || playerId.length === 0) {
806
+ playerId = 'fullscreen';
807
+ }
808
+ if (this._players[playerId]) {
809
+ const seekTime = this._players[playerId].videoEl.currentTime;
810
+ return Promise.resolve({
811
+ method: 'getCurrentTime',
812
+ result: true,
813
+ value: seekTime,
814
+ });
815
+ }
816
+ else {
817
+ return Promise.resolve({
818
+ method: 'getCurrentTime',
819
+ result: false,
820
+ message: 'Given PlayerId does not exist)',
821
+ });
822
+ }
823
+ }
824
+ /**
825
+ * Get the current time of the current video from a given playerId
826
+ *
827
+ */
828
+ async stopAllPlayers() {
829
+ for (const i in this._players) {
830
+ if (this._players[i].pipMode) {
831
+ const doc = document;
832
+ if (doc.pictureInPictureElement) {
833
+ await doc.exitPictureInPicture();
834
+ }
835
+ }
836
+ if (!this._players[i].videoEl.paused)
837
+ this._players[i].videoEl.pause();
838
+ }
839
+ return Promise.resolve({
840
+ method: 'stopAllPlayers',
841
+ result: true,
842
+ value: true,
843
+ });
844
+ }
845
+ /**
846
+ * Show controller
847
+ *
848
+ */
849
+ async showController() {
850
+ return Promise.resolve({
851
+ method: 'showController',
852
+ result: true,
853
+ value: true,
854
+ });
855
+ }
856
+ /**
857
+ * isControllerIsFullyVisible
858
+ *
859
+ */
860
+ async isControllerIsFullyVisible() {
861
+ return Promise.resolve({
862
+ method: 'isControllerIsFullyVisible',
863
+ result: true,
864
+ value: true,
865
+ });
866
+ }
867
+ /**
868
+ * Exit the current player
869
+ *
870
+ */
871
+ async exitPlayer() {
872
+ return Promise.resolve({
873
+ method: 'exitPlayer',
874
+ result: true,
875
+ value: true,
876
+ });
877
+ }
878
+ checkSize(options) {
879
+ const playerSize = {
880
+ width: options.width ? options.width : 320,
881
+ height: options.height ? options.height : 180,
882
+ };
883
+ const ratio = playerSize.height / playerSize.width;
884
+ if (playerSize.width > window.innerWidth) {
885
+ playerSize.width = window.innerWidth;
886
+ playerSize.height = Math.floor(playerSize.width * ratio);
887
+ }
888
+ if (playerSize.height > window.innerHeight) {
889
+ playerSize.height = window.innerHeight;
890
+ playerSize.width = Math.floor(playerSize.height / ratio);
891
+ }
892
+ return playerSize;
893
+ }
894
+ async _initializeVideoPlayer(url, playerId, mode, rate, exitOnEnd, loopOnEnd, componentTag, playerSize) {
895
+ const videoURL = url ? (url.indexOf('%2F') == -1 ? encodeURI(url) : url) : null;
896
+ if (videoURL === null)
897
+ return Promise.resolve(false);
898
+ this.videoContainer = await this._getContainerElement(playerId, componentTag);
899
+ if (this.videoContainer === null)
900
+ return Promise.resolve({
901
+ method: 'initPlayer',
902
+ result: false,
903
+ message: 'componentTag or divContainerElement must be provided',
904
+ });
905
+ if (mode === 'embedded' && playerSize == null)
906
+ return Promise.resolve({
907
+ method: 'initPlayer',
908
+ result: false,
909
+ message: 'playerSize must be defined in embedded mode',
910
+ });
911
+ if (mode === 'embedded') {
912
+ this._players[playerId] = new VideoPlayer('embedded', videoURL, playerId, rate, exitOnEnd, loopOnEnd, this.videoContainer, 2, playerSize.width, playerSize.height);
913
+ await this._players[playerId].initialize();
914
+ }
915
+ else if (mode === 'fullscreen') {
916
+ this._players['fullscreen'] = new VideoPlayer('fullscreen', videoURL, 'fullscreen', rate, exitOnEnd, loopOnEnd, this.videoContainer, 99995);
917
+ await this._players['fullscreen'].initialize();
918
+ }
919
+ else {
920
+ return Promise.resolve({
921
+ method: 'initPlayer',
922
+ result: false,
923
+ message: 'mode not supported',
924
+ });
925
+ }
926
+ return Promise.resolve({ method: 'initPlayer', result: true, value: true });
927
+ }
928
+ async _getContainerElement(playerId, componentTag) {
929
+ const videoContainer = document.createElement('div');
930
+ videoContainer.id = `vc_${playerId}`;
931
+ if (componentTag != null && componentTag.length > 0) {
932
+ const cmpTagEl = document.querySelector(`${componentTag}`);
933
+ if (cmpTagEl === null)
934
+ return Promise.resolve(null);
935
+ let container = null;
936
+ const shadowRoot = cmpTagEl.shadowRoot ? cmpTagEl.shadowRoot : null;
937
+ if (shadowRoot != null) {
938
+ container = shadowRoot.querySelector(`[id='${playerId}']`);
939
+ }
940
+ else {
941
+ container = cmpTagEl.querySelector(`[id='${playerId}']`);
942
+ }
943
+ if (container != null)
944
+ container.appendChild(videoContainer);
945
+ return Promise.resolve(videoContainer);
946
+ }
947
+ else {
948
+ return Promise.resolve(null);
949
+ }
950
+ }
951
+ handlePlayerPlay(data) {
952
+ this.notifyListeners('jeepCapVideoPlayerPlay', data);
953
+ }
954
+ handlePlayerPause(data) {
955
+ this.notifyListeners('jeepCapVideoPlayerPause', data);
956
+ }
957
+ handlePlayerEnded(data) {
958
+ var _a;
959
+ if (this.mode === 'fullscreen') {
960
+ (_a = this.videoContainer) === null || _a === void 0 ? void 0 : _a.remove();
961
+ }
962
+ this.removeListeners();
963
+ this.notifyListeners('jeepCapVideoPlayerEnded', data);
964
+ }
965
+ handlePlayerExit() {
966
+ var _a;
967
+ if (this.mode === 'fullscreen') {
968
+ (_a = this.videoContainer) === null || _a === void 0 ? void 0 : _a.remove();
969
+ }
970
+ const retData = { dismiss: true };
971
+ this.removeListeners();
972
+ this.notifyListeners('jeepCapVideoPlayerExit', retData);
973
+ }
974
+ handlePlayerReady(data) {
975
+ this.notifyListeners('jeepCapVideoPlayerReady', data);
976
+ }
977
+ addListeners() {
978
+ document.addEventListener('videoPlayerPlay', (ev) => {
979
+ this.handlePlayerPlay(ev.detail);
980
+ }, false);
981
+ document.addEventListener('videoPlayerPause', (ev) => {
982
+ this.handlePlayerPause(ev.detail);
983
+ }, false);
984
+ document.addEventListener('videoPlayerEnded', (ev) => {
985
+ this.handlePlayerEnded(ev.detail);
986
+ }, false);
987
+ document.addEventListener('videoPlayerReady', (ev) => {
988
+ this.handlePlayerReady(ev.detail);
989
+ }, false);
990
+ document.addEventListener('videoPlayerExit', () => {
991
+ this.handlePlayerExit();
992
+ }, false);
993
+ }
994
+ removeListeners() {
995
+ document.removeEventListener('videoPlayerPlay', (ev) => {
996
+ this.handlePlayerPlay(ev.detail);
997
+ }, false);
998
+ document.removeEventListener('videoPlayerPause', (ev) => {
999
+ this.handlePlayerPause(ev.detail);
1000
+ }, false);
1001
+ document.removeEventListener('videoPlayerEnded', (ev) => {
1002
+ this.handlePlayerEnded(ev.detail);
1003
+ }, false);
1004
+ document.removeEventListener('videoPlayerReady', (ev) => {
1005
+ this.handlePlayerReady(ev.detail);
1006
+ }, false);
1007
+ document.removeEventListener('videoPlayerExit', () => {
1008
+ this.handlePlayerExit();
1009
+ }, false);
1010
+ }
1011
+ }
1012
+
1013
+ var web = /*#__PURE__*/Object.freeze({
1014
+ __proto__: null,
1015
+ VideoPlayerWeb: VideoPlayerWeb
1016
+ });
1017
+
1018
+ exports.VideoPlayer = VideoPlayer$1;
1019
+ //# sourceMappingURL=plugin.cjs.js.map