mirror of
https://github.com/androidx/media.git
synced 2025-05-04 14:10:40 +08:00
Tweak recently merged pull requests
This commit is contained in:
parent
1c594b4cdb
commit
feceabadeb
@ -16,23 +16,19 @@
|
||||
package com.google.android.exoplayer2.source.hls.playlist;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.ParserException;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test for {@link HlsMasterPlaylistParserTest}
|
||||
* Test for {@link HlsMasterPlaylistParserTest}.
|
||||
*/
|
||||
public class HlsMasterPlaylistParserTest extends TestCase {
|
||||
|
||||
@ -148,44 +144,6 @@ public class HlsMasterPlaylistParserTest extends TestCase {
|
||||
assertEquals(Collections.emptyList(), playlist.muxedCaptionFormats);
|
||||
}
|
||||
|
||||
public void testReorderedVariantCopy() throws IOException {
|
||||
HlsMasterPlaylist playlist = parseMasterPlaylist(PLAYLIST_URI, MASTER_PLAYLIST);
|
||||
HlsMasterPlaylist nonReorderedPlaylist =
|
||||
playlist.copyWithReorderedVariants(new Comparator<HlsMasterPlaylist.HlsUrl>() {
|
||||
@Override
|
||||
public int compare(HlsMasterPlaylist.HlsUrl url1, HlsMasterPlaylist.HlsUrl url2) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
assertEquals(playlist.variants, nonReorderedPlaylist.variants);
|
||||
HlsMasterPlaylist.HlsUrl preferred = null;
|
||||
for (HlsMasterPlaylist.HlsUrl url : playlist.variants) {
|
||||
if (preferred == null || url.format.bitrate > preferred.format.bitrate) {
|
||||
preferred = url;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(preferred);
|
||||
|
||||
final Comparator comparator = Collections.reverseOrder(new Comparator<HlsMasterPlaylist.HlsUrl>() {
|
||||
@Override
|
||||
public int compare(HlsMasterPlaylist.HlsUrl url1, HlsMasterPlaylist.HlsUrl url2) {
|
||||
if (url1.format.bitrate > url2.format.bitrate) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (url2.format.bitrate > url1.format.bitrate) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
HlsMasterPlaylist reorderedPlaylist = playlist.copyWithReorderedVariants(comparator);
|
||||
|
||||
assertEquals(reorderedPlaylist.variants.get(0), preferred);
|
||||
}
|
||||
|
||||
private static HlsMasterPlaylist parseMasterPlaylist(String uri, String playlistString)
|
||||
throws IOException {
|
||||
Uri playlistUri = Uri.parse(uri);
|
||||
|
@ -27,7 +27,7 @@ import java.util.Locale;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test for {@link HlsMediaPlaylistParserTest}
|
||||
* Test for {@link HlsMediaPlaylistParserTest}.
|
||||
*/
|
||||
public class HlsMediaPlaylistParserTest extends TestCase {
|
||||
|
||||
|
@ -76,13 +76,14 @@ public final class HlsMediaSource implements MediaSource,
|
||||
public HlsMediaSource(Uri manifestUri, HlsDataSourceFactory dataSourceFactory,
|
||||
int minLoadableRetryCount, Handler eventHandler,
|
||||
AdaptiveMediaSourceEventListener eventListener) {
|
||||
this(manifestUri, dataSourceFactory, minLoadableRetryCount, eventHandler, eventListener, new HlsPlaylistParser());
|
||||
this(manifestUri, dataSourceFactory, minLoadableRetryCount, eventHandler, eventListener,
|
||||
new HlsPlaylistParser());
|
||||
}
|
||||
|
||||
public HlsMediaSource(Uri manifestUri, HlsDataSourceFactory dataSourceFactory,
|
||||
int minLoadableRetryCount, Handler eventHandler,
|
||||
AdaptiveMediaSourceEventListener eventListener,
|
||||
ParsingLoadable.Parser<HlsPlaylist> playlistParser) {
|
||||
int minLoadableRetryCount, Handler eventHandler,
|
||||
AdaptiveMediaSourceEventListener eventListener,
|
||||
ParsingLoadable.Parser<HlsPlaylist> playlistParser) {
|
||||
this.manifestUri = manifestUri;
|
||||
this.dataSourceFactory = dataSourceFactory;
|
||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
||||
|
@ -19,7 +19,6 @@ import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -124,25 +123,6 @@ public final class HlsMasterPlaylist extends HlsPlaylist {
|
||||
muxedAudioFormat, muxedCaptionFormats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of this playlist which includes the variants sorted using the passed comparator. NOTE: the variants
|
||||
* will be sorted in ascending order by default. If you wish to use descending order, you can wrap your comparator in
|
||||
* {@link Collections#reverseOrder(Comparator)}.
|
||||
*
|
||||
* @param variantComparator the comparator to use to sort the variant list.
|
||||
* @return a copy of this playlist which includes the variants sorted using the passed comparator.
|
||||
*/
|
||||
public HlsMasterPlaylist copyWithReorderedVariants(Comparator<HlsUrl> variantComparator) {
|
||||
return new HlsMasterPlaylist(baseUri, tags, filterVariants(variants, variantComparator), audios,
|
||||
subtitles, muxedAudioFormat, muxedCaptionFormats);
|
||||
}
|
||||
|
||||
private List<HlsUrl> filterVariants(List<HlsUrl> variants, Comparator<HlsUrl> variantComparator) {
|
||||
List<HlsUrl> reorderedList = new ArrayList<>(variants);
|
||||
Collections.sort(reorderedList, variantComparator);
|
||||
return reorderedList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a playlist with a single variant.
|
||||
*
|
||||
|
@ -145,15 +145,16 @@ public final class HlsPlaylistTracker implements Loader.Callback<ParsingLoadable
|
||||
*/
|
||||
public HlsPlaylistTracker(Uri initialPlaylistUri, HlsDataSourceFactory dataSourceFactory,
|
||||
EventDispatcher eventDispatcher, int minRetryCount,
|
||||
PrimaryPlaylistListener primaryPlaylistListener, ParsingLoadable.Parser<HlsPlaylist> playlistParser) {
|
||||
PrimaryPlaylistListener primaryPlaylistListener,
|
||||
ParsingLoadable.Parser<HlsPlaylist> playlistParser) {
|
||||
this.initialPlaylistUri = initialPlaylistUri;
|
||||
this.dataSourceFactory = dataSourceFactory;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.minRetryCount = minRetryCount;
|
||||
this.primaryPlaylistListener = primaryPlaylistListener;
|
||||
this.playlistParser = playlistParser;
|
||||
listeners = new ArrayList<>();
|
||||
initialPlaylistLoader = new Loader("HlsPlaylistTracker:MasterPlaylist");
|
||||
this.playlistParser = playlistParser;
|
||||
playlistBundles = new IdentityHashMap<>();
|
||||
playlistRefreshHandler = new Handler();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user