From 72e1eae6f55580ecae06f649078d051e7f6f1f0f Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Mon, 20 Feb 2017 08:45:13 -0800 Subject: [PATCH] Discard preparation chunk if track selection does not include it This avoids breaking the player if the first variant is not supported by the device. Issue:#2353 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=148025791 --- .../exoplayer2/source/hls/HlsSampleStreamWrapper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java index 538acbeabf..6980fdd7a4 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsSampleStreamWrapper.java @@ -182,6 +182,7 @@ import java.util.LinkedList; } } // Enable new tracks. + TrackSelection primaryTrackSelection = null; boolean selectedNewTracks = false; for (int i = 0; i < selections.length; i++) { if (streams[i] == null && selections[i] != null) { @@ -189,6 +190,7 @@ import java.util.LinkedList; int group = trackGroups.indexOf(selection.getTrackGroup()); setTrackGroupEnabledState(group, true); if (group == primaryTrackGroupIndex) { + primaryTrackSelection = selection; chunkSource.selectTracks(selection); } streams[i] = new HlsSampleStream(this, group); @@ -205,6 +207,14 @@ import java.util.LinkedList; sampleQueues.valueAt(i).disable(); } } + if (primaryTrackSelection != null && !mediaChunks.isEmpty()) { + primaryTrackSelection.updateSelectedTrack(0); + int chunkIndex = chunkSource.getTrackGroup().indexOf(mediaChunks.getLast().trackFormat); + if (primaryTrackSelection.getSelectedIndexInTrackGroup() != chunkIndex) { + // The loaded preparation chunk does match the selection. We discard it. + seekTo(lastSeekPositionUs); + } + } } // Cancel requests if necessary. if (enabledTrackCount == 0) {