@v360-tech/v360-player 1.4.0 → 1.4.1
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 +54 -54
- package/package.json +1 -1
package/dist/v360-player.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import l from "hls.js";
|
|
2
2
|
import a from "jquery";
|
|
3
|
-
const
|
|
3
|
+
const e = {
|
|
4
4
|
None: "none",
|
|
5
5
|
DualLayer: "dual-layer",
|
|
6
6
|
Segments: "segments",
|
|
7
7
|
MinimalWave: "minimal-wave"
|
|
8
8
|
}, v = {
|
|
9
|
-
[
|
|
9
|
+
[e.None]: `
|
|
10
10
|
.progress-bar {
|
|
11
11
|
flex: 1;
|
|
12
12
|
height: 4px;
|
|
@@ -24,7 +24,7 @@ const t = {
|
|
|
24
24
|
border-radius: 2px;
|
|
25
25
|
}
|
|
26
26
|
`,
|
|
27
|
-
[
|
|
27
|
+
[e.DualLayer]: `
|
|
28
28
|
.progress-bar {
|
|
29
29
|
flex: 1;
|
|
30
30
|
height: 8px;
|
|
@@ -67,7 +67,7 @@ const t = {
|
|
|
67
67
|
transform: translateY(-50%) scale(1.2);
|
|
68
68
|
}
|
|
69
69
|
`,
|
|
70
|
-
[
|
|
70
|
+
[e.Segments]: `
|
|
71
71
|
.progress-bar {
|
|
72
72
|
flex: 1;
|
|
73
73
|
height: 4px;
|
|
@@ -105,7 +105,7 @@ const t = {
|
|
|
105
105
|
background: #40A2FF;
|
|
106
106
|
}
|
|
107
107
|
`,
|
|
108
|
-
[
|
|
108
|
+
[e.MinimalWave]: `
|
|
109
109
|
.progress-bar {
|
|
110
110
|
flex: 1;
|
|
111
111
|
height: 2px;
|
|
@@ -165,7 +165,7 @@ const t = {
|
|
|
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 =
|
|
168
|
+
progressBarStyle = e.None;
|
|
169
169
|
_hls;
|
|
170
170
|
_videoPlayer;
|
|
171
171
|
background = "dark";
|
|
@@ -175,7 +175,7 @@ class z extends HTMLElement {
|
|
|
175
175
|
return g / A * 100;
|
|
176
176
|
}
|
|
177
177
|
isValidProgressBarStyle(A) {
|
|
178
|
-
return Object.values(
|
|
178
|
+
return Object.values(e).includes(A);
|
|
179
179
|
}
|
|
180
180
|
// Import icons from dedicated file
|
|
181
181
|
svgIcons = W;
|
|
@@ -200,7 +200,7 @@ class z extends HTMLElement {
|
|
|
200
200
|
}
|
|
201
201
|
attributeChangedCallback(A, g, I) {
|
|
202
202
|
if (A === "progress-bar-style")
|
|
203
|
-
this.progressBarStyle = this.isValidProgressBarStyle(I) ? I :
|
|
203
|
+
this.progressBarStyle = this.isValidProgressBarStyle(I) ? I : e.None, this.render();
|
|
204
204
|
else if (A === "background")
|
|
205
205
|
this.background = I === "light" ? "light" : "dark", this.updateControlsColor();
|
|
206
206
|
else if (A === "aspect-ratio") {
|
|
@@ -219,26 +219,26 @@ class z extends HTMLElement {
|
|
|
219
219
|
if (!A || !g) return;
|
|
220
220
|
const I = () => {
|
|
221
221
|
if (!this._videoPlayer) return;
|
|
222
|
-
const
|
|
223
|
-
if (g.style.width = `${
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
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");
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
231
|
this._videoPlayer.addEventListener("timeupdate", I);
|
|
232
|
-
const s = (
|
|
233
|
-
if (!this._videoPlayer || !(
|
|
234
|
-
const
|
|
235
|
-
this._videoPlayer.currentTime =
|
|
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;
|
|
236
236
|
};
|
|
237
237
|
A.addEventListener("click", s);
|
|
238
238
|
}
|
|
239
239
|
renderProgressBar() {
|
|
240
240
|
switch (this.progressBarStyle) {
|
|
241
|
-
case
|
|
241
|
+
case e.DualLayer:
|
|
242
242
|
return `
|
|
243
243
|
<div class="progress-bar">
|
|
244
244
|
<div class="progress-bar-buffer"></div>
|
|
@@ -246,7 +246,7 @@ class z extends HTMLElement {
|
|
|
246
246
|
<div class="progress-handle"></div>
|
|
247
247
|
</div>
|
|
248
248
|
`;
|
|
249
|
-
case
|
|
249
|
+
case e.Segments:
|
|
250
250
|
return `
|
|
251
251
|
<div class="progress-bar">
|
|
252
252
|
${Array.from({ length: 20 }, (A, g) => `
|
|
@@ -254,14 +254,14 @@ class z extends HTMLElement {
|
|
|
254
254
|
`).join("")}
|
|
255
255
|
</div>
|
|
256
256
|
`;
|
|
257
|
-
case
|
|
257
|
+
case e.MinimalWave:
|
|
258
258
|
return `
|
|
259
259
|
<div class="progress-bar">
|
|
260
260
|
<div class="progress-bar-fill" style="width: 0%"></div>
|
|
261
261
|
<div class="progress-wave"></div>
|
|
262
262
|
</div>
|
|
263
263
|
`;
|
|
264
|
-
case
|
|
264
|
+
case e.None:
|
|
265
265
|
default:
|
|
266
266
|
return "";
|
|
267
267
|
}
|
|
@@ -469,13 +469,13 @@ class z extends HTMLElement {
|
|
|
469
469
|
async initializeHls(A, g) {
|
|
470
470
|
return new Promise((I, s) => {
|
|
471
471
|
try {
|
|
472
|
-
const
|
|
473
|
-
debug:
|
|
472
|
+
const o = {
|
|
473
|
+
// debug: true,
|
|
474
474
|
enableWorker: !0,
|
|
475
475
|
lowLatencyMode: !0,
|
|
476
476
|
backBufferLength: 90,
|
|
477
|
-
startLevel: -1,
|
|
478
|
-
autoStartLoad:
|
|
477
|
+
startLevel: parseInt(this.getAttribute("default-quality") || "-1"),
|
|
478
|
+
autoStartLoad: this.hasAttribute("auto-play"),
|
|
479
479
|
manifestLoadingTimeOut: 2e4,
|
|
480
480
|
manifestLoadingMaxRetry: 3,
|
|
481
481
|
manifestLoadingRetryDelay: 500,
|
|
@@ -485,11 +485,11 @@ class z extends HTMLElement {
|
|
|
485
485
|
fragLoadingTimeOut: 2e4,
|
|
486
486
|
fragLoadingMaxRetry: 3,
|
|
487
487
|
fragLoadingRetryDelay: 500,
|
|
488
|
-
xhrSetup: (
|
|
489
|
-
|
|
488
|
+
xhrSetup: (i) => {
|
|
489
|
+
i.withCredentials = !1, i.setRequestHeader(j, D);
|
|
490
490
|
}
|
|
491
491
|
};
|
|
492
|
-
this._hls = new l(
|
|
492
|
+
this._hls = new l(o), this._hls.on(l.Events.ERROR, (i, C) => {
|
|
493
493
|
if (console.error("HLS Error:", C), C.fatal)
|
|
494
494
|
switch (C.type) {
|
|
495
495
|
case l.ErrorTypes.NETWORK_ERROR:
|
|
@@ -504,26 +504,26 @@ class z extends HTMLElement {
|
|
|
504
504
|
}
|
|
505
505
|
}), this._hls.on(l.Events.MEDIA_ATTACHED, () => {
|
|
506
506
|
console.log("Media attached, loading source:", g), this._hls?.loadSource(g);
|
|
507
|
-
}), this._hls.on(l.Events.MANIFEST_PARSED, (
|
|
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 (
|
|
509
|
-
console.error("Autoplay failed:",
|
|
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;
|
|
510
510
|
try {
|
|
511
511
|
await A.play(), console.log("Muted autoplay successful");
|
|
512
|
-
} catch (
|
|
513
|
-
console.error("Muted autoplay also failed:",
|
|
512
|
+
} catch (d) {
|
|
513
|
+
console.error("Muted autoplay also failed:", d);
|
|
514
514
|
}
|
|
515
515
|
}));
|
|
516
516
|
}), console.log("Attaching media element..."), this._hls.attachMedia(A);
|
|
517
|
-
} catch (
|
|
518
|
-
console.error("Error in HLS initialization:",
|
|
517
|
+
} catch (t) {
|
|
518
|
+
console.error("Error in HLS initialization:", t), s(t);
|
|
519
519
|
}
|
|
520
520
|
});
|
|
521
521
|
}
|
|
522
522
|
startListeners() {
|
|
523
523
|
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"),
|
|
525
|
-
if (A.on("click", () => this.play()), g.on("click", () => this.pause()), I.on("click", () => this.forward()), s.on("click", () => this.backward()),
|
|
526
|
-
const
|
|
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
527
|
this._videoPlayer.addEventListener("play", () => {
|
|
528
528
|
A.hide(), g.show();
|
|
529
529
|
}), this._videoPlayer.addEventListener("pause", () => {
|
|
@@ -532,30 +532,30 @@ class z extends HTMLElement {
|
|
|
532
532
|
if (!this._videoPlayer || !this.shadowRoot) return;
|
|
533
533
|
const r = this._videoPlayer.currentTime, m = this._videoPlayer.duration, u = r / m * 100;
|
|
534
534
|
if (this.hasAttribute("show-time-display")) {
|
|
535
|
-
const
|
|
536
|
-
|
|
535
|
+
const p = this.shadowRoot.querySelector(".current-time");
|
|
536
|
+
p && (p.textContent = this.formatTime(r));
|
|
537
537
|
}
|
|
538
538
|
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 /
|
|
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);
|
|
543
543
|
u >= y ? M.classList.add("filled") : M.classList.remove("filled");
|
|
544
544
|
});
|
|
545
545
|
}
|
|
546
546
|
}), this._videoPlayer.addEventListener("loadedmetadata", () => {
|
|
547
|
-
this.hasAttribute("show-time-display") &&
|
|
548
|
-
}),
|
|
547
|
+
this.hasAttribute("show-time-display") && o.text(this.formatTime(this._videoPlayer.duration));
|
|
548
|
+
}), i.on("click", (r) => {
|
|
549
549
|
const m = r.currentTarget.getBoundingClientRect(), u = (r.clientX - m.left) / m.width;
|
|
550
550
|
this._videoPlayer.currentTime = u * this._videoPlayer.duration;
|
|
551
551
|
});
|
|
552
|
-
const
|
|
553
|
-
let
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
const r =
|
|
557
|
-
this._videoPlayer.playbackRate = r,
|
|
558
|
-
})) :
|
|
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();
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
561
|
play() {
|
package/package.json
CHANGED