Add URLs EXT-X-STREAM-INF uris only once

This prevents ExoPlayer from thinking there are many more video tracks
than there actually are. And will prevent downloading multiple times
the same rendition once offline support for HLS is added.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160285777
This commit is contained in:
aquilescanta 2017-06-27 09:38:31 -07:00 committed by Oliver Woodman
parent 6c24d93805
commit efd17f86c5

View File

@ -30,6 +30,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
@ -174,6 +175,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
private static HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, String baseUri) private static HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, String baseUri)
throws IOException { throws IOException {
HashSet<String> variantUrls = new HashSet<>();
ArrayList<HlsMasterPlaylist.HlsUrl> variants = new ArrayList<>(); ArrayList<HlsMasterPlaylist.HlsUrl> variants = new ArrayList<>();
ArrayList<HlsMasterPlaylist.HlsUrl> audios = new ArrayList<>(); ArrayList<HlsMasterPlaylist.HlsUrl> audios = new ArrayList<>();
ArrayList<HlsMasterPlaylist.HlsUrl> subtitles = new ArrayList<>(); ArrayList<HlsMasterPlaylist.HlsUrl> subtitles = new ArrayList<>();
@ -251,11 +253,13 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
width = Format.NO_VALUE; width = Format.NO_VALUE;
height = Format.NO_VALUE; height = Format.NO_VALUE;
} }
line = iterator.next(); line = iterator.next(); // #EXT-X-STREAM-INF's URI.
Format format = Format.createVideoContainerFormat(Integer.toString(variants.size()), if (variantUrls.add(line)) {
MimeTypes.APPLICATION_M3U8, null, codecs, bitrate, width, height, Format.NO_VALUE, null, Format format = Format.createVideoContainerFormat(Integer.toString(variants.size()),
0); MimeTypes.APPLICATION_M3U8, null, codecs, bitrate, width, height, Format.NO_VALUE,
variants.add(new HlsMasterPlaylist.HlsUrl(line, format)); null, 0);
variants.add(new HlsMasterPlaylist.HlsUrl(line, format));
}
} }
} }
if (noClosedCaptions) { if (noClosedCaptions) {