From 7acc0ee798d4e5fb1bc97a179d47fa232f166680 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Mon, 11 Mar 2019 22:50:35 +0000 Subject: [PATCH] Fix ProgressiveMediaSource DefaultExtractorsFactory proguarding PiperOrigin-RevId: 237900673 --- RELEASENOTES.md | 5 ++++ .../exoplayer2/ext/flac/FlacPlaybackTest.java | 4 ++-- .../exoplayer2/ext/opus/OpusPlaybackTest.java | 4 ++-- .../exoplayer2/ext/vp9/VpxPlaybackTest.java | 4 ++-- .../source/ProgressiveMediaSource.java | 23 +++++++++++++++---- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 3126b32473..0394f8d83d 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -70,6 +70,11 @@ * Update `DefaultTimeBar` based on duration of media and add parameter to set the minimum update interval to control the smoothness of the updates ([#5040](https://github.com/google/ExoPlayer/issues/5040)). +* Fix issue where using `ProgressiveMediaSource.Factory` would mean that + `DefaultExtractorsFactory` would be kept by proguard. Custom + `ExtractorsFactory` instances must now be passed via the + `ProgressiveMediaSource.Factory` constructor, and `setExtractorsFactory` is + deprecated. ### 2.9.6 ### diff --git a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacPlaybackTest.java b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacPlaybackTest.java index 5448919626..5904a8eb2b 100644 --- a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacPlaybackTest.java +++ b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacPlaybackTest.java @@ -87,8 +87,8 @@ public class FlacPlaybackTest { player.addListener(this); MediaSource mediaSource = new ProgressiveMediaSource.Factory( - new DefaultDataSourceFactory(context, "ExoPlayerExtFlacTest")) - .setExtractorsFactory(MatroskaExtractor.FACTORY) + new DefaultDataSourceFactory(context, "ExoPlayerExtFlacTest"), + MatroskaExtractor.FACTORY) .createMediaSource(uri); player.prepare(mediaSource); player.setPlayWhenReady(true); diff --git a/extensions/opus/src/androidTest/java/com/google/android/exoplayer2/ext/opus/OpusPlaybackTest.java b/extensions/opus/src/androidTest/java/com/google/android/exoplayer2/ext/opus/OpusPlaybackTest.java index 6a254c8230..536f605293 100644 --- a/extensions/opus/src/androidTest/java/com/google/android/exoplayer2/ext/opus/OpusPlaybackTest.java +++ b/extensions/opus/src/androidTest/java/com/google/android/exoplayer2/ext/opus/OpusPlaybackTest.java @@ -87,8 +87,8 @@ public class OpusPlaybackTest { player.addListener(this); MediaSource mediaSource = new ProgressiveMediaSource.Factory( - new DefaultDataSourceFactory(context, "ExoPlayerExtOpusTest")) - .setExtractorsFactory(MatroskaExtractor.FACTORY) + new DefaultDataSourceFactory(context, "ExoPlayerExtOpusTest"), + MatroskaExtractor.FACTORY) .createMediaSource(uri); player.prepare(mediaSource); player.setPlayWhenReady(true); diff --git a/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java b/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java index a36b578588..e835810778 100644 --- a/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java +++ b/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java @@ -120,8 +120,8 @@ public class VpxPlaybackTest { player.addListener(this); MediaSource mediaSource = new ProgressiveMediaSource.Factory( - new DefaultDataSourceFactory(context, "ExoPlayerExtVp9Test")) - .setExtractorsFactory(MatroskaExtractor.FACTORY) + new DefaultDataSourceFactory(context, "ExoPlayerExtVp9Test"), + MatroskaExtractor.FACTORY) .createMediaSource(uri); player .createMessage(videoRenderer) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/ProgressiveMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/ProgressiveMediaSource.java index 4130ce3e98..f448b0b6c8 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/ProgressiveMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/ProgressiveMediaSource.java @@ -49,7 +49,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource private final DataSource.Factory dataSourceFactory; - @Nullable private ExtractorsFactory extractorsFactory; + private ExtractorsFactory extractorsFactory; @Nullable private String customCacheKey; @Nullable private Object tag; private LoadErrorHandlingPolicy loadErrorHandlingPolicy; @@ -57,12 +57,24 @@ public final class ProgressiveMediaSource extends BaseMediaSource private boolean isCreateCalled; /** - * Creates a new factory for {@link ProgressiveMediaSource}s. + * Creates a new factory for {@link ProgressiveMediaSource}s, using the extractors provided by + * {@link DefaultExtractorsFactory}. * * @param dataSourceFactory A factory for {@link DataSource}s to read the media. */ public Factory(DataSource.Factory dataSourceFactory) { + this(dataSourceFactory, new DefaultExtractorsFactory()); + } + + /** + * Creates a new factory for {@link ProgressiveMediaSource}s. + * + * @param dataSourceFactory A factory for {@link DataSource}s to read the media. + * @param extractorsFactory A factory for extractors used to extract media from its container. + */ + public Factory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) { this.dataSourceFactory = dataSourceFactory; + this.extractorsFactory = extractorsFactory; loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy(); continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES; } @@ -76,7 +88,11 @@ public final class ProgressiveMediaSource extends BaseMediaSource * formats. * @return This factory, for convenience. * @throws IllegalStateException If one of the {@code create} methods has already been called. + * @deprecated Pass the {@link ExtractorsFactory} via {@link #Factory(DataSource.Factory, + * ExtractorsFactory)}. This is necessary so that proguard can treat the default extractors + * factory as unused. */ + @Deprecated public Factory setExtractorsFactory(ExtractorsFactory extractorsFactory) { Assertions.checkState(!isCreateCalled); this.extractorsFactory = extractorsFactory; @@ -153,9 +169,6 @@ public final class ProgressiveMediaSource extends BaseMediaSource @Override public ProgressiveMediaSource createMediaSource(Uri uri) { isCreateCalled = true; - if (extractorsFactory == null) { - extractorsFactory = new DefaultExtractorsFactory(); - } return new ProgressiveMediaSource( uri, dataSourceFactory,