@geekapps/silo-elements-nextjs 0.3.6 → 0.3.7

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.
@@ -218,7 +218,12 @@ function Video({
218
218
  const best = sorted.find((e) => e.px >= targetPx) ?? sorted[sorted.length - 1];
219
219
  setPoster(best.url);
220
220
  }, [parsed.thumbnailUrls, parsed.thumbnailSrc, playerWidth]);
221
- const activeSource = parsed.sources[sourceIndex] ?? parsed.sources[0] ?? null;
221
+ const rawActiveSource = parsed.sources[sourceIndex] ?? parsed.sources[0] ?? null;
222
+ const activeSourceRef = useRef(null);
223
+ if (rawActiveSource?.src !== activeSourceRef.current?.src || rawActiveSource?.type !== activeSourceRef.current?.type) {
224
+ activeSourceRef.current = rawActiveSource;
225
+ }
226
+ const activeSource = activeSourceRef.current;
222
227
  const progressPercent = duration ? currentTime / duration * 100 : 0;
223
228
  const bufferedPercent = duration ? bufferedTime / duration * 100 : 0;
224
229
  const destroyMediaEngines = useCallback(() => {
@@ -466,7 +471,9 @@ function Video({
466
471
  }, 60 * 1e3);
467
472
  }
468
473
  };
469
- const onWaiting = () => setIsLoading(true);
474
+ const onWaiting = () => {
475
+ if (video.played.length > 0) setIsLoading(true);
476
+ };
470
477
  const onCanPlay = () => setIsLoading(false);
471
478
  const onEnded = () => setControlsVisible(true);
472
479
  video.addEventListener("timeupdate", syncTime);
@@ -751,6 +758,7 @@ function Video({
751
758
  const HlsModule = await import('hls.js');
752
759
  if (cancelled) return;
753
760
  const Hls = HlsModule.default;
761
+ console.debug("[Silo/hls] Hls.isSupported()=", Hls.isSupported());
754
762
  if (Hls.isSupported()) {
755
763
  const hls = new Hls({
756
764
  enableWorker: true,
@@ -759,10 +767,12 @@ function Video({
759
767
  maxBufferSize: 20 * 1e3 * 1e3
760
768
  });
761
769
  hlsRef.current = hls;
770
+ console.debug("[Silo/hls] loadSource", activeSource.src);
762
771
  hls.loadSource(activeSource.src);
763
772
  hls.attachMedia(video);
764
773
  hls.on(Hls.Events.MANIFEST_PARSED, (_, data) => {
765
774
  const levels = data.levels ?? hls.levels ?? [];
775
+ console.debug("[Silo/hls] MANIFEST_PARSED levels=", levels.length, "audioTracks=", hls.audioTracks?.length ?? 0);
766
776
  setQualities([
767
777
  AUTO_QUALITY,
768
778
  ...levels.map((level, index) => ({
@@ -773,6 +783,7 @@ function Video({
773
783
  }))
774
784
  ]);
775
785
  const tracks = hls.audioTracks ?? [];
786
+ console.debug("[Silo/hls] audio tracks:", tracks.map((t) => ({ name: t.name, lang: t.lang, url: t.url })));
776
787
  if (tracks.length > 1) {
777
788
  setAudioTracks(
778
789
  tracks.map((t, i) => ({
@@ -786,6 +797,7 @@ function Video({
786
797
  });
787
798
  hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, (_, data) => {
788
799
  const tracks = data.audioTracks ?? [];
800
+ console.debug("[Silo/hls] AUDIO_TRACKS_UPDATED", tracks.length);
789
801
  if (tracks.length > 1) {
790
802
  setAudioTracks(
791
803
  tracks.map((t, i) => ({
@@ -795,18 +807,41 @@ function Video({
795
807
  );
796
808
  }
797
809
  });
810
+ hls.on(Hls.Events.LEVEL_LOADED, (_, data) => {
811
+ console.debug("[Silo/hls] LEVEL_LOADED level=", data.level, "fragments=", data.details?.fragments?.length);
812
+ });
813
+ hls.on(Hls.Events.AUDIO_TRACK_LOADED, (_, data) => {
814
+ console.debug("[Silo/hls] AUDIO_TRACK_LOADED track=", data.id, "fragments=", data.details?.fragments?.length);
815
+ });
816
+ hls.on(Hls.Events.FRAG_LOADING, (_, data) => {
817
+ console.debug("[Silo/hls] FRAG_LOADING", data.frag?.type, data.frag?.url?.slice(-60));
818
+ });
819
+ hls.on(Hls.Events.FRAG_LOADED, (_, data) => {
820
+ console.debug("[Silo/hls] FRAG_LOADED", data.frag?.type, data.frag?.sn);
821
+ });
822
+ let mediaErrorAttempts = 0;
798
823
  hls.on(Hls.Events.ERROR, (_, data) => {
824
+ console.debug("[Silo/hls] ERROR fatal=", data.fatal, "type=", data.type, "details=", data.details, "url=", (data.frag?.url ?? data.url ?? "").slice(-80));
799
825
  if (!data.fatal) return;
800
- if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
826
+ if (data.type === Hls.ErrorTypes.MEDIA_ERROR && mediaErrorAttempts < 2) {
827
+ mediaErrorAttempts += 1;
828
+ console.debug("[Silo/hls] recoverMediaError attempt", mediaErrorAttempts);
801
829
  hls.recoverMediaError();
802
830
  return;
803
831
  }
804
- console.error("[Silo] HLS playback failed");
832
+ console.error("[Silo] HLS playback failed", data.details);
833
+ hls.destroy();
834
+ hlsRef.current = null;
805
835
  setIsLoading(false);
806
836
  });
837
+ video.addEventListener("waiting", () => console.debug("[Silo/hls] video:waiting readyState=", video.readyState, "played=", video.played.length));
838
+ video.addEventListener("canplay", () => console.debug("[Silo/hls] video:canplay readyState=", video.readyState));
839
+ video.addEventListener("stalled", () => console.debug("[Silo/hls] video:stalled"));
840
+ video.addEventListener("suspend", () => console.debug("[Silo/hls] video:suspend"));
807
841
  return;
808
842
  }
809
843
  if (video.canPlayType("application/vnd.apple.mpegurl")) {
844
+ console.debug("[Silo/hls] using native HLS (Safari)");
810
845
  video.src = activeSource.src;
811
846
  video.load();
812
847
  setIsLoading(false);