Commit a076924c by tonihei Committed by Oliver Woodman

Simplify using DataSource factories without a TransferListener.

Setting the transfer listener on the data source factories is only needed for debug
purposes, logging and for custom bandwidth metering which doesn't use the
player-provided bandwidth meter. As such, it is not compulsary and it should be easy
to set up the data source factory without a transfer listener.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204926083
parent 59b18a52
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.ext.cronet; package com.google.android.exoplayer2.ext.cronet;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource;
...@@ -46,7 +47,7 @@ public final class CronetDataSourceFactory extends BaseFactory { ...@@ -46,7 +47,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
private final CronetEngineWrapper cronetEngineWrapper; private final CronetEngineWrapper cronetEngineWrapper;
private final Executor executor; private final Executor executor;
private final Predicate<String> contentTypePredicate; private final Predicate<String> contentTypePredicate;
private final TransferListener<? super DataSource> transferListener; private final @Nullable TransferListener<? super DataSource> transferListener;
private final int connectTimeoutMs; private final int connectTimeoutMs;
private final int readTimeoutMs; private final int readTimeoutMs;
private final boolean resetTimeoutOnRedirects; private final boolean resetTimeoutOnRedirects;
...@@ -54,26 +55,176 @@ public final class CronetDataSourceFactory extends BaseFactory { ...@@ -54,26 +55,176 @@ public final class CronetDataSourceFactory extends BaseFactory {
/** /**
* Constructs a CronetDataSourceFactory. * Constructs a CronetDataSourceFactory.
* <p> *
* If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided * <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
* fallback {@link HttpDataSource.Factory} will be used instead.
*
* <p>Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout,
* {@link CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
* cross-protocol redirects.
*
* @param cronetEngineWrapper A {@link CronetEngineWrapper}.
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
* CronetDataSource#open}.
* @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case no
* suitable CronetEngine can be build.
*/
public CronetDataSourceFactory(
CronetEngineWrapper cronetEngineWrapper,
Executor executor,
Predicate<String> contentTypePredicate,
HttpDataSource.Factory fallbackFactory) {
this(
cronetEngineWrapper,
executor,
contentTypePredicate,
/* transferListener= */ null,
DEFAULT_CONNECT_TIMEOUT_MILLIS,
DEFAULT_READ_TIMEOUT_MILLIS,
false,
fallbackFactory);
}
/**
* Constructs a CronetDataSourceFactory.
*
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
* DefaultHttpDataSourceFactory} will be used instead.
*
* <p>Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout,
* {@link CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
* cross-protocol redirects.
*
* @param cronetEngineWrapper A {@link CronetEngineWrapper}.
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
* CronetDataSource#open}.
* @param userAgent A user agent used to create a fallback HttpDataSource if needed.
*/
public CronetDataSourceFactory(
CronetEngineWrapper cronetEngineWrapper,
Executor executor,
Predicate<String> contentTypePredicate,
String userAgent) {
this(
cronetEngineWrapper,
executor,
contentTypePredicate,
/* transferListener= */ null,
DEFAULT_CONNECT_TIMEOUT_MILLIS,
DEFAULT_READ_TIMEOUT_MILLIS,
false,
new DefaultHttpDataSourceFactory(
userAgent,
/* listener= */ null,
DEFAULT_CONNECT_TIMEOUT_MILLIS,
DEFAULT_READ_TIMEOUT_MILLIS,
false));
}
/**
* Constructs a CronetDataSourceFactory.
*
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
* DefaultHttpDataSourceFactory} will be used instead.
*
* @param cronetEngineWrapper A {@link CronetEngineWrapper}.
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
* CronetDataSource#open}.
* @param connectTimeoutMs The connection timeout, in milliseconds.
* @param readTimeoutMs The read timeout, in milliseconds.
* @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
* @param userAgent A user agent used to create a fallback HttpDataSource if needed.
*/
public CronetDataSourceFactory(
CronetEngineWrapper cronetEngineWrapper,
Executor executor,
Predicate<String> contentTypePredicate,
int connectTimeoutMs,
int readTimeoutMs,
boolean resetTimeoutOnRedirects,
String userAgent) {
this(
cronetEngineWrapper,
executor,
contentTypePredicate,
/* transferListener= */ null,
DEFAULT_CONNECT_TIMEOUT_MILLIS,
DEFAULT_READ_TIMEOUT_MILLIS,
resetTimeoutOnRedirects,
new DefaultHttpDataSourceFactory(
userAgent,
/* listener= */ null,
connectTimeoutMs,
readTimeoutMs,
resetTimeoutOnRedirects));
}
/**
* Constructs a CronetDataSourceFactory.
*
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
* fallback {@link HttpDataSource.Factory} will be used instead.
*
* @param cronetEngineWrapper A {@link CronetEngineWrapper}.
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
* CronetDataSource#open}.
* @param connectTimeoutMs The connection timeout, in milliseconds.
* @param readTimeoutMs The read timeout, in milliseconds.
* @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
* @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case no
* suitable CronetEngine can be build.
*/
public CronetDataSourceFactory(
CronetEngineWrapper cronetEngineWrapper,
Executor executor,
Predicate<String> contentTypePredicate,
int connectTimeoutMs,
int readTimeoutMs,
boolean resetTimeoutOnRedirects,
HttpDataSource.Factory fallbackFactory) {
this(
cronetEngineWrapper,
executor,
contentTypePredicate,
/* transferListener= */ null,
connectTimeoutMs,
readTimeoutMs,
resetTimeoutOnRedirects,
fallbackFactory);
}
/**
* Constructs a CronetDataSourceFactory.
*
* <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
* fallback {@link HttpDataSource.Factory} will be used instead. * fallback {@link HttpDataSource.Factory} will be used instead.
* *
* Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link * <p>Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout,
* CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables * {@link CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
* cross-protocol redirects. * cross-protocol redirects.
* *
* @param cronetEngineWrapper A {@link CronetEngineWrapper}. * @param cronetEngineWrapper A {@link CronetEngineWrapper}.
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests. * @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then an {@link InvalidContentTypeException} is thrown from * predicate then an {@link InvalidContentTypeException} is thrown from {@link
* {@link CronetDataSource#open}. * CronetDataSource#open}.
* @param transferListener An optional listener. * @param transferListener An optional listener.
* @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case * @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case no
* no suitable CronetEngine can be build. * suitable CronetEngine can be build.
*/ */
public CronetDataSourceFactory(CronetEngineWrapper cronetEngineWrapper, public CronetDataSourceFactory(
Executor executor, Predicate<String> contentTypePredicate, CronetEngineWrapper cronetEngineWrapper,
TransferListener<? super DataSource> transferListener, Executor executor,
Predicate<String> contentTypePredicate,
@Nullable TransferListener<? super DataSource> transferListener,
HttpDataSource.Factory fallbackFactory) { HttpDataSource.Factory fallbackFactory) {
this(cronetEngineWrapper, executor, contentTypePredicate, transferListener, this(cronetEngineWrapper, executor, contentTypePredicate, transferListener,
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, false, fallbackFactory); DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, false, fallbackFactory);
...@@ -81,25 +232,28 @@ public final class CronetDataSourceFactory extends BaseFactory { ...@@ -81,25 +232,28 @@ public final class CronetDataSourceFactory extends BaseFactory {
/** /**
* Constructs a CronetDataSourceFactory. * Constructs a CronetDataSourceFactory.
* <p>
* If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a
* {@link DefaultHttpDataSourceFactory} will be used instead.
* *
* Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link * <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
* CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables * DefaultHttpDataSourceFactory} will be used instead.
*
* <p>Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout,
* {@link CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
* cross-protocol redirects. * cross-protocol redirects.
* *
* @param cronetEngineWrapper A {@link CronetEngineWrapper}. * @param cronetEngineWrapper A {@link CronetEngineWrapper}.
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests. * @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then an {@link InvalidContentTypeException} is thrown from * predicate then an {@link InvalidContentTypeException} is thrown from {@link
* {@link CronetDataSource#open}. * CronetDataSource#open}.
* @param transferListener An optional listener. * @param transferListener An optional listener.
* @param userAgent A user agent used to create a fallback HttpDataSource if needed. * @param userAgent A user agent used to create a fallback HttpDataSource if needed.
*/ */
public CronetDataSourceFactory(CronetEngineWrapper cronetEngineWrapper, public CronetDataSourceFactory(
Executor executor, Predicate<String> contentTypePredicate, CronetEngineWrapper cronetEngineWrapper,
TransferListener<? super DataSource> transferListener, String userAgent) { Executor executor,
Predicate<String> contentTypePredicate,
@Nullable TransferListener<? super DataSource> transferListener,
String userAgent) {
this(cronetEngineWrapper, executor, contentTypePredicate, transferListener, this(cronetEngineWrapper, executor, contentTypePredicate, transferListener,
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, false, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, false,
new DefaultHttpDataSourceFactory(userAgent, transferListener, new DefaultHttpDataSourceFactory(userAgent, transferListener,
...@@ -108,25 +262,30 @@ public final class CronetDataSourceFactory extends BaseFactory { ...@@ -108,25 +262,30 @@ public final class CronetDataSourceFactory extends BaseFactory {
/** /**
* Constructs a CronetDataSourceFactory. * Constructs a CronetDataSourceFactory.
* <p> *
* If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a * <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a {@link
* {@link DefaultHttpDataSourceFactory} will be used instead. * DefaultHttpDataSourceFactory} will be used instead.
* *
* @param cronetEngineWrapper A {@link CronetEngineWrapper}. * @param cronetEngineWrapper A {@link CronetEngineWrapper}.
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests. * @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then an {@link InvalidContentTypeException} is thrown from * predicate then an {@link InvalidContentTypeException} is thrown from {@link
* {@link CronetDataSource#open}. * CronetDataSource#open}.
* @param transferListener An optional listener. * @param transferListener An optional listener.
* @param connectTimeoutMs The connection timeout, in milliseconds. * @param connectTimeoutMs The connection timeout, in milliseconds.
* @param readTimeoutMs The read timeout, in milliseconds. * @param readTimeoutMs The read timeout, in milliseconds.
* @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs. * @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
* @param userAgent A user agent used to create a fallback HttpDataSource if needed. * @param userAgent A user agent used to create a fallback HttpDataSource if needed.
*/ */
public CronetDataSourceFactory(CronetEngineWrapper cronetEngineWrapper, public CronetDataSourceFactory(
Executor executor, Predicate<String> contentTypePredicate, CronetEngineWrapper cronetEngineWrapper,
TransferListener<? super DataSource> transferListener, int connectTimeoutMs, Executor executor,
int readTimeoutMs, boolean resetTimeoutOnRedirects, String userAgent) { Predicate<String> contentTypePredicate,
@Nullable TransferListener<? super DataSource> transferListener,
int connectTimeoutMs,
int readTimeoutMs,
boolean resetTimeoutOnRedirects,
String userAgent) {
this(cronetEngineWrapper, executor, contentTypePredicate, transferListener, this(cronetEngineWrapper, executor, contentTypePredicate, transferListener,
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, resetTimeoutOnRedirects, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, resetTimeoutOnRedirects,
new DefaultHttpDataSourceFactory(userAgent, transferListener, connectTimeoutMs, new DefaultHttpDataSourceFactory(userAgent, transferListener, connectTimeoutMs,
...@@ -135,26 +294,30 @@ public final class CronetDataSourceFactory extends BaseFactory { ...@@ -135,26 +294,30 @@ public final class CronetDataSourceFactory extends BaseFactory {
/** /**
* Constructs a CronetDataSourceFactory. * Constructs a CronetDataSourceFactory.
* <p> *
* If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided * <p>If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, the provided
* fallback {@link HttpDataSource.Factory} will be used instead. * fallback {@link HttpDataSource.Factory} will be used instead.
* *
* @param cronetEngineWrapper A {@link CronetEngineWrapper}. * @param cronetEngineWrapper A {@link CronetEngineWrapper}.
* @param executor The {@link java.util.concurrent.Executor} that will perform the requests. * @param executor The {@link java.util.concurrent.Executor} that will perform the requests.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the * @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then an {@link InvalidContentTypeException} is thrown from * predicate then an {@link InvalidContentTypeException} is thrown from {@link
* {@link CronetDataSource#open}. * CronetDataSource#open}.
* @param transferListener An optional listener. * @param transferListener An optional listener.
* @param connectTimeoutMs The connection timeout, in milliseconds. * @param connectTimeoutMs The connection timeout, in milliseconds.
* @param readTimeoutMs The read timeout, in milliseconds. * @param readTimeoutMs The read timeout, in milliseconds.
* @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs. * @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
* @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case * @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case no
* no suitable CronetEngine can be build. * suitable CronetEngine can be build.
*/ */
public CronetDataSourceFactory(CronetEngineWrapper cronetEngineWrapper, public CronetDataSourceFactory(
Executor executor, Predicate<String> contentTypePredicate, CronetEngineWrapper cronetEngineWrapper,
TransferListener<? super DataSource> transferListener, int connectTimeoutMs, Executor executor,
int readTimeoutMs, boolean resetTimeoutOnRedirects, Predicate<String> contentTypePredicate,
@Nullable TransferListener<? super DataSource> transferListener,
int connectTimeoutMs,
int readTimeoutMs,
boolean resetTimeoutOnRedirects,
HttpDataSource.Factory fallbackFactory) { HttpDataSource.Factory fallbackFactory) {
this.cronetEngineWrapper = cronetEngineWrapper; this.cronetEngineWrapper = cronetEngineWrapper;
this.executor = executor; this.executor = executor;
......
...@@ -39,11 +39,33 @@ public final class OkHttpDataSourceFactory extends BaseFactory { ...@@ -39,11 +39,33 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use * @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
* by the sources created by the factory. * by the sources created by the factory.
* @param userAgent An optional User-Agent string. * @param userAgent An optional User-Agent string.
*/
public OkHttpDataSourceFactory(@NonNull Call.Factory callFactory, @Nullable String userAgent) {
this(callFactory, userAgent, /* listener= */ null, /* cacheControl= */ null);
}
/**
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
* by the sources created by the factory.
* @param userAgent An optional User-Agent string.
* @param cacheControl An optional {@link CacheControl} for setting the Cache-Control header.
*/
public OkHttpDataSourceFactory(
@NonNull Call.Factory callFactory,
@Nullable String userAgent,
@Nullable CacheControl cacheControl) {
this(callFactory, userAgent, /* listener= */ null, cacheControl);
}
/**
* @param callFactory A {@link Call.Factory} (typically an {@link okhttp3.OkHttpClient}) for use
* by the sources created by the factory.
* @param userAgent An optional User-Agent string.
* @param listener An optional listener. * @param listener An optional listener.
*/ */
public OkHttpDataSourceFactory(@NonNull Call.Factory callFactory, @Nullable String userAgent, public OkHttpDataSourceFactory(@NonNull Call.Factory callFactory, @Nullable String userAgent,
@Nullable TransferListener<? super DataSource> listener) { @Nullable TransferListener<? super DataSource> listener) {
this(callFactory, userAgent, listener, null); this(callFactory, userAgent, listener, /* cacheControl= */ null);
} }
/** /**
...@@ -68,5 +90,4 @@ public final class OkHttpDataSourceFactory extends BaseFactory { ...@@ -68,5 +90,4 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
return new OkHttpDataSource(callFactory, userAgent, null, listener, cacheControl, return new OkHttpDataSource(callFactory, userAgent, null, listener, cacheControl,
defaultRequestProperties); defaultRequestProperties);
} }
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.upstream; package com.google.android.exoplayer2.upstream;
import android.content.Context; import android.content.Context;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.DataSource.Factory; import com.google.android.exoplayer2.upstream.DataSource.Factory;
/** /**
...@@ -25,7 +26,7 @@ import com.google.android.exoplayer2.upstream.DataSource.Factory; ...@@ -25,7 +26,7 @@ import com.google.android.exoplayer2.upstream.DataSource.Factory;
public final class DefaultDataSourceFactory implements Factory { public final class DefaultDataSourceFactory implements Factory {
private final Context context; private final Context context;
private final TransferListener<? super DataSource> listener; private final @Nullable TransferListener<? super DataSource> listener;
private final DataSource.Factory baseDataSourceFactory; private final DataSource.Factory baseDataSourceFactory;
/** /**
...@@ -33,7 +34,7 @@ public final class DefaultDataSourceFactory implements Factory { ...@@ -33,7 +34,7 @@ public final class DefaultDataSourceFactory implements Factory {
* @param userAgent The User-Agent string that should be used. * @param userAgent The User-Agent string that should be used.
*/ */
public DefaultDataSourceFactory(Context context, String userAgent) { public DefaultDataSourceFactory(Context context, String userAgent) {
this(context, userAgent, null); this(context, userAgent, /* listener= */ null);
} }
/** /**
...@@ -41,19 +42,31 @@ public final class DefaultDataSourceFactory implements Factory { ...@@ -41,19 +42,31 @@ public final class DefaultDataSourceFactory implements Factory {
* @param userAgent The User-Agent string that should be used. * @param userAgent The User-Agent string that should be used.
* @param listener An optional listener. * @param listener An optional listener.
*/ */
public DefaultDataSourceFactory(Context context, String userAgent, public DefaultDataSourceFactory(
TransferListener<? super DataSource> listener) { Context context, String userAgent, @Nullable TransferListener<? super DataSource> listener) {
this(context, listener, new DefaultHttpDataSourceFactory(userAgent, listener)); this(context, listener, new DefaultHttpDataSourceFactory(userAgent, listener));
} }
/** /**
* @param context A context. * @param context A context.
* @param baseDataSourceFactory A {@link Factory} to be used to create a base {@link DataSource}
* for {@link DefaultDataSource}.
* @see DefaultDataSource#DefaultDataSource(Context, TransferListener, DataSource)
*/
public DefaultDataSourceFactory(Context context, DataSource.Factory baseDataSourceFactory) {
this(context, /* listener= */ null, baseDataSourceFactory);
}
/**
* @param context A context.
* @param listener An optional listener. * @param listener An optional listener.
* @param baseDataSourceFactory A {@link Factory} to be used to create a base {@link DataSource} * @param baseDataSourceFactory A {@link Factory} to be used to create a base {@link DataSource}
* for {@link DefaultDataSource}. * for {@link DefaultDataSource}.
* @see DefaultDataSource#DefaultDataSource(Context, TransferListener, DataSource) * @see DefaultDataSource#DefaultDataSource(Context, TransferListener, DataSource)
*/ */
public DefaultDataSourceFactory(Context context, TransferListener<? super DataSource> listener, public DefaultDataSourceFactory(
Context context,
@Nullable TransferListener<? super DataSource> listener,
DataSource.Factory baseDataSourceFactory) { DataSource.Factory baseDataSourceFactory) {
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
this.listener = listener; this.listener = listener;
...@@ -64,5 +77,4 @@ public final class DefaultDataSourceFactory implements Factory { ...@@ -64,5 +77,4 @@ public final class DefaultDataSourceFactory implements Factory {
public DefaultDataSource createDataSource() { public DefaultDataSource createDataSource() {
return new DefaultDataSource(context, listener, baseDataSourceFactory.createDataSource()); return new DefaultDataSource(context, listener, baseDataSourceFactory.createDataSource());
} }
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.upstream; package com.google.android.exoplayer2.upstream;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory; import com.google.android.exoplayer2.upstream.HttpDataSource.BaseFactory;
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory; import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
...@@ -22,7 +23,7 @@ import com.google.android.exoplayer2.upstream.HttpDataSource.Factory; ...@@ -22,7 +23,7 @@ import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
public final class DefaultHttpDataSourceFactory extends BaseFactory { public final class DefaultHttpDataSourceFactory extends BaseFactory {
private final String userAgent; private final String userAgent;
private final TransferListener<? super DataSource> listener; private final @Nullable TransferListener<? super DataSource> listener;
private final int connectTimeoutMillis; private final int connectTimeoutMillis;
private final int readTimeoutMillis; private final int readTimeoutMillis;
private final boolean allowCrossProtocolRedirects; private final boolean allowCrossProtocolRedirects;
...@@ -50,13 +51,35 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory { ...@@ -50,13 +51,35 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
* @see #DefaultHttpDataSourceFactory(String, TransferListener, int, int, boolean) * @see #DefaultHttpDataSourceFactory(String, TransferListener, int, int, boolean)
*/ */
public DefaultHttpDataSourceFactory( public DefaultHttpDataSourceFactory(
String userAgent, TransferListener<? super DataSource> listener) { String userAgent, @Nullable TransferListener<? super DataSource> listener) {
this(userAgent, listener, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, this(userAgent, listener, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false); DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false);
} }
/** /**
* @param userAgent The User-Agent string that should be used. * @param userAgent The User-Agent string that should be used.
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in
* milliseconds. A timeout of zero is interpreted as an infinite timeout.
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
* to HTTPS and vice versa) are enabled.
*/
public DefaultHttpDataSourceFactory(
String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects) {
this(
userAgent,
/* listener= */ null,
connectTimeoutMillis,
readTimeoutMillis,
allowCrossProtocolRedirects);
}
/**
* @param userAgent The User-Agent string that should be used.
* @param listener An optional listener. * @param listener An optional listener.
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote * @param connectTimeoutMillis The connection timeout that should be used when requesting remote
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout. * data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
...@@ -65,9 +88,12 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory { ...@@ -65,9 +88,12 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP * @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
* to HTTPS and vice versa) are enabled. * to HTTPS and vice versa) are enabled.
*/ */
public DefaultHttpDataSourceFactory(String userAgent, public DefaultHttpDataSourceFactory(
TransferListener<? super DataSource> listener, int connectTimeoutMillis, String userAgent,
int readTimeoutMillis, boolean allowCrossProtocolRedirects) { @Nullable TransferListener<? super DataSource> listener,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects) {
this.userAgent = userAgent; this.userAgent = userAgent;
this.listener = listener; this.listener = listener;
this.connectTimeoutMillis = connectTimeoutMillis; this.connectTimeoutMillis = connectTimeoutMillis;
...@@ -81,5 +107,4 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory { ...@@ -81,5 +107,4 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
return new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis, return new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties); readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment