Skip to content

Commit

Permalink
fix: Don't forget active track after new period is added to live stream.
Browse files Browse the repository at this point in the history
The algorithm in shaka.Player.getVariantTracks assumed that the variants in the
manifest would never change, and thus used object equality to see if a track
should be marked as active or not.
However, the (relatively) new Shaka Player period combiner system now
causes all of the variants to be re-built whenever the manifest was updated.
This change makes shaka.Player.getVariantTracks continue to recognize
the previously active variant, even if it is not literally equal to the old one.

Closes: shaka-project#3510
  • Loading branch information
Álvaro Velad Galván committed Oct 12, 2021
1 parent 5783694 commit 22307d0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/player.js
Expand Up @@ -3402,6 +3402,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

const tracks = [];

let activeTracks = 0;

// Convert each variant to a track.
for (const variant of this.manifest_.variants) {
if (!shaka.util.StreamUtils.isPlayable(variant)) {
Expand All @@ -3410,10 +3412,22 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

const track = shaka.util.StreamUtils.variantToTrack(variant);
track.active = variant == currentVariant;
if (!track.active && activeTracks != 1 && currentVariant != null &&
variant.video == currentVariant.video &&
variant.audio == currentVariant.audio) {
track.active = true;
}

if (track.active) {
activeTracks++;
}

tracks.push(track);
}

goog.asserts.assert(activeTracks <= 1,
'It should only have one active track');

return tracks;
} else if (this.video_ && this.video_.audioTracks) {
// Safari's native HLS always shows a single element in videoTracks.
Expand Down

0 comments on commit 22307d0

Please sign in to comment.