hls.js 1.6.0-beta.1.0.canary.10809 → 1.6.0-beta.1.0.canary.10810

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.
@@ -11,6 +11,7 @@ import { PlaylistContextType, PlaylistLevelType } from '../types/loader';
11
11
  import { ChunkMetadata } from '../types/transmuxer';
12
12
  import { BufferHelper } from '../utils/buffer-helper';
13
13
  import { pickMostCompleteCodecName } from '../utils/codecs';
14
+ import { useAlternateAudio } from '../utils/rendition-helper';
14
15
  import type { FragmentTracker } from './fragment-tracker';
15
16
  import type Hls from '../hls';
16
17
  import type { Fragment, MediaFragment } from '../loader/fragment';
@@ -851,9 +852,10 @@ export default class StreamController
851
852
  event: Events.AUDIO_TRACK_SWITCHING,
852
853
  data: AudioTrackSwitchingData,
853
854
  ) {
855
+ const hls = this.hls;
854
856
  // if any URL found on new audio track, it is an alternate audio track
855
857
  const fromAltAudio = this.altAudio === AlternateAudio.SWITCHED;
856
- const altAudio = !!data.url;
858
+ const altAudio = useAlternateAudio(data.url, hls);
857
859
  // if we switch on main audio, ensure that main fragment scheduling is synced with media.buffered
858
860
  // don't do anything if we switch to alt audio: audio stream controller is handling it.
859
861
  // we will just have to change buffer scheduling on audioTrackSwitched
@@ -878,7 +880,6 @@ export default class StreamController
878
880
  // Reset audio transmuxer so when switching back to main audio we're not still appending where we left off
879
881
  this.resetTransmuxer();
880
882
  }
881
- const hls = this.hls;
882
883
  // If switching from alt to main audio, flush all audio and trigger track switched
883
884
  if (fromAltAudio) {
884
885
  hls.trigger(Events.BUFFER_FLUSHING, {
@@ -898,8 +899,7 @@ export default class StreamController
898
899
  event: Events.AUDIO_TRACK_SWITCHED,
899
900
  data: AudioTrackSwitchedData,
900
901
  ) {
901
- const trackId = data.id;
902
- const altAudio = !!this.hls.audioTracks[trackId].url;
902
+ const altAudio = useAlternateAudio(data.url, this.hls);
903
903
  if (altAudio) {
904
904
  const videoBuffer = this.videoBuffer;
905
905
  // if we switched on alternate audio, ensure that main fragment scheduling is synced with video sourcebuffer buffered
@@ -1,6 +1,7 @@
1
1
  import { codecsSetSelectionPreferenceValue } from './codecs';
2
2
  import { getVideoSelectionOptions } from './hdr';
3
3
  import { logger } from './logger';
4
+ import type Hls from '../hls';
4
5
  import type { Level, VideoRange } from '../types/level';
5
6
  import type {
6
7
  AudioSelectionOption,
@@ -500,3 +501,7 @@ function searchDownAndUpList(
500
501
  }
501
502
  return -1;
502
503
  }
504
+
505
+ export function useAlternateAudio(audioTrackUrl: string, hls: Hls): boolean {
506
+ return !!audioTrackUrl && audioTrackUrl !== hls.levels[hls.loadLevel]?.uri;
507
+ }