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 interface
DataSource.Factory
Deprecated.A factory forDataSource
instances.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
addTransferListener(TransferListener transferListener)
Deprecated.Adds aTransferListener
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 lastopen(com.google.android.exoplayer2.upstream.DataSpec)
call.Uri
getUri()
Deprecated.When the source is open, returns theUri
from which data is being read.long
open(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 aTransferListener
to 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 anIOException
is 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 position
is within the resource, but therequested length
extends 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 position
is 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 position
is greater than the length of the resource, thenopen(com.google.android.exoplayer2.upstream.DataSpec)
will throw anIOException
for 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.length
equalsC.LENGTH_UNSET
) this value is the resolved length of the request, orC.LENGTH_UNSET
if 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.DataSourceException
can 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 theUri
from which data is being read. The returnedUri
will be identical to the one passedopen(DataSpec)
in theDataSpec
unless redirection has occurred. If redirection has occurred, theUri
after redirection is returned.- Returns:
- The
Uri
from 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 IOException
Deprecated.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.
-
-