docs/doc/reference/com/google/android/exoplayer2/ext/okhttp/OkHttpDataSource.html
Package com.google.android.exoplayer2.ext.okhttp
All Implemented Interfaces:DataReader, DataSource, HttpDataSource
[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public classOkHttpDataSourceextends[BaseDataSource](../../upstream/BaseDataSource.html "class in com.google.android.exoplayer2.upstream")implements[HttpDataSource](../../upstream/HttpDataSource.html "interface in com.google.android.exoplayer2.upstream")
Deprecated. com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.
An HttpDataSource that delegates to Square's Call.Factory.
Note: HTTP request headers will be set using all parameters passed via (in order of decreasing priority) the dataSpec, setRequestProperty(java.lang.String, java.lang.String) and the default parameters used to construct the instance.
Nested Classes | Modifier and Type | Class | Description |
| --- | --- | --- |
| static class | OkHttpDataSource.Factory |
Deprecated.
DataSource.Factory for OkHttpDataSource instances.
|
-
HttpDataSource.BaseFactory, HttpDataSource.CleartextNotPermittedException, HttpDataSource.HttpDataSourceException, HttpDataSource.InvalidContentTypeException, HttpDataSource.InvalidResponseCodeException, HttpDataSource.RequestProperties
-
REJECT_PAYWALL_TYPES
Constructors | Constructor | Description |
| --- | --- |
| OkHttpDataSource(okhttp3.Call.Factory callFactory) |
Deprecated.
Use OkHttpDataSource.Factory instead.
|
| OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent) |
Deprecated.
Use OkHttpDataSource.Factory instead.
|
| OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, okhttp3.CacheControl cacheControl, HttpDataSource.RequestProperties defaultRequestProperties) |
Deprecated.
Use OkHttpDataSource.Factory instead.
|
All Methods Instance Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| void | clearAllRequestProperties() |
Deprecated.
Clears all request headers that were set by HttpDataSource.setRequestProperty(String, String).
|
| void | clearRequestProperty(String name) |
Deprecated.
Clears the value of a request header.
|
| void | close() |
Deprecated.
Closes the source.
|
| int | getResponseCode() |
Deprecated.
When the source is open, returns the HTTP response status code associated with the last HttpDataSource.open(com.google.android.exoplayer2.upstream.DataSpec) call.
|
| Map<String,List<String>> | getResponseHeaders() |
Deprecated.
When the source is open, returns the response headers associated with the last DataSource.open(com.google.android.exoplayer2.upstream.DataSpec) call.
|
| Uri | getUri() |
Deprecated.
When the source is open, returns the Uri from which data is being read.
|
| long | open(DataSpec dataSpec) |
Deprecated.
Opens the source to read the specified data.
|
| int | read(byte[] buffer, int offset, int length) |
Deprecated.
Reads up to length bytes of data from the input.
|
| void | setContentTypePredicate(Predicate<String> contentTypePredicate) |
Deprecated.
Use OkHttpDataSource.Factory.setContentTypePredicate(Predicate) instead.
|
| void | setRequestProperty(String name, String value) |
Deprecated.
Sets the value of a request header. |
-
addTransferListener, bytesTransferred, transferEnded, transferInitializing, transferStarted
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
addTransferListener
-
[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public OkHttpDataSource(okhttp3.Call.Factory callFactory)
Deprecated.
Use OkHttpDataSource.Factory instead.
-
[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public OkHttpDataSource(okhttp3.Call.Factory callFactory,
@Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")userAgent)
Deprecated.
Use OkHttpDataSource.Factory instead.
-
[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public OkHttpDataSource(okhttp3.Call.Factory callFactory,
@Nullable[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")userAgent,
@Nullable
okhttp3.CacheControl cacheControl,
@Nullable[HttpDataSource.RequestProperties](../../upstream/HttpDataSource.RequestProperties.html "class in com.google.android.exoplayer2.upstream")defaultRequestProperties)
Deprecated.
Use OkHttpDataSource.Factory instead.
-
[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public void 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)
Deprecated.
Use OkHttpDataSource.Factory.setContentTypePredicate(Predicate) instead.
-
@Nullable
public[Uri](https://developer.android.com/reference/android/net/Uri.html "class or interface in android.net")getUri()
Deprecated.
Description copied from interface: DataSource
When the source is open, returns the Uri from which data is being read. The returned Uri will be identical to the one passed DataSource.open(DataSpec) in the DataSpec unless redirection has occurred. If redirection has occurred, the Uri after redirection is returned.
Specified by:getUri in interface DataSourceReturns:The Uri from which data is being read, or null if the source is not open.
-
public int getResponseCode()
Deprecated.
Description copied from interface: HttpDataSource
When the source is open, returns the HTTP response status code associated with the last HttpDataSource.open(com.google.android.exoplayer2.upstream.DataSpec) call. Otherwise, returns a negative value.
Specified by:getResponseCode in interface HttpDataSource
-
public[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"),[List](https://developer.android.com/reference/java/util/List.html?is-external=true "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")>> getResponseHeaders()
Deprecated.
Description copied from interface: DataSource
When the source is open, returns the response headers associated with the last DataSource.open(com.google.android.exoplayer2.upstream.DataSpec) call. Otherwise, returns an empty map.
Key look-up in the returned map is case-insensitive.
Specified by:getResponseHeaders in interface DataSourceSpecified by:getResponseHeaders in interface HttpDataSource
-
public void setRequestProperty([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")name,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")value)
Deprecated.
Description copied from interface: HttpDataSource
Sets the value of a request header. The value will be used for subsequent connections established by the source.
Note: If the same header is set as a default parameter in the HttpDataSource.Factory, then the header value set with this method should be preferred when connecting with the data source. See HttpDataSource.open(com.google.android.exoplayer2.upstream.DataSpec).
Specified by:setRequestProperty in interface HttpDataSourceParameters:name - The name of the header field.value - The value of the field.
-
public void clearRequestProperty([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")name)
Deprecated.
Description copied from interface: HttpDataSource
Clears the value of a request header. The change will apply to subsequent connections established by the source.
Specified by:clearRequestProperty in interface HttpDataSourceParameters:name - The name of the header field.
-
public void clearAllRequestProperties()
Deprecated.
Description copied from interface: HttpDataSource
Clears all request headers that were set by HttpDataSource.setRequestProperty(String, String).
Specified by:clearAllRequestProperties in interface HttpDataSource
-
public long open([DataSpec](../../upstream/DataSpec.html "class in com.google.android.exoplayer2.upstream")dataSpec)
throws[HttpDataSource.HttpDataSourceException](../../upstream/HttpDataSource.HttpDataSourceException.html "class in com.google.android.exoplayer2.upstream")
Deprecated.
Description copied from interface: HttpDataSource
Opens the source to read the specified data.
Note: HttpDataSource implementations are advised to set request headers passed via (in order of decreasing priority) the dataSpec, HttpDataSource.setRequestProperty(java.lang.String, java.lang.String) and the default parameters set in the HttpDataSource.Factory.
Specified by:open in interface DataSourceSpecified by:open in interface HttpDataSourceParameters:dataSpec - Defines the data to be read.Returns:The number of bytes that can be read from the opened source. For unbounded requests (i.e., requests where DataSpec.length equals C.LENGTH_UNSET) this value is the resolved length of the request, or C.LENGTH_UNSET if the length is still unresolved. For all other requests, the value returned will be equal to the request's DataSpec.length.Throws:HttpDataSource.HttpDataSourceException
-
public int read(byte[] buffer,
int offset,
int length)
throws[HttpDataSource.HttpDataSourceException](../../upstream/HttpDataSource.HttpDataSourceException.html "class in com.google.android.exoplayer2.upstream")
Deprecated.
Description copied from interface: DataReader
Reads up to length bytes of data from the input.
If readLength is zero then 0 is returned. Otherwise, if no data is available because the end of the opened range has been reached, then C.RESULT_END_OF_INPUT is returned. Otherwise, the call will block until at least one byte of data has been read and the number of bytes read is returned.
Specified by:read in interface DataReaderSpecified by:read in interface HttpDataSourceParameters:buffer - A target array into which data should be written.offset - The offset into the target array at which to write.length - The maximum number of bytes to read from the input.Returns:The number of bytes read, or C.RESULT_END_OF_INPUT if the input has ended. This may be less than length because the end of the input (or available data) was reached, the method was interrupted, or the operation was aborted early for another reason.Throws:HttpDataSource.HttpDataSourceException
-
public void close()
Deprecated.
Description copied from interface: DataSource
Closes the source. This method must be called even if the corresponding call to DataSource.open(DataSpec) threw an IOException.
Specified by:close in interface DataSourceSpecified by:close in interface HttpDataSource