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