DataSourceCallback

Added in 1.0.0
Deprecated in 1.3.0

abstract class DataSourceCallback : Closeable


For supplying media data, implement this if your app has special requirements for the way media data is obtained.

Methods of this interface may be called on multiple different threads. There will be a thread synchronization point between each call to ensure that modifications to the state of your DataSourceCallback are visible to future calls. This means you don't need to do your own synchronization unless you're modifying the DataSourceCallback from another thread while it's being used by the media library.

Summary

Public constructors

Public functions

abstract Long

Called to get the size of the data source.

abstract Int
readAt(position: Long, buffer: ByteArray, offset: Int, size: Int)

Called to request data from the given position.

Inherited functions

From java.io.Closeable
abstract Unit

Public constructors

DataSourceCallback

Added in 1.0.0
Deprecated in 1.3.0
DataSourceCallback()

Public functions

getSize

Added in 1.0.0
Deprecated in 1.3.0
abstract fun getSize(): Long

Called to get the size of the data source.

Returns
Long

the size of data source in bytes, or -1 if the size is unknown.

Throws
java.io.IOException

on fatal errors

readAt

Added in 1.0.0
Deprecated in 1.3.0
abstract fun readAt(position: Long, buffer: ByteArray, offset: Int, size: Int): Int

Called to request data from the given position. Implementations should should write up to size bytes into buffer, and return the number of bytes written. Return 0 if size is zero (thus no bytes are read). Return -1 to indicate that end of stream is reached.

Parameters
position: Long

the position in the media item to read from.

buffer: ByteArray

the buffer to read the data into.

offset: Int

the offset within buffer to read the data into.

size: Int

the number of bytes to read.

Returns
Int

the number of bytes read, or -1 if the end of stream was reached.

Throws
java.io.IOException

on fatal errors.