ez-vid-ang 22.0.9 → 22.0.10

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.
@@ -819,6 +819,34 @@ class EvaApi {
819
819
  const currentPercent = this.getVideoVolume() * PERCENTAGE;
820
820
  this.setVideoVolume((currentPercent + direction * VOLUME_ARROW_KEY_STEP) / PERCENTAGE);
821
821
  }
822
+ /**
823
+ * Resets native-video-derived playback state ahead of an explicit `.load()` call
824
+ * triggered by a runtime `evaVideoSources` change. Called by `EvaPlayer.ngAfterViewChecked()`
825
+ * immediately before it reloads the video element.
826
+ *
827
+ * `HTMLMediaElement.load()` silently resets the element to a paused state — per the HTML5
828
+ * media element load algorithm — without dispatching a `pause` event, or any other event
829
+ * `EvaMediaEventListenersDirective` listens to. Without this reset, `EvaApi`'s state would
830
+ * go stale across the switch: e.g. `videoStateSubject` would keep reporting `PLAYING`
831
+ * indefinitely after switching away from a playing video — even though the video is no
832
+ * longer actually playing — until the *next* native event happens to correct it, which may
833
+ * never come if the new source fails to load (confirmed via real-browser testing: no
834
+ * `pause` event fires at any point during a source switch, playing or not).
835
+ *
836
+ * Mirrors the fields' initial values so the player looks the same as it would on first
837
+ * load, since the browser is about to re-run the same resource-selection algorithm.
838
+ */
839
+ prepareForSourceChange() {
840
+ this.currentVideoState = EvaState.LOADING;
841
+ this.videoStateSubject.next(this.currentVideoState);
842
+ this.canPlay.set(false);
843
+ this.isBuffering.set(true);
844
+ this.isSeeking.set(false);
845
+ this.isLive.set(false);
846
+ this.hasStartedPlaying = false;
847
+ this.pendingPlayAfterSeek = false;
848
+ this.time.set({ current: 0, remaining: 0, total: 0 });
849
+ }
822
850
  // ─── Event Listener Callbacks ─────────────────────────────────────────────
823
851
  /**
824
852
  * Called from `EvaMediaEventListenersDirective` on the `error` event.
@@ -9697,6 +9725,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImpor
9697
9725
  * - Assigns the native `<video>` element to `EvaApi` after the view initializes.
9698
9726
  * - Signals player readiness via `EvaApi.onPlayerReady()`.
9699
9727
  * - Propagates `evaVideoTracks` changes to `EvaApi.videoTracksSubject` at runtime.
9728
+ * - Reloads the video element when `evaVideoSources` changes at runtime (e.g. switching to a
9729
+ * different video), since the browser does not do this on its own once a `<video>` has
9730
+ * already loaded once — see `ngOnChanges`/`ngAfterViewChecked`.
9700
9731
  * - Optionally integrates HLS or DASH streaming via `EvaHlsDirective` / `EvaDashDirective`
9701
9732
  * (injected optionally — absent if neither streaming directive is present).
9702
9733
  *
@@ -9800,9 +9831,38 @@ class EvaPlayer {
9800
9831
  activeSubtitleLabel = signal(null, /* @ts-ignore */
9801
9832
  ...(ngDevMode ? [{ debugName: "activeSubtitleLabel" }] : /* istanbul ignore next */ []));
9802
9833
  /**
9803
- * Responds to runtime changes of `evaVideoTracks`.
9804
- * Forwards the updated track list to `EvaApi.videoTracksSubject` so that
9805
- * child components (e.g. `eva-track-selector`) stay in sync.
9834
+ * Serialized form (`type`+`src`+`media` per entry) of the last-seen `evaVideoSources()`
9835
+ * value. `null` until the first `ngOnChanges` run. Used to detect a genuine content change
9836
+ * while ignoring array-reference-only re-emissions — e.g. an inline `[]` literal recreated
9837
+ * by an unrelated parent re-render in HLS/DASH setups, where `evaVideoSources` is
9838
+ * intentionally empty and unrelated to playback — which would otherwise trigger a
9839
+ * spurious reload. `SimpleChanges` alone can't distinguish these, since Angular compares
9840
+ * `evaVideoSources` by reference, not content.
9841
+ */
9842
+ previousVideoSourcesKey = null;
9843
+ /**
9844
+ * Set by `ngOnChanges` when `evaVideoSources` has genuinely changed, and consumed by
9845
+ * `ngAfterViewChecked` on the same change-detection pass. See `ngOnChanges` for why the
9846
+ * actual `.load()` call is deferred to `ngAfterViewChecked` rather than made directly here.
9847
+ */
9848
+ pendingVideoSourcesReload = false;
9849
+ /**
9850
+ * Responds to runtime changes of `evaVideoTracks` and `evaVideoSources`.
9851
+ *
9852
+ * `evaVideoTracks` changes are forwarded to `EvaApi.videoTracksSubject` so that child
9853
+ * components (e.g. `eva-track-selector`) stay in sync.
9854
+ *
9855
+ * `evaVideoSources` changes need to reload the video element — per the HTML5 media
9856
+ * resource-selection algorithm, a `<video>` element only re-reads its `<source>` children
9857
+ * via `.load()`, on initial load or when explicitly told to; updating the `<source>`
9858
+ * elements' `src`/`type` attributes alone (already handled by the template binding) has no
9859
+ * effect once the element has already loaded once. `ngOnChanges` only *detects* a genuine
9860
+ * change here (skipping the first change, and comparing content rather than array
9861
+ * reference so an incidentally-recreated-but-identical array — e.g. `[]` in HLS/DASH
9862
+ * setups — doesn't trigger a reload) and records it in `pendingVideoSourcesReload`. The
9863
+ * `.load()` call itself happens in `ngAfterViewChecked`, since `ngOnChanges` fires *before*
9864
+ * this component's own template — including the `<source>` elements' bindings — is
9865
+ * refreshed; calling `.load()` here would reload the still-stale previous source.
9806
9866
  *
9807
9867
  * @param changes - The `SimpleChanges` map provided by Angular.
9808
9868
  */
@@ -9810,6 +9870,14 @@ class EvaPlayer {
9810
9870
  if (changes["evaVideoTracks"]) {
9811
9871
  this.playerMainAPI.updateAndPrepareTracks(changes["evaVideoTracks"].currentValue);
9812
9872
  }
9873
+ if (changes["evaVideoSources"]) {
9874
+ const isFirstChange = changes["evaVideoSources"].firstChange;
9875
+ const sources = this.evaVideoSources();
9876
+ const key = JSON.stringify(sources.map((s) => ({ type: s.type, src: s.src, media: s.media })));
9877
+ const hasGenuinelyChanged = key !== this.previousVideoSourcesKey;
9878
+ this.previousVideoSourcesKey = key;
9879
+ this.pendingVideoSourcesReload = !isFirstChange && hasGenuinelyChanged;
9880
+ }
9813
9881
  }
9814
9882
  ngOnInit() {
9815
9883
  const defaultTrack = this.evaVideoTracks().find((t) => t.default && t.kind === "subtitles");
@@ -9835,6 +9903,23 @@ class EvaPlayer {
9835
9903
  }
9836
9904
  });
9837
9905
  }
9906
+ /**
9907
+ * Performs the video reload flagged by `ngOnChanges`, once the view (and so the
9908
+ * `<source>` elements' updated `src`/`type` attributes) has actually been refreshed.
9909
+ *
9910
+ * Calls `EvaApi.prepareForSourceChange()` first — `.load()` silently resets the video
9911
+ * element to paused without firing a `pause` event, so without this, `EvaApi`'s playback
9912
+ * state (e.g. `videoStateSubject`) would keep reporting whatever it was before the switch
9913
+ * (e.g. `PLAYING`) indefinitely, since nothing would ever correct it if the new source
9914
+ * fails to load. See `EvaApi.prepareForSourceChange()`.
9915
+ */
9916
+ ngAfterViewChecked() {
9917
+ if (this.pendingVideoSourcesReload) {
9918
+ this.pendingVideoSourcesReload = false;
9919
+ this.playerMainAPI.prepareForSourceChange();
9920
+ this.evaVideoElement().nativeElement.load();
9921
+ }
9922
+ }
9838
9923
  ngOnDestroy() {
9839
9924
  this.subtitleChangeSubject?.unsubscribe();
9840
9925
  this.playerFullscreenAPI.destroy();