hls.js 1.5.7-0.canary.10021 → 1.5.7-0.canary.10023

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/hls.mjs CHANGED
@@ -512,7 +512,7 @@ function enableLogs(debugConfig, context, id) {
512
512
  // Some browsers don't allow to use bind on console object anyway
513
513
  // fallback to default if needed
514
514
  try {
515
- newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.5.7-0.canary.10021"}`);
515
+ newLogger.log(`Debug logs enabled for "${context}" in hls.js version ${"1.5.7-0.canary.10023"}`);
516
516
  } catch (e) {
517
517
  /* log fn threw an exception. All logger methods are no-ops. */
518
518
  return createLogger();
@@ -8064,40 +8064,29 @@ class BufferHelper {
8064
8064
  * Return true if `media`'s buffered include `position`
8065
8065
  */
8066
8066
  static isBuffered(media, position) {
8067
- try {
8068
- if (media) {
8069
- const buffered = BufferHelper.getBuffered(media);
8070
- for (let i = 0; i < buffered.length; i++) {
8071
- if (position >= buffered.start(i) && position <= buffered.end(i)) {
8072
- return true;
8073
- }
8067
+ if (media) {
8068
+ const buffered = BufferHelper.getBuffered(media);
8069
+ for (let i = buffered.length; i--;) {
8070
+ if (position >= buffered.start(i) && position <= buffered.end(i)) {
8071
+ return true;
8074
8072
  }
8075
8073
  }
8076
- } catch (error) {
8077
- // this is to catch
8078
- // InvalidStateError: Failed to read the 'buffered' property from 'SourceBuffer':
8079
- // This SourceBuffer has been removed from the parent media source
8080
8074
  }
8081
8075
  return false;
8082
8076
  }
8083
8077
  static bufferInfo(media, pos, maxHoleDuration) {
8084
- try {
8085
- if (media) {
8086
- const vbuffered = BufferHelper.getBuffered(media);
8078
+ if (media) {
8079
+ const vbuffered = BufferHelper.getBuffered(media);
8080
+ if (vbuffered.length) {
8087
8081
  const buffered = [];
8088
- let i;
8089
- for (i = 0; i < vbuffered.length; i++) {
8082
+ for (let i = 0; i < vbuffered.length; i++) {
8090
8083
  buffered.push({
8091
8084
  start: vbuffered.start(i),
8092
8085
  end: vbuffered.end(i)
8093
8086
  });
8094
8087
  }
8095
- return this.bufferedInfo(buffered, pos, maxHoleDuration);
8088
+ return BufferHelper.bufferedInfo(buffered, pos, maxHoleDuration);
8096
8089
  }
8097
- } catch (error) {
8098
- // this is to catch
8099
- // InvalidStateError: Failed to read the 'buffered' property from 'SourceBuffer':
8100
- // This SourceBuffer has been removed from the parent media source
8101
8090
  }
8102
8091
  return {
8103
8092
  len: 0,
@@ -8109,14 +8098,7 @@ class BufferHelper {
8109
8098
  static bufferedInfo(buffered, pos, maxHoleDuration) {
8110
8099
  pos = Math.max(0, pos);
8111
8100
  // sort on buffer.start/smaller end (IE does not always return sorted buffered range)
8112
- buffered.sort(function (a, b) {
8113
- const diff = a.start - b.start;
8114
- if (diff) {
8115
- return diff;
8116
- } else {
8117
- return b.end - a.end;
8118
- }
8119
- });
8101
+ buffered.sort((a, b) => a.start - b.start || b.end - a.end);
8120
8102
  let buffered2 = [];
8121
8103
  if (maxHoleDuration) {
8122
8104
  // there might be some small holes between buffer time range
@@ -8183,7 +8165,7 @@ class BufferHelper {
8183
8165
  */
8184
8166
  static getBuffered(media) {
8185
8167
  try {
8186
- return media.buffered;
8168
+ return media.buffered || noopBuffered;
8187
8169
  } catch (e) {
8188
8170
  logger.log('failed to get media.buffered', e);
8189
8171
  return noopBuffered;
@@ -10399,7 +10381,9 @@ class BaseStreamController extends TaskLoop {
10399
10381
  this.log('Reset loading state');
10400
10382
  this.fragCurrent = null;
10401
10383
  this.fragPrevious = null;
10402
- this.state = State.IDLE;
10384
+ if (this.state !== State.STOPPED) {
10385
+ this.state = State.IDLE;
10386
+ }
10403
10387
  }
10404
10388
  resetStartWhenNotLoaded(level) {
10405
10389
  // if loadedmetadata is not set, it means that first frag request failed
@@ -16736,7 +16720,9 @@ class AudioStreamController extends BaseStreamController {
16736
16720
  this.fragmentTracker.removeFragment(waitingData.frag);
16737
16721
  this.waitingData = null;
16738
16722
  this.waitingVideoCC = -1;
16739
- this.state = State.IDLE;
16723
+ if (this.state !== State.STOPPED) {
16724
+ this.state = State.IDLE;
16725
+ }
16740
16726
  }
16741
16727
  }
16742
16728
  resetLoadingState() {
@@ -16876,26 +16862,25 @@ class AudioStreamController extends BaseStreamController {
16876
16862
  this.removeUnbufferedFrags(fragCurrent.start);
16877
16863
  }
16878
16864
  this.resetLoadingState();
16879
- // destroy useless transmuxer when switching audio to main
16880
- if (!altAudio) {
16881
- this.resetTransmuxer();
16882
- } else {
16883
- // switching to audio track, start timer if not already started
16884
- this.setInterval(TICK_INTERVAL$2);
16885
- }
16886
16865
 
16887
16866
  // should we switch tracks ?
16888
16867
  if (altAudio) {
16889
16868
  this.switchingTrack = data;
16890
16869
  // main audio track are handled by stream-controller, just do something if switching to alt audio track
16891
- this.state = State.IDLE;
16892
16870
  this.flushAudioIfNeeded(data);
16871
+ if (this.state !== State.STOPPED) {
16872
+ // switching to audio track, start timer if not already started
16873
+ this.setInterval(TICK_INTERVAL$2);
16874
+ this.state = State.IDLE;
16875
+ this.tick();
16876
+ }
16893
16877
  } else {
16878
+ // destroy useless transmuxer when switching audio to main
16879
+ this.resetTransmuxer();
16894
16880
  this.switchingTrack = null;
16895
16881
  this.bufferedTrack = data;
16896
- this.state = State.STOPPED;
16882
+ this.clearInterval();
16897
16883
  }
16898
- this.tick();
16899
16884
  }
16900
16885
  onManifestLoading() {
16901
16886
  this.fragmentTracker.removeAllFragments();
@@ -17812,7 +17797,7 @@ class SubtitleStreamController extends BaseStreamController {
17812
17797
  } else {
17813
17798
  this.mediaBuffer = null;
17814
17799
  }
17815
- if (currentTrack) {
17800
+ if (currentTrack && this.state !== State.STOPPED) {
17816
17801
  this.setInterval(TICK_INTERVAL$1);
17817
17802
  }
17818
17803
  }
@@ -28713,7 +28698,7 @@ class Hls {
28713
28698
  * Get the video-dev/hls.js package version.
28714
28699
  */
28715
28700
  static get version() {
28716
- return "1.5.7-0.canary.10021";
28701
+ return "1.5.7-0.canary.10023";
28717
28702
  }
28718
28703
 
28719
28704
  /**