@nomercy-entertainment/nomercy-video-player 2.9.3 → 2.10.0

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.
@@ -181,6 +181,8 @@ export interface IVideoBackend {
181
181
  setHdrOnSdrFallback?(fallback: HdrOnSdrFallback): void;
182
182
  /** How a live stream stays near the live edge. `NMVideoPlayer` pushes `options.liveSync` here before the first load; backends with no live catch-up omit it. */
183
183
  setLiveSync?(options: LiveSyncOptions): void;
184
+ /** Use hls.js over the element's native HLS when it is supported. `NMVideoPlayer` pushes `options.preferHlsJs` here before the first load; backends with one HLS path omit it. */
185
+ setPreferHlsJs?(prefer: boolean): void;
184
186
  /** Fetch the manifests and first `segments` segments of `url` into memory for the next `load(url)`. Optional; a repeat call for the same URL is a no-op. */
185
187
  warm?(url: string, opts?: {
186
188
  segments?: number;
@@ -145,6 +145,10 @@ export declare class Html5VideoBackend extends MediaElementBackend<HTMLVideoElem
145
145
  /** The speed the viewer chose; hls.js catch-up may move the element's own rate off it while live. */
146
146
  private _viewerRate;
147
147
  setLiveSync(options: LiveSyncOptions): void;
148
+ private _preferHlsJs;
149
+ setPreferHlsJs(prefer: boolean): void;
150
+ /** The element's own HLS, unless hls.js is preferred and MediaSource lets it run. */
151
+ private _useNativeHls;
148
152
  private _maxCatchUpRate;
149
153
  playbackRate(): number;
150
154
  playbackRate(rate: number): void;
@@ -205,7 +205,12 @@ export class Html5VideoBackend extends MediaElementBackend {
205
205
  }
206
206
  const hlsUrl = isHls(url);
207
207
  const warmed = this._warmCache.take(url);
208
- const nativeHls = supportsNativeHls(this.element);
208
+ let nativeHls = this._useNativeHls();
209
+ // Preferred hls.js that cannot run here leaves the element's own HLS in place.
210
+ if (hlsUrl && !nativeHls && supportsNativeHls(this.element)) {
211
+ const { default: Hls } = await import('hls.js');
212
+ nativeHls = !Hls?.isSupported?.();
213
+ }
209
214
  // Tear down any previous Hls instance BEFORE wiring a new source.
210
215
  // Without this, every load() leaks an Hls that keeps polling segment 0
211
216
  // against the same media element — symptom: thousands of identical
@@ -408,6 +413,17 @@ export class Html5VideoBackend extends MediaElementBackend {
408
413
  setLiveSync(options) {
409
414
  this._liveSync = options;
410
415
  }
416
+ _preferHlsJs = false;
417
+ setPreferHlsJs(prefer) {
418
+ this._preferHlsJs = prefer;
419
+ }
420
+ /** The element's own HLS, unless hls.js is preferred and MediaSource lets it run. */
421
+ _useNativeHls() {
422
+ if (!supportsNativeHls(this.element)) {
423
+ return false;
424
+ }
425
+ return !(this._preferHlsJs && typeof MediaSource !== 'undefined');
426
+ }
411
427
  _maxCatchUpRate() {
412
428
  return this._liveSync.maxCatchUpRate ?? DEFAULT_MAX_CATCH_UP_RATE;
413
429
  }
@@ -438,7 +454,7 @@ export class Html5VideoBackend extends MediaElementBackend {
438
454
  }
439
455
  _warmCache = new HlsWarmCache();
440
456
  async warm(url, opts) {
441
- if (!isHls(url) || supportsNativeHls(this.element))
457
+ if (!isHls(url) || this._useNativeHls())
442
458
  return;
443
459
  const playingHeight = this.hls?.levels[this.currentLevel()]?.height;
444
460
  await this._warmCache.warm(url, {
package/dist/index.js CHANGED
@@ -371,6 +371,7 @@ export class NMVideoPlayer extends EventEmitter {
371
371
  // point of use when this was never pushed at all.
372
372
  instance.setHdrOnSdrFallback?.(this.options?.hdrOnSdr ?? 'play');
373
373
  instance.setLiveSync?.(this.options?.liveSync ?? {});
374
+ instance.setPreferHlsJs?.(this.options?.preferHlsJs ?? false);
374
375
  // Mount the ResizeObserver that keeps videoRect() fresh. Done here so
375
376
  // the observer sees the real video element immediately after backend init.
376
377
  this._mountVideoRectObserver();