docs/doc/reference/com/google/android/exoplayer2/upstream/DataSource.html
Package com.google.android.exoplayer2.upstream
DataReaderAll Known Subinterfaces:HttpDataSourceAll 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](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public interfaceDataSourceextends[DataReader](DataReader.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.
Reads data from URI-identified resources.
Nested Classes | Modifier and Type | Interface | Description |
| --- | --- | --- |
| static interface | DataSource.Factory |
Deprecated.
A factory for DataSource instances.
|
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| void | addTransferListener(TransferListener transferListener) |
Deprecated.
Adds a TransferListener to listen to data transfers.
|
| void | close() |
Deprecated.
Closes the source.
|
| default Map<String,List<String>> | getResponseHeaders() |
Deprecated.
When the source is open, returns the response headers associated with the last 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. |
-
read
-
void addTransferListener([TransferListener](TransferListener.html "interface in com.google.android.exoplayer2.upstream")transferListener)
Deprecated.
Adds a TransferListener to listen to data transfers. This method is not thread-safe.
Parameters:transferListener - A TransferListener.
-
long open([DataSpec](DataSpec.html "class in com.google.android.exoplayer2.upstream")dataSpec)
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Deprecated.
Opens the source to read the specified data. If an IOException is thrown, callers must still call close() to ensure that any partial effects of the invocation are cleaned up.
The following edge case behaviors apply:
- If the [`requested position`](DataSpec.html#position) is within the resource, but the [`requested length`](DataSpec.html#length) extends beyond the end of the resource, then [`open(com.google.android.exoplayer2.upstream.DataSpec)`](#open(com.google.android.exoplayer2.upstream.DataSpec)) will succeed and data from the requested position to the end of the resource will be made available through [`DataReader.read(byte[], int, int)`](DataReader.html#read(byte%5B%5D,int,int)).
- If the [`requested position`](DataSpec.html#position) is equal to the length of the resource, then [`open(com.google.android.exoplayer2.upstream.DataSpec)`](#open(com.google.android.exoplayer2.upstream.DataSpec)) will succeed, and [`DataReader.read(byte[], int, int)`](DataReader.html#read(byte%5B%5D,int,int)) will immediately return [`C.RESULT_END_OF_INPUT`](../C.html#RESULT_END_OF_INPUT).
- If the [`requested position`](DataSpec.html#position) is greater than the length of the resource, then [`open(com.google.android.exoplayer2.upstream.DataSpec)`](#open(com.google.android.exoplayer2.upstream.DataSpec)) will throw an [`IOException`](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io") for which [`DataSourceException.isCausedByPositionOutOfRange(java.io.IOException)`](DataSourceException.html#isCausedByPositionOutOfRange(java.io.IOException)) will be `true`.
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.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:IOException - If an error occurs opening the source. DataSourceException can be thrown or used as a cause of the thrown exception to specify the reason of the error.
-
@Nullable[Uri](https://developer.android.com/reference/android/net/Uri.html "class or interface in android.net")getUri()
Deprecated.
When the source is open, returns the Uri from which data is being read. The returned Uri will be identical to the one passed open(DataSpec) in the DataSpec unless redirection has occurred. If redirection has occurred, the Uri after redirection is returned.
Returns:The Uri from which data is being read, or null if the source is not open.
-
default[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.
When the source is open, returns the response headers associated with the last open(com.google.android.exoplayer2.upstream.DataSpec) call. Otherwise, returns an empty map.
Key look-up in the returned map is case-insensitive.
-
void close()
throws[IOException](https://developer.android.com/reference/java/io/IOException.html "class or interface in java.io")
Deprecated.
Closes the source. This method must be called even if the corresponding call to open(DataSpec) threw an IOException.
Throws:IOException - If an error occurs closing the source.