@UnstableApi
public abstract class BaseDataSource implements DataSource

Known direct subclasses
AssetDataSource

A DataSource for reading from a local asset.

ByteArrayDataSource

A DataSource for reading from a byte array.

ContentDataSource

A DataSource for reading from a content URI.

CronetDataSource

DataSource without intermediate buffer based on Cronet API set using UrlRequest.

DataSchemeDataSource

A DataSource for reading data URLs, as defined by RFC 2397.

DefaultHttpDataSource

An HttpDataSource that uses Android's HttpURLConnection.

FakeDataSource

A fake DataSource capable of simulating various scenarios.

FileDataSource

A DataSource for reading local files.

FileDescriptorDataSource

A DataSource for reading from a FileDescriptor.

HttpEngineDataSource

DataSource without intermediate buffer based on HttpEngine set using UrlRequest.

MediaDataSourceAdapter

A DataSource for reading from a MediaDataSource.

OkHttpDataSource

An HttpDataSource that delegates to Square's Call.Factory.

RawResourceDataSource

A DataSource for reading a raw resource.

RtmpDataSource

A Real-Time Messaging Protocol (RTMP) DataSource.

UdpDataSource

A UDP DataSource.


Base DataSource implementation to keep a list of TransferListeners.

Subclasses must call transferInitializing, transferStarted, bytesTransferred, and transferEnded to inform listeners of data transfers.

Summary

Protected constructors

BaseDataSource(boolean isNetwork)

Creates base data source.

Public methods

final void

Adds a TransferListener to listen to data transfers.

Protected methods

final void
bytesTransferred(int bytesTransferred)

Notifies listeners that bytes were transferred.

final void

Notifies listeners that a transfer ended.

final void

Notifies listeners that data transfer for the specified DataSpec is being initialized.

final void

Notifies listeners that data transfer for the specified DataSpec started.

Inherited methods

From androidx.media3.common.DataReader
abstract int
read(byte[] buffer, int offset, int length)

Reads up to length bytes of data from the input.

From androidx.media3.datasource.DataSource
abstract void

Closes the source.

Map<StringList<String>>

When the source is open, returns the response headers associated with the last open call.

abstract @Nullable Uri

When the source is open, returns the Uri from which data is being read.

abstract long

Opens the source to read the specified data.

Protected constructors

BaseDataSource

protected BaseDataSource(boolean isNetwork)

Creates base data source.

Parameters
boolean isNetwork

Whether the data source loads data through a network.

Public methods

addTransferListener

@UnstableApi
public final void addTransferListener(TransferListener transferListener)

Adds a TransferListener to listen to data transfers. This method is not thread-safe.

Parameters
TransferListener transferListener

A TransferListener.

Protected methods

bytesTransferred

protected final void bytesTransferred(int bytesTransferred)

Notifies listeners that bytes were transferred.

Parameters
int bytesTransferred

The number of bytes transferred since the previous call to this method (or if the first call, since the transfer was started).

transferEnded

protected final void transferEnded()

Notifies listeners that a transfer ended.

transferInitializing

protected final void transferInitializing(DataSpec dataSpec)

Notifies listeners that data transfer for the specified DataSpec is being initialized.

Parameters
DataSpec dataSpec

DataSpec describing the data for initializing transfer.

transferStarted

protected final void transferStarted(DataSpec dataSpec)

Notifies listeners that data transfer for the specified DataSpec started.

Parameters
DataSpec dataSpec

DataSpec describing the data being transferred.