From ef14462db841ae9fd577df321217705c60986a6c Mon Sep 17 00:00:00 2001 From: Sascha Peilicke Date: Tue, 25 Sep 2018 20:19:57 +0200 Subject: [PATCH] Switch to OkHttpDataSource As requested in ExoPlayer issue 3735[0]. [0] https://github.com/google/ExoPlayer/issues/3735 --- exoplayer2-ext-icy/build.gradle | 1 + .../exoplayer2/ext/icy/IcyHttpDataSource.java | 55 +++++++++---------- .../ext/icy/IcyHttpDataSourceFactory.java | 3 +- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/exoplayer2-ext-icy/build.gradle b/exoplayer2-ext-icy/build.gradle index 0931fcf..d922e37 100644 --- a/exoplayer2-ext-icy/build.gradle +++ b/exoplayer2-ext-icy/build.gradle @@ -54,6 +54,7 @@ android { dependencies { // Runtime dependencies implementation 'com.google.android.exoplayer:exoplayer-core:2.8.4' + implementation 'com.google.android.exoplayer:extension-okhttp:2.8.4' // Test dependencies testImplementation 'junit:junit:4.12' diff --git a/exoplayer2-ext-icy/src/main/java/saschpe/exoplayer2/ext/icy/IcyHttpDataSource.java b/exoplayer2-ext-icy/src/main/java/saschpe/exoplayer2/ext/icy/IcyHttpDataSource.java index e625e45..5bbe5e9 100644 --- a/exoplayer2-ext-icy/src/main/java/saschpe/exoplayer2/ext/icy/IcyHttpDataSource.java +++ b/exoplayer2-ext-icy/src/main/java/saschpe/exoplayer2/ext/icy/IcyHttpDataSource.java @@ -4,9 +4,9 @@ import android.support.annotation.Nullable; import android.util.Log; +import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSpec; -import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.util.Predicate; @@ -14,11 +14,14 @@ import java.util.List; import java.util.Map; +import okhttp3.CacheControl; +import okhttp3.Call; + /** * https://cast.readme.io/v1.0/docs/icy * http://www.smackfu.com/stuff/programming/shoutcast.html */ -public final class IcyHttpDataSource extends DefaultHttpDataSource { +public final class IcyHttpDataSource extends OkHttpDataSource { private static final String TAG = IcyHttpDataSource.class.getSimpleName(); private static final String REQUEST_HEADER_ICY_METAINT_KEY = "Icy-MetaData"; @@ -49,14 +52,13 @@ public interface IcyMetadataListener { } private IcyHttpDataSource( - @NonNull final String userAgent, + @NonNull Call.Factory callFactory, + @Nullable final String userAgent, @Nullable final Predicate contentTypePredicate, - @Nullable final TransferListener listener, - final int connectTimeoutMillis, - final int readTimeoutMillis, - final boolean allowCrossProtocolRedirects, + @Nullable final TransferListener listener, + @Nullable CacheControl cacheControl, @Nullable final RequestProperties defaultRequestProperties) { - super(userAgent, contentTypePredicate, listener, connectTimeoutMillis, readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties); + super(callFactory, userAgent, contentTypePredicate, listener, cacheControl, defaultRequestProperties); defaultRequestProperties.set(REQUEST_HEADER_ICY_METAINT_KEY, REQUEST_HEADER_ICY_METAINT_VALUE); // See class Builder } @@ -202,18 +204,22 @@ private IcyMetadata parseMetadata(final String metaDataString) { } public final static class Builder { + private Call.Factory callFactory; private String userAgent; private Predicate contentTypePredicate; - private TransferListener listener; - private int connectTimeoutMillis; - private int readTimeoutMillis; - private boolean allowCrossProtocolRedirects; + private TransferListener listener; + private CacheControl cacheControl; private RequestProperties defaultRequestProperties = new RequestProperties(); private IcyHeadersListener icyHeadersListener; private IcyMetadataListener icyMetadataListener; - public Builder(@NonNull final String userAgent) { + public Builder(@NonNull Call.Factory callFactory) { + this.callFactory = callFactory; + } + + public Builder setUserAgent(@NonNull final String userAgent) { this.userAgent = userAgent; + return this; } public Builder setContentTypePredicate(@NonNull final Predicate contentTypePredicate) { @@ -226,18 +232,8 @@ public Builder setTransferListener(@NonNull final TransferListener * The exact contents isn't specified and implementation specific. It's therefore up to the * user to figure what format a given stream returns. */ diff --git a/exoplayer2-ext-icy/src/main/java/saschpe/exoplayer2/ext/icy/IcyHttpDataSourceFactory.java b/exoplayer2-ext-icy/src/main/java/saschpe/exoplayer2/ext/icy/IcyHttpDataSourceFactory.java index 454da17..04d2ec0 100644 --- a/exoplayer2-ext-icy/src/main/java/saschpe/exoplayer2/ext/icy/IcyHttpDataSourceFactory.java +++ b/exoplayer2-ext-icy/src/main/java/saschpe/exoplayer2/ext/icy/IcyHttpDataSourceFactory.java @@ -2,12 +2,13 @@ import android.support.annotation.NonNull; +import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.TransferListener; /** A {@link HttpDataSource.Factory} that produces {@link IcyHttpDataSource} instances. */ -public final class IcyHttpDataSourceFactory extends HttpDataSource.BaseFactory { +public final class IcyHttpDataSourceFactory extends OkHttpDataSource.BaseFactory { private String userAgent; private TransferListener listener; private int connectTimeoutMillis;