@v360-tech/v360-player 1.4.1 → 1.4.3
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.
- package/dist/v360-player.browser.js +18 -18
- package/dist/v360-player.js +70 -67
- package/package.json +1 -1
package/dist/v360-player.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import l from "hls.js";
|
|
2
|
-
import
|
|
3
|
-
const
|
|
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
|
-
[
|
|
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
|
-
[
|
|
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
|
-
[
|
|
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
|
-
[
|
|
108
|
+
[t.MinimalWave]: `
|
|
109
109
|
.progress-bar {
|
|
110
110
|
flex: 1;
|
|
111
111
|
height: 2px;
|
|
@@ -163,19 +163,22 @@ const e = {
|
|
|
163
163
|
"speed-1.00": `<img src="${Y}" width="24" height="24" alt="1x speed">`,
|
|
164
164
|
"speed-1.50": `<img src="${R}" width="24" height="24" alt="1.5x speed">`,
|
|
165
165
|
"speed-2.00": `<img src="${N}" width="24" height="24" alt="2x speed">`
|
|
166
|
-
}, j = "X-Jewel-
|
|
166
|
+
}, j = "X-Jewel-Studio", D = "69d2c1660df6540944e25eb708fb252724ab27fb";
|
|
167
167
|
class z extends HTMLElement {
|
|
168
|
-
progressBarStyle =
|
|
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(
|
|
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 :
|
|
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
|
|
223
|
-
if (g.style.width = `${
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
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 = (
|
|
233
|
-
if (!this._videoPlayer || !(
|
|
234
|
-
const
|
|
235
|
-
this._videoPlayer.currentTime =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
475
|
+
const i = {
|
|
473
476
|
// debug: true,
|
|
474
477
|
enableWorker: !0,
|
|
475
478
|
lowLatencyMode: !0,
|
|
476
479
|
backBufferLength: 90,
|
|
477
|
-
startLevel:
|
|
478
|
-
autoStartLoad: this.
|
|
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: (
|
|
489
|
-
|
|
491
|
+
xhrSetup: (e) => {
|
|
492
|
+
e.withCredentials = !1, e.setRequestHeader(j, D);
|
|
490
493
|
}
|
|
491
494
|
};
|
|
492
|
-
this._hls = new l(
|
|
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.
|
|
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.
|
|
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.
|
|
507
|
-
}), this._hls.on(l.Events.MANIFEST_PARSED, (
|
|
508
|
-
console.
|
|
509
|
-
console.error("Autoplay failed:",
|
|
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.
|
|
512
|
-
} catch (
|
|
513
|
-
console.error("Muted autoplay also failed:",
|
|
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.
|
|
517
|
-
} catch (
|
|
518
|
-
console.error("Error in HLS initialization:",
|
|
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 =
|
|
525
|
-
if (A.on("click", () => this.play()), g.on("click", () => this.pause()), I.on("click", () => this.forward()), s.on("click", () => this.backward()),
|
|
526
|
-
const
|
|
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
|
|
536
|
+
const a = this._videoPlayer.currentTime, m = this._videoPlayer.duration, u = a / m * 100;
|
|
534
537
|
if (this.hasAttribute("show-time-display")) {
|
|
535
|
-
const
|
|
536
|
-
|
|
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 ===
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
const y = (w + 1) * (100 /
|
|
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") &&
|
|
548
|
-
}),
|
|
549
|
-
const m =
|
|
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
|
|
553
|
-
let
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
const
|
|
557
|
-
this._videoPlayer.playbackRate =
|
|
558
|
-
})) :
|
|
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