@geekapps/silo-elements-nextjs 0.3.20 → 0.3.22
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/VideoPlayer.js +47 -14
- package/dist/VideoPlayer.js.map +1 -1
- package/dist/index.js +47 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1550,9 +1550,8 @@ function deviceSupportsHdr() {
|
|
|
1550
1550
|
function deviceSupportsOpus() {
|
|
1551
1551
|
if (typeof window === "undefined") return false;
|
|
1552
1552
|
try {
|
|
1553
|
-
if (typeof MediaSource !== "undefined" && MediaSource.isTypeSupported)
|
|
1554
|
-
|
|
1555
|
-
}
|
|
1553
|
+
if (typeof MediaSource !== "undefined" && MediaSource.isTypeSupported)
|
|
1554
|
+
return MediaSource.isTypeSupported('audio/mp4; codecs="opus"');
|
|
1556
1555
|
const a = document.createElement("audio");
|
|
1557
1556
|
return a.canPlayType('audio/ogg; codecs="opus"') !== "" || a.canPlayType('video/mp4; codecs="opus"') !== "";
|
|
1558
1557
|
} catch {
|
|
@@ -2403,6 +2402,12 @@ function Video({
|
|
|
2403
2402
|
const Hls = HlsModule.default;
|
|
2404
2403
|
console.debug("[Silo/hls] Hls.isSupported()=", Hls.isSupported());
|
|
2405
2404
|
if (Hls.isSupported()) {
|
|
2405
|
+
let audioCodecPriority2 = function(codec) {
|
|
2406
|
+
const c = codec.toLowerCase();
|
|
2407
|
+
const idx = AUDIO_CODEC_PRIORITY.findIndex((k) => c.includes(k));
|
|
2408
|
+
return idx === -1 ? 0 : idx;
|
|
2409
|
+
};
|
|
2410
|
+
var audioCodecPriority = audioCodecPriority2;
|
|
2406
2411
|
const hls = new Hls({
|
|
2407
2412
|
enableWorker: true,
|
|
2408
2413
|
// Buffer ~20s ahead (≈1/6 of a 2min video). maxMaxBufferLength caps the
|
|
@@ -2464,18 +2469,36 @@ function Video({
|
|
|
2464
2469
|
if (pinnedAudio >= 0) hls.audioTrack = pinnedAudio;
|
|
2465
2470
|
setIsLoading(false);
|
|
2466
2471
|
});
|
|
2472
|
+
const AUDIO_CODEC_PRIORITY = ["opus", "mp4a", "aac", "ac-3", "ac3", "dts", "ec-3", "eac3", "dts-hd", "dtshd", "truehd"];
|
|
2473
|
+
let audioUpgradeDone = false;
|
|
2474
|
+
let mappedAudioTracks = [];
|
|
2467
2475
|
hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, (_, data) => {
|
|
2468
2476
|
const tracks = data.audioTracks ?? [];
|
|
2469
2477
|
console.debug("[Silo/hls] AUDIO_TRACKS_UPDATED", tracks.length);
|
|
2470
|
-
if (tracks.length >
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2478
|
+
if (tracks.length > 0) {
|
|
2479
|
+
mappedAudioTracks = tracks.map((t, i) => {
|
|
2480
|
+
const codec = (t.attrs?.CODECS ?? t.codecSet ?? "").split(",")[0]?.trim() ?? "";
|
|
2481
|
+
const supported = deviceSupportsAudioCodec(codec);
|
|
2482
|
+
const label = friendlyAudioLabel(t.name, t.lang, codec, t.channels ?? t.attrs?.CHANNELS);
|
|
2483
|
+
return { id: i, label, supported, codec };
|
|
2484
|
+
});
|
|
2485
|
+
if (pinnedAudio === -1) {
|
|
2486
|
+
const opusTrack = mappedAudioTracks.find((t) => t.supported && /opus/i.test(t.codec));
|
|
2487
|
+
const fallback = mappedAudioTracks.find((t) => t.supported);
|
|
2488
|
+
const startTrack = opusTrack ?? fallback;
|
|
2489
|
+
if (startTrack) {
|
|
2490
|
+
hls.audioTrack = startTrack.id;
|
|
2491
|
+
setSelectedAudio(startTrack.id);
|
|
2492
|
+
console.debug("[Silo/hls] starting with audio track", startTrack.id, startTrack.codec);
|
|
2493
|
+
} else {
|
|
2494
|
+
console.warn("[Silo/hls] no supported audio track found \u2014 disabling");
|
|
2495
|
+
try {
|
|
2496
|
+
hls.audioTrack = -1;
|
|
2497
|
+
} catch {
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
if (mappedAudioTracks.length > 1) setAudioTracks(mappedAudioTracks.map(({ id, label, supported }) => ({ id, label, supported })));
|
|
2479
2502
|
}
|
|
2480
2503
|
if (pinnedAudio >= 0 && hls.audioTrack !== pinnedAudio) {
|
|
2481
2504
|
hls.audioTrack = pinnedAudio;
|
|
@@ -2507,6 +2530,16 @@ function Video({
|
|
|
2507
2530
|
});
|
|
2508
2531
|
hls.on(Hls.Events.FRAG_LOADED, (_, data) => {
|
|
2509
2532
|
console.debug("[Silo/hls] FRAG_LOADED", data.frag?.type, data.frag?.sn);
|
|
2533
|
+
if (!audioUpgradeDone && data.frag?.type === "audio" && data.frag?.sn === 0 && pinnedAudio === -1 && mappedAudioTracks.length > 1) {
|
|
2534
|
+
audioUpgradeDone = true;
|
|
2535
|
+
const supported = mappedAudioTracks.filter((t) => t.supported);
|
|
2536
|
+
const best = supported.reduce((a, b) => audioCodecPriority2(b.codec) > audioCodecPriority2(a.codec) ? b : a, supported[0]);
|
|
2537
|
+
if (best && best.id !== hls.audioTrack) {
|
|
2538
|
+
console.debug("[Silo/hls] upgrading audio track", hls.audioTrack, "\u2192", best.id, best.codec);
|
|
2539
|
+
hls.audioTrack = best.id;
|
|
2540
|
+
setSelectedAudio(best.id);
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2510
2543
|
});
|
|
2511
2544
|
let mediaErrorAttempts = 0;
|
|
2512
2545
|
let audioAppendErrors = 0;
|
|
@@ -2519,8 +2552,8 @@ function Video({
|
|
|
2519
2552
|
const isAudioBufError = fragType === "audio" && (data.details === Hls.ErrorDetails.BUFFER_APPEND_ERROR || data.details === Hls.ErrorDetails.BUFFER_APPENDING_ERROR);
|
|
2520
2553
|
if (isAudioBufError) {
|
|
2521
2554
|
audioAppendErrors += 1;
|
|
2522
|
-
if (audioAppendErrors >=
|
|
2523
|
-
console.warn("[Silo/hls]
|
|
2555
|
+
if (audioAppendErrors >= 1) {
|
|
2556
|
+
console.warn("[Silo/hls] audio buffer append error \u2014 disabling separate audio tracks");
|
|
2524
2557
|
setAudioTracks([]);
|
|
2525
2558
|
try {
|
|
2526
2559
|
hls.audioTrack = -1;
|