Back to Exoplayer

OkHttpDataSource.Factory (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.Factory.html

latest8.1 KB
Original Source

Package com.google.android.exoplayer2.ext.okhttp

Class OkHttpDataSource.Factory

  • java.lang.Object

    • com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource.Factory
  • All Implemented Interfaces:DataSource.Factory, HttpDataSource.FactoryEnclosing class:OkHttpDataSource


public static final classOkHttpDataSource.Factoryextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[HttpDataSource.Factory](../../upstream/HttpDataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")

DataSource.Factory for OkHttpDataSource instances.

Constructor Summary

Constructors | Constructor | Description | | --- | --- | | Factory​(okhttp3.Call.Factory callFactory) | Creates an instance. |

Method Summary

All Methods Instance Methods Concrete Methods | Modifier and Type | Method | Description | | --- | --- | --- | | OkHttpDataSource | createDataSource() | Creates a DataSource instance. | | OkHttpDataSource.Factory | setCacheControl​(okhttp3.CacheControl cacheControl) | Sets the CacheControl that will be used. | | OkHttpDataSource.Factory | setContentTypePredicate​(Predicate<String> contentTypePredicate) | Sets a content type Predicate. | | OkHttpDataSource.Factory | setDefaultRequestProperties​(Map<String,​String> defaultRequestProperties) | Sets the default request headers for HttpDataSource instances created by the factory. | | OkHttpDataSource.Factory | setTransferListener​(TransferListener transferListener) | Sets the TransferListener that will be used. | | OkHttpDataSource.Factory | setUserAgent​(String userAgent) | Sets the user agent that will be used. |

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

- 

Factory

public Factory​(okhttp3.Call.Factory callFactory)

Creates an instance. Parameters:callFactory - A Call.Factory (typically an OkHttpClient) for use by the sources created by the factory.

Method Detail

- 

setDefaultRequestProperties

@CanIgnoreReturnValue
public final[OkHttpDataSource.Factory](OkHttpDataSource.Factory.html "class in com.google.android.exoplayer2.ext.okhttp")setDefaultRequestProperties​([Map](https://developer.android.com/reference/java/util/Map.html "class or interface in java.util")<[String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang"),​[String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang")> defaultRequestProperties)

Description copied from interface: HttpDataSource.Factory

Sets the default request headers for HttpDataSource instances created by the factory.

The new request properties will be used for future requests made by HttpDataSources created by the factory, including instances that have already been created. Modifying the defaultRequestProperties map after a call to this method will have no effect, and so it's necessary to call this method again each time the request properties need to be updated.

Specified by:setDefaultRequestProperties in interface HttpDataSource.FactoryParameters:defaultRequestProperties - The default request properties.Returns:This factory.

- 

setUserAgent

@CanIgnoreReturnValue
public[OkHttpDataSource.Factory](OkHttpDataSource.Factory.html "class in com.google.android.exoplayer2.ext.okhttp")setUserAgent​(@Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")userAgent)

Sets the user agent that will be used.

The default is null, which causes the default user agent of the underlying OkHttpClient to be used.

Parameters:userAgent - The user agent that will be used, or null to use the default user agent of the underlying OkHttpClient.Returns:This factory.

- 

setCacheControl

@CanIgnoreReturnValue
public[OkHttpDataSource.Factory](OkHttpDataSource.Factory.html "class in com.google.android.exoplayer2.ext.okhttp")setCacheControl​(@Nullable
                                                okhttp3.CacheControl cacheControl)

Sets the CacheControl that will be used.

The default is null.

Parameters:cacheControl - The cache control that will be used.Returns:This factory.

- 

setContentTypePredicate

@CanIgnoreReturnValue
public[OkHttpDataSource.Factory](OkHttpDataSource.Factory.html "class in com.google.android.exoplayer2.ext.okhttp")setContentTypePredicate​(@Nullable[Predicate](https://guava.dev/releases/31.1-android/api/docs/com/google/common/base/Predicate.html?is-external=true "class or interface in com.google.common.base")<[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")> contentTypePredicate)

Sets a content type Predicate. If a content type is rejected by the predicate then a HttpDataSource.InvalidContentTypeException is thrown from OkHttpDataSource.open(DataSpec).

The default is null.

Parameters:contentTypePredicate - The content type Predicate, or null to clear a predicate that was previously set.Returns:This factory.

- 

setTransferListener

@CanIgnoreReturnValue
public[OkHttpDataSource.Factory](OkHttpDataSource.Factory.html "class in com.google.android.exoplayer2.ext.okhttp")setTransferListener​(@Nullable[TransferListener](../../upstream/TransferListener.html "interface in com.google.android.exoplayer2.upstream")transferListener)

Sets the TransferListener that will be used.

The default is null.

See DataSource.addTransferListener(TransferListener).

Parameters:transferListener - The listener that will be used.Returns:This factory.

- 

createDataSource

public[OkHttpDataSource](OkHttpDataSource.html "class in com.google.android.exoplayer2.ext.okhttp")createDataSource()

Description copied from interface: DataSource.Factory

Creates a DataSource instance. Specified by:createDataSource in interface DataSource.FactorySpecified by:createDataSource in interface HttpDataSource.Factory