mirror of
https://github.com/samsonjs/media.git
synced 2026-04-08 11:45:51 +00:00
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
This commit is contained in:
parent
59b18a52d2
commit
a076924caa
4 changed files with 277 additions and 56 deletions
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
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.DefaultHttpDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||
|
|
@ -46,7 +47,7 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
|||
private final CronetEngineWrapper cronetEngineWrapper;
|
||||
private final Executor executor;
|
||||
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 readTimeoutMs;
|
||||
private final boolean resetTimeoutOnRedirects;
|
||||
|
|
@ -54,26 +55,176 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Sets {@link CronetDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
|
||||
* CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
|
||||
* <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 transferListener An optional listener.
|
||||
* @param fallbackFactory A {@link HttpDataSource.Factory} which is used as a fallback in case
|
||||
* no suitable CronetEngine can be build.
|
||||
* 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,
|
||||
TransferListener<? super DataSource> transferListener,
|
||||
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.
|
||||
*
|
||||
* <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 transferListener An optional listener.
|
||||
* @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,
|
||||
@Nullable TransferListener<? super DataSource> transferListener,
|
||||
HttpDataSource.Factory fallbackFactory) {
|
||||
this(cronetEngineWrapper, executor, contentTypePredicate, transferListener,
|
||||
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, false, fallbackFactory);
|
||||
|
|
@ -81,25 +232,28 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
|||
|
||||
/**
|
||||
* 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
|
||||
* CronetDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
|
||||
* <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}.
|
||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||
* CronetDataSource#open}.
|
||||
* @param transferListener An optional listener.
|
||||
* @param userAgent A user agent used to create a fallback HttpDataSource if needed.
|
||||
*/
|
||||
public CronetDataSourceFactory(CronetEngineWrapper cronetEngineWrapper,
|
||||
Executor executor, Predicate<String> contentTypePredicate,
|
||||
TransferListener<? super DataSource> transferListener, String userAgent) {
|
||||
public CronetDataSourceFactory(
|
||||
CronetEngineWrapper cronetEngineWrapper,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable TransferListener<? super DataSource> transferListener,
|
||||
String userAgent) {
|
||||
this(cronetEngineWrapper, executor, contentTypePredicate, transferListener,
|
||||
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, false,
|
||||
new DefaultHttpDataSourceFactory(userAgent, transferListener,
|
||||
|
|
@ -108,25 +262,30 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
|||
|
||||
/**
|
||||
* Constructs a CronetDataSourceFactory.
|
||||
* <p>
|
||||
* If the {@link CronetEngineWrapper} fails to provide a {@link CronetEngine}, a
|
||||
* {@link DefaultHttpDataSourceFactory} will be used instead.
|
||||
*
|
||||
* <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}.
|
||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||
* CronetDataSource#open}.
|
||||
* @param transferListener An optional listener.
|
||||
* @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,
|
||||
TransferListener<? super DataSource> transferListener, int connectTimeoutMs,
|
||||
int readTimeoutMs, boolean resetTimeoutOnRedirects, String userAgent) {
|
||||
public CronetDataSourceFactory(
|
||||
CronetEngineWrapper cronetEngineWrapper,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable TransferListener<? super DataSource> transferListener,
|
||||
int connectTimeoutMs,
|
||||
int readTimeoutMs,
|
||||
boolean resetTimeoutOnRedirects,
|
||||
String userAgent) {
|
||||
this(cronetEngineWrapper, executor, contentTypePredicate, transferListener,
|
||||
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS, resetTimeoutOnRedirects,
|
||||
new DefaultHttpDataSourceFactory(userAgent, transferListener, connectTimeoutMs,
|
||||
|
|
@ -135,26 +294,30 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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}.
|
||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||
* CronetDataSource#open}.
|
||||
* @param transferListener An optional listener.
|
||||
* @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.
|
||||
* @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,
|
||||
TransferListener<? super DataSource> transferListener, int connectTimeoutMs,
|
||||
int readTimeoutMs, boolean resetTimeoutOnRedirects,
|
||||
public CronetDataSourceFactory(
|
||||
CronetEngineWrapper cronetEngineWrapper,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable TransferListener<? super DataSource> transferListener,
|
||||
int connectTimeoutMs,
|
||||
int readTimeoutMs,
|
||||
boolean resetTimeoutOnRedirects,
|
||||
HttpDataSource.Factory fallbackFactory) {
|
||||
this.cronetEngineWrapper = cronetEngineWrapper;
|
||||
this.executor = executor;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,28 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
|
|||
@Nullable private final TransferListener<? super DataSource> listener;
|
||||
@Nullable private final CacheControl 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.
|
||||
*/
|
||||
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.
|
||||
|
|
@ -43,7 +65,7 @@ public final class OkHttpDataSourceFactory extends BaseFactory {
|
|||
*/
|
||||
public OkHttpDataSourceFactory(@NonNull Call.Factory callFactory, @Nullable String userAgent,
|
||||
@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 {
|
|||
return new OkHttpDataSource(callFactory, userAgent, null, listener, cacheControl,
|
||||
defaultRequestProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
package com.google.android.exoplayer2.upstream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
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 {
|
||||
|
||||
private final Context context;
|
||||
private final TransferListener<? super DataSource> listener;
|
||||
private final @Nullable TransferListener<? super DataSource> listener;
|
||||
private final DataSource.Factory baseDataSourceFactory;
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +34,7 @@ public final class DefaultDataSourceFactory implements Factory {
|
|||
* @param userAgent The User-Agent string that should be used.
|
||||
*/
|
||||
public DefaultDataSourceFactory(Context context, String userAgent) {
|
||||
this(context, userAgent, null);
|
||||
this(context, userAgent, /* listener= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -41,11 +42,21 @@ public final class DefaultDataSourceFactory implements Factory {
|
|||
* @param userAgent The User-Agent string that should be used.
|
||||
* @param listener An optional listener.
|
||||
*/
|
||||
public DefaultDataSourceFactory(Context context, String userAgent,
|
||||
TransferListener<? super DataSource> listener) {
|
||||
public DefaultDataSourceFactory(
|
||||
Context context, String userAgent, @Nullable TransferListener<? super DataSource> listener) {
|
||||
this(context, listener, new DefaultHttpDataSourceFactory(userAgent, listener));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
|
|
@ -53,7 +64,9 @@ public final class DefaultDataSourceFactory implements Factory {
|
|||
* for {@link DefaultDataSource}.
|
||||
* @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) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.listener = listener;
|
||||
|
|
@ -64,5 +77,4 @@ public final class DefaultDataSourceFactory implements Factory {
|
|||
public DefaultDataSource createDataSource() {
|
||||
return new DefaultDataSource(context, listener, baseDataSourceFactory.createDataSource());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
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.Factory;
|
||||
|
||||
|
|
@ -22,7 +23,7 @@ import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
|
|||
public final class DefaultHttpDataSourceFactory extends BaseFactory {
|
||||
|
||||
private final String userAgent;
|
||||
private final TransferListener<? super DataSource> listener;
|
||||
private final @Nullable TransferListener<? super DataSource> listener;
|
||||
private final int connectTimeoutMillis;
|
||||
private final int readTimeoutMillis;
|
||||
private final boolean allowCrossProtocolRedirects;
|
||||
|
|
@ -50,11 +51,33 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
|
|||
* @see #DefaultHttpDataSourceFactory(String, TransferListener, int, int, boolean)
|
||||
*/
|
||||
public DefaultHttpDataSourceFactory(
|
||||
String userAgent, TransferListener<? super DataSource> listener) {
|
||||
String userAgent, @Nullable TransferListener<? super DataSource> listener) {
|
||||
this(userAgent, listener, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
|
|
@ -65,9 +88,12 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
|
|||
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||
* to HTTPS and vice versa) are enabled.
|
||||
*/
|
||||
public DefaultHttpDataSourceFactory(String userAgent,
|
||||
TransferListener<? super DataSource> listener, int connectTimeoutMillis,
|
||||
int readTimeoutMillis, boolean allowCrossProtocolRedirects) {
|
||||
public DefaultHttpDataSourceFactory(
|
||||
String userAgent,
|
||||
@Nullable TransferListener<? super DataSource> listener,
|
||||
int connectTimeoutMillis,
|
||||
int readTimeoutMillis,
|
||||
boolean allowCrossProtocolRedirects) {
|
||||
this.userAgent = userAgent;
|
||||
this.listener = listener;
|
||||
this.connectTimeoutMillis = connectTimeoutMillis;
|
||||
|
|
@ -81,5 +107,4 @@ public final class DefaultHttpDataSourceFactory extends BaseFactory {
|
|||
return new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
|
||||
readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue