@geekapps/silo-elements-nextjs 0.3.22 → 0.3.23

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/index.js CHANGED
@@ -2402,12 +2402,22 @@ function Video({
2402
2402
  const Hls = HlsModule.default;
2403
2403
  console.debug("[Silo/hls] Hls.isSupported()=", Hls.isSupported());
2404
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;
2405
+ let tryNextAudioTrack2 = function() {
2406
+ const next = mappedAudioTracks.find((t) => t.supported && !failedAudioTracks.has(t.id));
2407
+ if (next) {
2408
+ console.debug("[Silo/hls] trying audio track", next.id, next.codec || "(unknown codec)");
2409
+ hls.audioTrack = next.id;
2410
+ if (pinnedAudio === -1) setSelectedAudio(next.id);
2411
+ } else {
2412
+ console.warn("[Silo/hls] all audio tracks failed \u2014 disabling demuxed audio");
2413
+ setAudioTracks([]);
2414
+ try {
2415
+ hls.audioTrack = -1;
2416
+ } catch {
2417
+ }
2418
+ }
2409
2419
  };
2410
- var audioCodecPriority = audioCodecPriority2;
2420
+ var tryNextAudioTrack = tryNextAudioTrack2;
2411
2421
  const hls = new Hls({
2412
2422
  enableWorker: true,
2413
2423
  // Buffer ~20s ahead (≈1/6 of a 2min video). maxMaxBufferLength caps the
@@ -2469,9 +2479,8 @@ function Video({
2469
2479
  if (pinnedAudio >= 0) hls.audioTrack = pinnedAudio;
2470
2480
  setIsLoading(false);
2471
2481
  });
2472
- const AUDIO_CODEC_PRIORITY = ["opus", "mp4a", "aac", "ac-3", "ac3", "dts", "ec-3", "eac3", "dts-hd", "dtshd", "truehd"];
2473
- let audioUpgradeDone = false;
2474
2482
  let mappedAudioTracks = [];
2483
+ const failedAudioTracks = /* @__PURE__ */ new Set();
2475
2484
  hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, (_, data) => {
2476
2485
  const tracks = data.audioTracks ?? [];
2477
2486
  console.debug("[Silo/hls] AUDIO_TRACKS_UPDATED", tracks.length);
@@ -2483,19 +2492,11 @@ function Video({
2483
2492
  return { id: i, label, supported, codec };
2484
2493
  });
2485
2494
  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
- }
2495
+ const first = mappedAudioTracks.find((t) => t.supported) ?? mappedAudioTracks[0];
2496
+ if (first) {
2497
+ hls.audioTrack = first.id;
2498
+ setSelectedAudio(first.id);
2499
+ console.debug("[Silo/hls] starting with audio track", first.id, first.codec || "(unknown codec)");
2499
2500
  }
2500
2501
  }
2501
2502
  if (mappedAudioTracks.length > 1) setAudioTracks(mappedAudioTracks.map(({ id, label, supported }) => ({ id, label, supported })));
@@ -2530,19 +2531,8 @@ function Video({
2530
2531
  });
2531
2532
  hls.on(Hls.Events.FRAG_LOADED, (_, data) => {
2532
2533
  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
- }
2543
2534
  });
2544
2535
  let mediaErrorAttempts = 0;
2545
- let audioAppendErrors = 0;
2546
2536
  let stalledOnPinnedLevel = 0;
2547
2537
  hls.on(Hls.Events.ERROR, (_, data) => {
2548
2538
  const fragUrl = (data.frag?.url ?? data.url ?? "").slice(-80);
@@ -2551,18 +2541,12 @@ function Video({
2551
2541
  if (!data.fatal) {
2552
2542
  const isAudioBufError = fragType === "audio" && (data.details === Hls.ErrorDetails.BUFFER_APPEND_ERROR || data.details === Hls.ErrorDetails.BUFFER_APPENDING_ERROR);
2553
2543
  if (isAudioBufError) {
2554
- audioAppendErrors += 1;
2555
- if (audioAppendErrors >= 1) {
2556
- console.warn("[Silo/hls] audio buffer append error \u2014 disabling separate audio tracks");
2557
- setAudioTracks([]);
2558
- try {
2559
- hls.audioTrack = -1;
2560
- } catch {
2561
- }
2562
- audioAppendErrors = 0;
2544
+ const failedTrack = hls.audioTrack;
2545
+ if (failedTrack >= 0 && pinnedAudio === -1) {
2546
+ failedAudioTracks.add(failedTrack);
2547
+ console.warn("[Silo/hls] audio track", failedTrack, "failed \u2014 trying next");
2548
+ tryNextAudioTrack2();
2563
2549
  }
2564
- } else {
2565
- audioAppendErrors = 0;
2566
2550
  }
2567
2551
  if (data.details === Hls.ErrorDetails.BUFFER_STALLED_ERROR && pinnedLevel >= 0) {
2568
2552
  stalledOnPinnedLevel += 1;