Skip to content

Commit

Permalink
Switch to OkHttpDataSource
Browse files Browse the repository at this point in the history
As requested in ExoPlayer issue 3735[0].

[0] google/ExoPlayer#3735
  • Loading branch information
saschpe committed Sep 25, 2018
1 parent 757f603 commit ef14462
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
1 change: 1 addition & 0 deletions exoplayer2-ext-icy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
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;

import java.util.HashMap;
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";
Expand Down Expand Up @@ -49,14 +52,13 @@ public interface IcyMetadataListener {
}

private IcyHttpDataSource(
@NonNull final String userAgent,
@NonNull Call.Factory callFactory,
@Nullable final String userAgent,
@Nullable final Predicate<String> contentTypePredicate,
@Nullable final TransferListener<? super DefaultHttpDataSource> listener,
final int connectTimeoutMillis,
final int readTimeoutMillis,
final boolean allowCrossProtocolRedirects,
@Nullable final TransferListener<? super OkHttpDataSource> 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
}
Expand Down Expand Up @@ -202,18 +204,22 @@ private IcyMetadata parseMetadata(final String metaDataString) {
}

public final static class Builder {
private Call.Factory callFactory;
private String userAgent;
private Predicate<String> contentTypePredicate;
private TransferListener<? super DefaultHttpDataSource> listener;
private int connectTimeoutMillis;
private int readTimeoutMillis;
private boolean allowCrossProtocolRedirects;
private TransferListener<? super OkHttpDataSource> 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<String> contentTypePredicate) {
Expand All @@ -226,18 +232,8 @@ public Builder setTransferListener(@NonNull final TransferListener<? super DataS
return this;
}

public Builder setConnectTimeoutMillis(final int connectTimeoutMillis) {
this.connectTimeoutMillis = connectTimeoutMillis;
return this;
}

public Builder setReadTimeoutMillis(final int readTimeoutMillis) {
this.readTimeoutMillis = readTimeoutMillis;
return this;
}

public Builder setAllowCrossProtocolRedirects(final boolean allowCrossProtocolRedirects) {
this.allowCrossProtocolRedirects = allowCrossProtocolRedirects;
public Builder setCacheControl(@NonNull final CacheControl cacheControl) {
this.cacheControl = cacheControl;
return this;
}

Expand All @@ -258,12 +254,11 @@ public Builder setIcyMetadataListener(@NonNull final IcyMetadataListener icyMeta

IcyHttpDataSource build() {
final IcyHttpDataSource dataSource =
new IcyHttpDataSource(userAgent,
new IcyHttpDataSource(callFactory,
userAgent,
contentTypePredicate,
listener,
connectTimeoutMillis,
readTimeoutMillis,
allowCrossProtocolRedirects,
cacheControl,
defaultRequestProperties);
dataSource.icyHeadersListener = icyHeadersListener;
dataSource.icyMetadataListener = icyMetadataListener;
Expand Down Expand Up @@ -346,7 +341,7 @@ public String toString() {

/**
* Container for stream title and URL.
*
* <p>
* The exact contents isn't specified and implementation specific. It's therefore up to the
* user to figure what format a given stream returns.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? super DataSource> listener;
private int connectTimeoutMillis;
Expand Down

0 comments on commit ef14462

Please sign in to comment.