From bcc69c2da7afc8a8463b9ec11fab78af2305564a Mon Sep 17 00:00:00 2001 From: eguven Date: Wed, 26 Jul 2017 08:58:02 -0700 Subject: [PATCH] Add HlsMasterPlaylist.copy method Creates a copy of this playlist which includes only the variants identified by the given variantUrls. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=163212562 --- .../hls/playlist/HlsMasterPlaylist.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMasterPlaylist.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMasterPlaylist.java index b38763f7e8..0b237e75e7 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMasterPlaylist.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMasterPlaylist.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.hls.playlist; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.util.MimeTypes; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -108,6 +109,20 @@ public final class HlsMasterPlaylist extends HlsPlaylist { ? Collections.unmodifiableList(muxedCaptionFormats) : null; } + /** + * Returns a copy of this playlist which includes only the renditions identified by the given + * urls. + * + * @param renditionUrls List of rendition urls. + * @return A copy of this playlist which includes only the renditions identified by the given + * urls. + */ + public HlsMasterPlaylist copy(List renditionUrls) { + return new HlsMasterPlaylist(baseUri, tags, copyRenditionList(variants, renditionUrls), + copyRenditionList(audios, renditionUrls), copyRenditionList(subtitles, renditionUrls), + muxedAudioFormat, muxedCaptionFormats); + } + /** * Creates a playlist with a single variant. * @@ -121,4 +136,15 @@ public final class HlsMasterPlaylist extends HlsPlaylist { emptyList, null, null); } + private static List copyRenditionList(List variants, List variantUrls) { + List copyVariants = new ArrayList<>(); + for (int i = 0; i < variants.size(); i++) { + HlsUrl variant = variants.get(i); + if (variantUrls.contains(variant.url)) { + copyVariants.add(variant); + } + } + return copyVariants; + } + }