Fix ProgressiveMediaSource DefaultExtractorsFactory proguarding

PiperOrigin-RevId: 237900673
This commit is contained in:
andrewlewis 2019-03-11 22:50:35 +00:00 committed by Oliver Woodman
parent 7bf963c06c
commit 7acc0ee798
5 changed files with 29 additions and 11 deletions

View File

@ -70,6 +70,11 @@
* Update `DefaultTimeBar` based on duration of media and add parameter to set * Update `DefaultTimeBar` based on duration of media and add parameter to set
the minimum update interval to control the smoothness of the updates the minimum update interval to control the smoothness of the updates
([#5040](https://github.com/google/ExoPlayer/issues/5040)). ([#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 ### ### 2.9.6 ###

View File

@ -87,8 +87,8 @@ public class FlacPlaybackTest {
player.addListener(this); player.addListener(this);
MediaSource mediaSource = MediaSource mediaSource =
new ProgressiveMediaSource.Factory( new ProgressiveMediaSource.Factory(
new DefaultDataSourceFactory(context, "ExoPlayerExtFlacTest")) new DefaultDataSourceFactory(context, "ExoPlayerExtFlacTest"),
.setExtractorsFactory(MatroskaExtractor.FACTORY) MatroskaExtractor.FACTORY)
.createMediaSource(uri); .createMediaSource(uri);
player.prepare(mediaSource); player.prepare(mediaSource);
player.setPlayWhenReady(true); player.setPlayWhenReady(true);

View File

@ -87,8 +87,8 @@ public class OpusPlaybackTest {
player.addListener(this); player.addListener(this);
MediaSource mediaSource = MediaSource mediaSource =
new ProgressiveMediaSource.Factory( new ProgressiveMediaSource.Factory(
new DefaultDataSourceFactory(context, "ExoPlayerExtOpusTest")) new DefaultDataSourceFactory(context, "ExoPlayerExtOpusTest"),
.setExtractorsFactory(MatroskaExtractor.FACTORY) MatroskaExtractor.FACTORY)
.createMediaSource(uri); .createMediaSource(uri);
player.prepare(mediaSource); player.prepare(mediaSource);
player.setPlayWhenReady(true); player.setPlayWhenReady(true);

View File

@ -120,8 +120,8 @@ public class VpxPlaybackTest {
player.addListener(this); player.addListener(this);
MediaSource mediaSource = MediaSource mediaSource =
new ProgressiveMediaSource.Factory( new ProgressiveMediaSource.Factory(
new DefaultDataSourceFactory(context, "ExoPlayerExtVp9Test")) new DefaultDataSourceFactory(context, "ExoPlayerExtVp9Test"),
.setExtractorsFactory(MatroskaExtractor.FACTORY) MatroskaExtractor.FACTORY)
.createMediaSource(uri); .createMediaSource(uri);
player player
.createMessage(videoRenderer) .createMessage(videoRenderer)

View File

@ -49,7 +49,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
private final DataSource.Factory dataSourceFactory; private final DataSource.Factory dataSourceFactory;
@Nullable private ExtractorsFactory extractorsFactory; private ExtractorsFactory extractorsFactory;
@Nullable private String customCacheKey; @Nullable private String customCacheKey;
@Nullable private Object tag; @Nullable private Object tag;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy; private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
@ -57,12 +57,24 @@ public final class ProgressiveMediaSource extends BaseMediaSource
private boolean isCreateCalled; 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. * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
*/ */
public Factory(DataSource.Factory dataSourceFactory) { 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.dataSourceFactory = dataSourceFactory;
this.extractorsFactory = extractorsFactory;
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy(); loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES; continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
} }
@ -76,7 +88,11 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* formats. * formats.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called. * @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) { public Factory setExtractorsFactory(ExtractorsFactory extractorsFactory) {
Assertions.checkState(!isCreateCalled); Assertions.checkState(!isCreateCalled);
this.extractorsFactory = extractorsFactory; this.extractorsFactory = extractorsFactory;
@ -153,9 +169,6 @@ public final class ProgressiveMediaSource extends BaseMediaSource
@Override @Override
public ProgressiveMediaSource createMediaSource(Uri uri) { public ProgressiveMediaSource createMediaSource(Uri uri) {
isCreateCalled = true; isCreateCalled = true;
if (extractorsFactory == null) {
extractorsFactory = new DefaultExtractorsFactory();
}
return new ProgressiveMediaSource( return new ProgressiveMediaSource(
uri, uri,
dataSourceFactory, dataSourceFactory,