Class OkHttpDataSource
- java.lang.Object
-
- com.google.android.exoplayer2.upstream.BaseDataSource
-
- com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
-
- All Implemented Interfaces:
DataReader,DataSource,HttpDataSource
@Deprecated public class OkHttpDataSource extends BaseDataSource implements HttpDataSource
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.AnHttpDataSourcethat delegates to Square'sCall.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 Class Summary
Nested Classes Modifier and Type Class Description static classOkHttpDataSource.FactoryDeprecated.DataSource.FactoryforOkHttpDataSourceinstances.-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.upstream.HttpDataSource
HttpDataSource.BaseFactory, HttpDataSource.CleartextNotPermittedException, HttpDataSource.HttpDataSourceException, HttpDataSource.InvalidContentTypeException, HttpDataSource.InvalidResponseCodeException, HttpDataSource.RequestProperties
-
-
Field Summary
-
Fields inherited from interface com.google.android.exoplayer2.upstream.HttpDataSource
REJECT_PAYWALL_TYPES
-
-
Constructor Summary
Constructors Constructor Description OkHttpDataSource(okhttp3.Call.Factory callFactory)Deprecated.UseOkHttpDataSource.Factoryinstead.OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent)Deprecated.UseOkHttpDataSource.Factoryinstead.OkHttpDataSource(okhttp3.Call.Factory callFactory, String userAgent, okhttp3.CacheControl cacheControl, HttpDataSource.RequestProperties defaultRequestProperties)Deprecated.UseOkHttpDataSource.Factoryinstead.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclearAllRequestProperties()Deprecated.Clears all request headers that were set byHttpDataSource.setRequestProperty(String, String).voidclearRequestProperty(String name)Deprecated.Clears the value of a request header.voidclose()Deprecated.Closes the source.intgetResponseCode()Deprecated.When the source is open, returns the HTTP response status code associated with the lastHttpDataSource.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 lastDataSource.open(com.google.android.exoplayer2.upstream.DataSpec)call.UrigetUri()Deprecated.When the source is open, returns theUrifrom which data is being read.longopen(DataSpec dataSpec)Deprecated.Opens the source to read the specified data.intread(byte[] buffer, int offset, int length)Deprecated.Reads up tolengthbytes of data from the input.voidsetContentTypePredicate(Predicate<String> contentTypePredicate)Deprecated.voidsetRequestProperty(String name, String value)Deprecated.Sets the value of a request header.-
Methods inherited from class com.google.android.exoplayer2.upstream.BaseDataSource
addTransferListener, bytesTransferred, transferEnded, transferInitializing, transferStarted
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.android.exoplayer2.upstream.DataSource
addTransferListener
-
-
-
-
Constructor Detail
-
OkHttpDataSource
@Deprecated public OkHttpDataSource(okhttp3.Call.Factory callFactory)
Deprecated.UseOkHttpDataSource.Factoryinstead.
-
OkHttpDataSource
@Deprecated public OkHttpDataSource(okhttp3.Call.Factory callFactory, @Nullable String userAgent)
Deprecated.UseOkHttpDataSource.Factoryinstead.
-
OkHttpDataSource
@Deprecated public OkHttpDataSource(okhttp3.Call.Factory callFactory, @Nullable String userAgent, @Nullable okhttp3.CacheControl cacheControl, @Nullable HttpDataSource.RequestProperties defaultRequestProperties)
Deprecated.UseOkHttpDataSource.Factoryinstead.
-
-
Method Detail
-
setContentTypePredicate
@Deprecated public void setContentTypePredicate(@Nullable Predicate<String> contentTypePredicate)
Deprecated.
-
getUri
@Nullable public Uri getUri()
Deprecated.Description copied from interface:DataSourceWhen the source is open, returns theUrifrom which data is being read. The returnedUriwill be identical to the one passedDataSource.open(DataSpec)in theDataSpecunless redirection has occurred. If redirection has occurred, theUriafter redirection is returned.- Specified by:
getUriin interfaceDataSource- Returns:
- The
Urifrom which data is being read, or null if the source is not open.
-
getResponseCode
public int getResponseCode()
Deprecated.Description copied from interface:HttpDataSourceWhen the source is open, returns the HTTP response status code associated with the lastHttpDataSource.open(com.google.android.exoplayer2.upstream.DataSpec)call. Otherwise, returns a negative value.- Specified by:
getResponseCodein interfaceHttpDataSource
-
getResponseHeaders
public Map<String,List<String>> getResponseHeaders()
Deprecated.Description copied from interface:DataSourceWhen the source is open, returns the response headers associated with the lastDataSource.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:
getResponseHeadersin interfaceDataSource- Specified by:
getResponseHeadersin interfaceHttpDataSource
-
setRequestProperty
public void setRequestProperty(String name, String value)
Deprecated.Description copied from interface:HttpDataSourceSets 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. SeeHttpDataSource.open(com.google.android.exoplayer2.upstream.DataSpec).- Specified by:
setRequestPropertyin interfaceHttpDataSource- Parameters:
name- The name of the header field.value- The value of the field.
-
clearRequestProperty
public void clearRequestProperty(String name)
Deprecated.Description copied from interface:HttpDataSourceClears the value of a request header. The change will apply to subsequent connections established by the source.- Specified by:
clearRequestPropertyin interfaceHttpDataSource- Parameters:
name- The name of the header field.
-
clearAllRequestProperties
public void clearAllRequestProperties()
Deprecated.Description copied from interface:HttpDataSourceClears all request headers that were set byHttpDataSource.setRequestProperty(String, String).- Specified by:
clearAllRequestPropertiesin interfaceHttpDataSource
-
open
public long open(DataSpec dataSpec) throws HttpDataSource.HttpDataSourceException
Deprecated.Description copied from interface:HttpDataSourceOpens the source to read the specified data.Note:
HttpDataSourceimplementations are advised to set request headers passed via (in order of decreasing priority) thedataSpec,HttpDataSource.setRequestProperty(java.lang.String, java.lang.String)and the default parameters set in theHttpDataSource.Factory.- Specified by:
openin interfaceDataSource- Specified by:
openin interfaceHttpDataSource- Parameters:
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.lengthequalsC.LENGTH_UNSET) this value is the resolved length of the request, orC.LENGTH_UNSETif the length is still unresolved. For all other requests, the value returned will be equal to the request'sDataSpec.length. - Throws:
HttpDataSource.HttpDataSourceException
-
read
public int read(byte[] buffer, int offset, int length) throws HttpDataSource.HttpDataSourceExceptionDeprecated.Description copied from interface:DataReaderReads up tolengthbytes of data from the input.If
readLengthis zero then 0 is returned. Otherwise, if no data is available because the end of the opened range has been reached, thenC.RESULT_END_OF_INPUTis 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:
readin interfaceDataReader- Specified by:
readin interfaceHttpDataSource- Parameters:
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_INPUTif the input has ended. This may be less thanlengthbecause 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
-
close
public void close()
Deprecated.Description copied from interface:DataSourceCloses the source. This method must be called even if the corresponding call toDataSource.open(DataSpec)threw anIOException.- Specified by:
closein interfaceDataSource- Specified by:
closein interfaceHttpDataSource
-
-