hls.js 1.6.0-beta.1.0.canary.10758 → 1.6.0-beta.1.0.canary.10761

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.
@@ -44,6 +44,12 @@ import type { BufferInfo } from '../utils/buffer-helper';
44
44
 
45
45
  const TICK_INTERVAL = 100; // how often to tick in ms
46
46
 
47
+ const enum AlternateAudio {
48
+ DISABLED = 0,
49
+ SWITCHING,
50
+ SWITCHED,
51
+ }
52
+
47
53
  export default class StreamController
48
54
  extends BaseStreamController
49
55
  implements NetworkComponentAPI
@@ -53,7 +59,7 @@ export default class StreamController
53
59
  private level: number = -1;
54
60
  private _forceStartLoad: boolean = false;
55
61
  private _hasEnoughToStart: boolean = false;
56
- private altAudio: boolean = false;
62
+ private altAudio: AlternateAudio = AlternateAudio.DISABLED;
57
63
  private audioOnly: boolean = false;
58
64
  private fragPlaying: Fragment | null = null;
59
65
  private fragLastKbps: number = 0;
@@ -256,7 +262,7 @@ export default class StreamController
256
262
  const lastDetails = this.getLevelDetails();
257
263
  if (lastDetails && this._streamEnded(bufferInfo, lastDetails)) {
258
264
  const data: BufferEOSData = {};
259
- if (this.altAudio) {
265
+ if (this.altAudio === AlternateAudio.SWITCHED) {
260
266
  data.type = 'video';
261
267
  }
262
268
 
@@ -509,7 +515,7 @@ export default class StreamController
509
515
  super.flushMainBuffer(
510
516
  startOffset,
511
517
  endOffset,
512
- this.altAudio ? 'video' : null,
518
+ this.altAudio === AlternateAudio.SWITCHED ? 'video' : null,
513
519
  );
514
520
  }
515
521
 
@@ -606,7 +612,8 @@ export default class StreamController
606
612
  this.couldBacktrack = false;
607
613
  this.fragLastKbps = 0;
608
614
  this.fragPlaying = this.backtrackFragment = null;
609
- this.altAudio = this.audioOnly = false;
615
+ this.altAudio = AlternateAudio.DISABLED;
616
+ this.audioOnly = false;
610
617
  }
611
618
 
612
619
  private onManifestParsed(
@@ -837,7 +844,7 @@ export default class StreamController
837
844
  data: AudioTrackSwitchingData,
838
845
  ) {
839
846
  // if any URL found on new audio track, it is an alternate audio track
840
- const fromAltAudio = this.altAudio;
847
+ const fromAltAudio = this.altAudio === AlternateAudio.SWITCHED;
841
848
  const altAudio = !!data.url;
842
849
  // if we switch on main audio, ensure that main fragment scheduling is synced with media.buffered
843
850
  // don't do anything if we switch to alt audio: audio stream controller is handling it.
@@ -874,6 +881,8 @@ export default class StreamController
874
881
  this.fragmentTracker.removeAllFragments();
875
882
  }
876
883
  hls.trigger(Events.AUDIO_TRACK_SWITCHED, data);
884
+ } else {
885
+ this.altAudio = AlternateAudio.SWITCHING;
877
886
  }
878
887
  }
879
888
 
@@ -893,7 +902,9 @@ export default class StreamController
893
902
  this.mediaBuffer = videoBuffer;
894
903
  }
895
904
  }
896
- this.altAudio = altAudio;
905
+ this.altAudio = altAudio
906
+ ? AlternateAudio.SWITCHED
907
+ : AlternateAudio.DISABLED;
897
908
  this.tick();
898
909
  }
899
910