Interface DataSource
-
- All Superinterfaces:
DataReader
- All Known Subinterfaces:
HttpDataSource
- All Known Implementing Classes:
AesCipherDataSource,AssetDataSource,BaseDataSource,ByteArrayDataSource,CacheDataSource,ContentDataSource,CronetDataSource,DataSchemeDataSource,DefaultDataSource,DefaultHttpDataSource,FakeDataSource,FileDataSource,OkHttpDataSource,PlaceholderDataSource,PriorityDataSource,RawResourceDataSource,ResolvingDataSource,RtmpDataSource,StatsDataSource,TeeDataSource,UdpDataSource
@Deprecated public interface DataSource extends DataReader
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.Reads data from URI-identified resources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceDataSource.FactoryDeprecated.A factory forDataSourceinstances.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description voidaddTransferListener(TransferListener transferListener)Deprecated.Adds aTransferListenerto listen to data transfers.voidclose()Deprecated.Closes the source.default Map<String,List<String>>getResponseHeaders()Deprecated.When the source is open, returns the response headers associated with the lastopen(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.-
Methods inherited from interface com.google.android.exoplayer2.upstream.DataReader
read
-
-
-
-
Method Detail
-
addTransferListener
void addTransferListener(TransferListener transferListener)
Deprecated.Adds aTransferListenerto listen to data transfers. This method is not thread-safe.- Parameters:
transferListener- ATransferListener.
-
open
long open(DataSpec dataSpec) throws IOException
Deprecated.Opens the source to read the specified data. If anIOExceptionis thrown, callers must still callclose()to ensure that any partial effects of the invocation are cleaned up.The following edge case behaviors apply:
- If the
requested positionis within the resource, but therequested lengthextends beyond the end of the resource, thenopen(com.google.android.exoplayer2.upstream.DataSpec)will succeed and data from the requested position to the end of the resource will be made available throughDataReader.read(byte[], int, int). - If the
requested positionis equal to the length of the resource, thenopen(com.google.android.exoplayer2.upstream.DataSpec)will succeed, andDataReader.read(byte[], int, int)will immediately returnC.RESULT_END_OF_INPUT. - If the
requested positionis greater than the length of the resource, thenopen(com.google.android.exoplayer2.upstream.DataSpec)will throw anIOExceptionfor whichDataSourceException.isCausedByPositionOutOfRange(java.io.IOException)will betrue.
- 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:
IOException- If an error occurs opening the source.DataSourceExceptioncan be thrown or used as a cause of the thrown exception to specify the reason of the error.
- If the
-
getUri
@Nullable Uri getUri()
Deprecated.When the source is open, returns theUrifrom which data is being read. The returnedUriwill be identical to the one passedopen(DataSpec)in theDataSpecunless redirection has occurred. If redirection has occurred, theUriafter redirection is returned.- Returns:
- The
Urifrom which data is being read, or null if the source is not open.
-
getResponseHeaders
default Map<String,List<String>> getResponseHeaders()
Deprecated.When the source is open, returns the response headers associated with the lastopen(com.google.android.exoplayer2.upstream.DataSpec)call. Otherwise, returns an empty map.Key look-up in the returned map is case-insensitive.
-
close
void close() throws IOExceptionDeprecated.Closes the source. This method must be called even if the corresponding call toopen(DataSpec)threw anIOException.- Throws:
IOException- If an error occurs closing the source.
-
-