@v360-tech/v360-player 1.4.1 → 1.4.2

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.
@@ -1,12 +1,12 @@
1
1
  import l from "hls.js";
2
- import a from "jquery";
3
- const e = {
2
+ import r from "jquery";
3
+ const t = {
4
4
  None: "none",
5
5
  DualLayer: "dual-layer",
6
6
  Segments: "segments",
7
7
  MinimalWave: "minimal-wave"
8
8
  }, v = {
9
- [e.None]: `
9
+ [t.None]: `
10
10
  .progress-bar {
11
11
  flex: 1;
12
12
  height: 4px;
@@ -24,7 +24,7 @@ const e = {
24
24
  border-radius: 2px;
25
25
  }
26
26
  `,
27
- [e.DualLayer]: `
27
+ [t.DualLayer]: `
28
28
  .progress-bar {
29
29
  flex: 1;
30
30
  height: 8px;
@@ -67,7 +67,7 @@ const e = {
67
67
  transform: translateY(-50%) scale(1.2);
68
68
  }
69
69
  `,
70
- [e.Segments]: `
70
+ [t.Segments]: `
71
71
  .progress-bar {
72
72
  flex: 1;
73
73
  height: 4px;
@@ -105,7 +105,7 @@ const e = {
105
105
  background: #40A2FF;
106
106
  }
107
107
  `,
108
- [e.MinimalWave]: `
108
+ [t.MinimalWave]: `
109
109
  .progress-bar {
110
110
  flex: 1;
111
111
  height: 2px;
@@ -165,17 +165,20 @@ const e = {
165
165
  "speed-2.00": `<img src="${N}" width="24" height="24" alt="2x speed">`
166
166
  }, j = "X-Jewel-Store", D = "69d2c1660df6540944e25eb708fb252724ab27fb";
167
167
  class z extends HTMLElement {
168
- progressBarStyle = e.None;
168
+ progressBarStyle = t.None;
169
169
  _hls;
170
170
  _videoPlayer;
171
171
  background = "dark";
172
172
  aspectRatio = "16:9";
173
+ _autoPlay = !1;
174
+ _streamLoaded = !1;
175
+ _startLevel = -1;
173
176
  calculateAspectRatioPadding() {
174
177
  const [A, g] = this.aspectRatio.split(":").map(Number);
175
178
  return g / A * 100;
176
179
  }
177
180
  isValidProgressBarStyle(A) {
178
- return Object.values(e).includes(A);
181
+ return Object.values(t).includes(A);
179
182
  }
180
183
  // Import icons from dedicated file
181
184
  svgIcons = W;
@@ -200,7 +203,7 @@ class z extends HTMLElement {
200
203
  }
201
204
  attributeChangedCallback(A, g, I) {
202
205
  if (A === "progress-bar-style")
203
- this.progressBarStyle = this.isValidProgressBarStyle(I) ? I : e.None, this.render();
206
+ this.progressBarStyle = this.isValidProgressBarStyle(I) ? I : t.None, this.render();
204
207
  else if (A === "background")
205
208
  this.background = I === "light" ? "light" : "dark", this.updateControlsColor();
206
209
  else if (A === "aspect-ratio") {
@@ -211,7 +214,7 @@ class z extends HTMLElement {
211
214
  async connectedCallback() {
212
215
  this.background = this.getAttribute("background") === "light" ? "light" : "dark";
213
216
  const A = this.getAttribute("aspect-ratio");
214
- A && /^\d+:\d+$/.test(A) && (this.aspectRatio = A), await this.render(), await this.initializePlayer(), this.setupProgressBarInteractions(), this.updateControlsColor();
217
+ A && /^\d+:\d+$/.test(A) && (this.aspectRatio = A), this._autoPlay = this.hasAttribute("auto-play"), this._streamLoaded = this._autoPlay, this._startLevel = parseInt(this.getAttribute("default-quality") || "-1"), await this.render(), await this.initializePlayer(), this.setupProgressBarInteractions(), this.updateControlsColor();
215
218
  }
216
219
  setupProgressBarInteractions() {
217
220
  if (!this.shadowRoot || !this._videoPlayer) return;
@@ -219,26 +222,26 @@ class z extends HTMLElement {
219
222
  if (!A || !g) return;
220
223
  const I = () => {
221
224
  if (!this._videoPlayer) return;
222
- const t = this._videoPlayer.currentTime / this._videoPlayer.duration * 100;
223
- if (g.style.width = `${t}%`, this.progressBarStyle === e.Segments) {
224
- const o = this.shadowRoot?.querySelectorAll(".progress-segment");
225
- o && o.forEach((i, C) => {
226
- const c = (C + 1) * (100 / o.length);
227
- t >= c ? i.classList.add("filled") : i.classList.remove("filled");
225
+ const i = this._videoPlayer.currentTime / this._videoPlayer.duration * 100;
226
+ if (g.style.width = `${i}%`, this.progressBarStyle === t.Segments) {
227
+ const e = this.shadowRoot?.querySelectorAll(".progress-segment");
228
+ e && e.forEach((C, o) => {
229
+ const n = (o + 1) * (100 / e.length);
230
+ i >= n ? C.classList.add("filled") : C.classList.remove("filled");
228
231
  });
229
232
  }
230
233
  };
231
234
  this._videoPlayer.addEventListener("timeupdate", I);
232
- const s = (t) => {
233
- if (!this._videoPlayer || !(t instanceof MouseEvent)) return;
234
- const o = A.getBoundingClientRect(), i = Math.max(0, Math.min(1, (t.clientX - o.left) / o.width));
235
- this._videoPlayer.currentTime = i * this._videoPlayer.duration;
235
+ const s = (i) => {
236
+ if (!this._videoPlayer || !(i instanceof MouseEvent)) return;
237
+ const e = A.getBoundingClientRect(), C = Math.max(0, Math.min(1, (i.clientX - e.left) / e.width));
238
+ this._videoPlayer.currentTime = C * this._videoPlayer.duration;
236
239
  };
237
240
  A.addEventListener("click", s);
238
241
  }
239
242
  renderProgressBar() {
240
243
  switch (this.progressBarStyle) {
241
- case e.DualLayer:
244
+ case t.DualLayer:
242
245
  return `
243
246
  <div class="progress-bar">
244
247
  <div class="progress-bar-buffer"></div>
@@ -246,7 +249,7 @@ class z extends HTMLElement {
246
249
  <div class="progress-handle"></div>
247
250
  </div>
248
251
  `;
249
- case e.Segments:
252
+ case t.Segments:
250
253
  return `
251
254
  <div class="progress-bar">
252
255
  ${Array.from({ length: 20 }, (A, g) => `
@@ -254,14 +257,14 @@ class z extends HTMLElement {
254
257
  `).join("")}
255
258
  </div>
256
259
  `;
257
- case e.MinimalWave:
260
+ case t.MinimalWave:
258
261
  return `
259
262
  <div class="progress-bar">
260
263
  <div class="progress-bar-fill" style="width: 0%"></div>
261
264
  <div class="progress-wave"></div>
262
265
  </div>
263
266
  `;
264
- case e.None:
267
+ case t.None:
265
268
  default:
266
269
  return "";
267
270
  }
@@ -440,7 +443,7 @@ class z extends HTMLElement {
440
443
  console.error("Shadow root not found");
441
444
  return;
442
445
  }
443
- console.log("Initialize player called");
446
+ console.debug("Initialize player called");
444
447
  const A = this.shadowRoot.querySelector("video");
445
448
  if (!A) {
446
449
  console.error("Video element not found");
@@ -457,9 +460,9 @@ class z extends HTMLElement {
457
460
  });
458
461
  try {
459
462
  if (l.isSupported())
460
- console.log("HLS.js is supported, initializing..."), await this.initializeHls(A, g);
463
+ console.debug("HLS.js is supported, initializing..."), await this.initializeHls(A, g);
461
464
  else if (A.canPlayType("application/vnd.apple.mpegurl"))
462
- console.log("Using native HLS support"), A.src = g, this.startListeners();
465
+ console.debug("Using native HLS support"), A.src = g, this.startListeners();
463
466
  else
464
467
  throw new Error("Neither HLS.js nor native HLS is supported");
465
468
  } catch (I) {
@@ -469,13 +472,13 @@ class z extends HTMLElement {
469
472
  async initializeHls(A, g) {
470
473
  return new Promise((I, s) => {
471
474
  try {
472
- const o = {
475
+ const i = {
473
476
  // debug: true,
474
477
  enableWorker: !0,
475
478
  lowLatencyMode: !0,
476
479
  backBufferLength: 90,
477
- startLevel: parseInt(this.getAttribute("default-quality") || "-1"),
478
- autoStartLoad: this.hasAttribute("auto-play"),
480
+ startLevel: this._startLevel,
481
+ autoStartLoad: this._autoPlay,
479
482
  manifestLoadingTimeOut: 2e4,
480
483
  manifestLoadingMaxRetry: 3,
481
484
  manifestLoadingRetryDelay: 500,
@@ -485,81 +488,81 @@ class z extends HTMLElement {
485
488
  fragLoadingTimeOut: 2e4,
486
489
  fragLoadingMaxRetry: 3,
487
490
  fragLoadingRetryDelay: 500,
488
- xhrSetup: (i) => {
489
- i.withCredentials = !1, i.setRequestHeader(j, D);
491
+ xhrSetup: (e) => {
492
+ e.withCredentials = !1, e.setRequestHeader(j, D);
490
493
  }
491
494
  };
492
- this._hls = new l(o), this._hls.on(l.Events.ERROR, (i, C) => {
495
+ this._hls = new l(i), this._hls.on(l.Events.ERROR, (e, C) => {
493
496
  if (console.error("HLS Error:", C), C.fatal)
494
497
  switch (C.type) {
495
498
  case l.ErrorTypes.NETWORK_ERROR:
496
- console.log("Fatal network error encountered, trying to recover..."), this._hls?.startLoad();
499
+ console.debug("Fatal network error encountered, trying to recover..."), this._hls?.startLoad();
497
500
  break;
498
501
  case l.ErrorTypes.MEDIA_ERROR:
499
- console.log("Fatal media error encountered, trying to recover..."), this._hls?.recoverMediaError();
502
+ console.debug("Fatal media error encountered, trying to recover..."), this._hls?.recoverMediaError();
500
503
  break;
501
504
  default:
502
505
  console.error("Fatal error, cannot recover:", C.details), this._hls?.destroy(), s(new Error(`Fatal HLS error: ${C.details}`));
503
506
  break;
504
507
  }
505
508
  }), this._hls.on(l.Events.MEDIA_ATTACHED, () => {
506
- console.log("Media attached, loading source:", g), this._hls?.loadSource(g);
507
- }), this._hls.on(l.Events.MANIFEST_PARSED, (i, C) => {
508
- console.log("Manifest parsed, levels:", C.levels), this.startListeners(), I(), this.hasAttribute("auto-play") && (console.log("Attempting autoplay..."), A.play().then(() => console.log("Playback started successfully")).catch(async (c) => {
509
- console.error("Autoplay failed:", c), A.muted = !0;
509
+ console.debug("Media attached, loading source:", g), this._hls?.loadSource(g);
510
+ }), this._hls.on(l.Events.MANIFEST_PARSED, (e, C) => {
511
+ console.debug("Manifest parsed, levels:", C.levels), this.startListeners(), I(), this._autoPlay && (console.debug("Attempting autoplay..."), A.play().then(() => console.debug("Playback started successfully")).catch(async (o) => {
512
+ console.error("Autoplay failed:", o), A.muted = !0;
510
513
  try {
511
- await A.play(), console.log("Muted autoplay successful");
512
- } catch (d) {
513
- console.error("Muted autoplay also failed:", d);
514
+ await A.play(), console.debug("Muted autoplay successful");
515
+ } catch (n) {
516
+ console.error("Muted autoplay also failed:", n);
514
517
  }
515
518
  }));
516
- }), console.log("Attaching media element..."), this._hls.attachMedia(A);
517
- } catch (t) {
518
- console.error("Error in HLS initialization:", t), s(t);
519
+ }), console.debug("Attaching media element..."), this._hls.attachMedia(A);
520
+ } catch (i) {
521
+ console.error("Error in HLS initialization:", i), s(i);
519
522
  }
520
523
  });
521
524
  }
522
525
  startListeners() {
523
526
  if (!this.shadowRoot) return;
524
- const A = a(this.shadowRoot).find(".play"), g = a(this.shadowRoot).find(".pause"), I = a(this.shadowRoot).find(".forward"), s = a(this.shadowRoot).find(".backward"), t = a(this.shadowRoot).find(".fullscreen");
525
- if (A.on("click", () => this.play()), g.on("click", () => this.pause()), I.on("click", () => this.forward()), s.on("click", () => this.backward()), t.on("click", () => this.toggleFullscreen()), this._videoPlayer) {
526
- const o = a(this.shadowRoot).find(".duration"), i = a(this.shadowRoot).find(".progress-bar"), C = a(this.shadowRoot).find(".speed-container");
527
+ const A = r(this.shadowRoot).find(".play"), g = r(this.shadowRoot).find(".pause"), I = r(this.shadowRoot).find(".forward"), s = r(this.shadowRoot).find(".backward"), i = r(this.shadowRoot).find(".fullscreen");
528
+ if (A.on("click", () => this.play()), g.on("click", () => this.pause()), I.on("click", () => this.forward()), s.on("click", () => this.backward()), i.on("click", () => this.toggleFullscreen()), this._videoPlayer) {
529
+ const e = r(this.shadowRoot).find(".duration"), C = r(this.shadowRoot).find(".progress-bar"), o = r(this.shadowRoot).find(".speed-container");
527
530
  this._videoPlayer.addEventListener("play", () => {
528
531
  A.hide(), g.show();
529
532
  }), this._videoPlayer.addEventListener("pause", () => {
530
533
  g.hide(), A.show();
531
534
  }), this._videoPlayer.addEventListener("timeupdate", () => {
532
535
  if (!this._videoPlayer || !this.shadowRoot) return;
533
- const r = this._videoPlayer.currentTime, m = this._videoPlayer.duration, u = r / m * 100;
536
+ const a = this._videoPlayer.currentTime, m = this._videoPlayer.duration, u = a / m * 100;
534
537
  if (this.hasAttribute("show-time-display")) {
535
- const p = this.shadowRoot.querySelector(".current-time");
536
- p && (p.textContent = this.formatTime(r));
538
+ const h = this.shadowRoot.querySelector(".current-time");
539
+ h && (h.textContent = this.formatTime(a));
537
540
  }
538
541
  const b = this.shadowRoot.querySelector(".progress-bar-fill");
539
- if (b instanceof HTMLElement && (b.style.width = `${u}%`), this.progressBarStyle === e.Segments) {
540
- const p = this.shadowRoot.querySelectorAll(".progress-segment");
541
- p.forEach((M, w) => {
542
- const y = (w + 1) * (100 / p.length);
542
+ if (b instanceof HTMLElement && (b.style.width = `${u}%`), this.progressBarStyle === t.Segments) {
543
+ const h = this.shadowRoot.querySelectorAll(".progress-segment");
544
+ h.forEach((M, w) => {
545
+ const y = (w + 1) * (100 / h.length);
543
546
  u >= y ? M.classList.add("filled") : M.classList.remove("filled");
544
547
  });
545
548
  }
546
549
  }), this._videoPlayer.addEventListener("loadedmetadata", () => {
547
- this.hasAttribute("show-time-display") && o.text(this.formatTime(this._videoPlayer.duration));
548
- }), i.on("click", (r) => {
549
- const m = r.currentTarget.getBoundingClientRect(), u = (r.clientX - m.left) / m.width;
550
+ this.hasAttribute("show-time-display") && e.text(this.formatTime(this._videoPlayer.duration));
551
+ }), C.on("click", (a) => {
552
+ const m = a.currentTarget.getBoundingClientRect(), u = (a.clientX - m.left) / m.width;
550
553
  this._videoPlayer.currentTime = u * this._videoPlayer.duration;
551
554
  });
552
- const c = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2], d = this.getAttribute("playback-speeds")?.split(",").map(Number) || c, n = parseFloat(this.getAttribute("default-speed") || "1");
553
- let h = d.indexOf(n);
554
- h === -1 && (h = d.indexOf(1) || 0), n && !isNaN(n) && (this._videoPlayer.playbackRate = n, C.text(`${n}x`)), this.hasAttribute("show-speed-control") ? (C.show(), C.html(this.getSpeedIcon(n)), C.on("click", () => {
555
- h = (h + 1) % d.length;
556
- const r = d[h];
557
- this._videoPlayer.playbackRate = r, C.html(this.getSpeedIcon(r));
558
- })) : C.hide();
555
+ const n = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2], p = this.getAttribute("playback-speeds")?.split(",").map(Number) || n, d = parseFloat(this.getAttribute("default-speed") || "1");
556
+ let c = p.indexOf(d);
557
+ c === -1 && (c = p.indexOf(1) || 0), d && !isNaN(d) && (this._videoPlayer.playbackRate = d, o.text(`${d}x`)), this.hasAttribute("show-speed-control") ? (o.show(), o.html(this.getSpeedIcon(d)), o.on("click", () => {
558
+ c = (c + 1) % p.length;
559
+ const a = p[c];
560
+ this._videoPlayer.playbackRate = a, o.html(this.getSpeedIcon(a));
561
+ })) : o.hide();
559
562
  }
560
563
  }
561
564
  play() {
562
- this._videoPlayer && this._videoPlayer.play();
565
+ this._videoPlayer && (!this._streamLoaded && !this._autoPlay && this._hls && (this._hls.startLoad(this._startLevel), this._streamLoaded = !0), this._videoPlayer.play());
563
566
  }
564
567
  pause() {
565
568
  this._videoPlayer && this._videoPlayer.pause();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v360-tech/v360-player",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "A lightweight, customizable HLS video player web component with built-in controls",
5
5
  "type": "module",
6
6
  "main": "dist/v360-player.browser.js",