@picsa/capacitor-video-player 7.1.0

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