MediaByteSource

Media bytes from caller code instead of a path: the custom I/O door. A player streams through its own HTTP client with its own TLS and auth, reads from an encrypted store, a torrent, a cache, or a byte array it already holds, and FFmpeg demuxes those bytes exactly as it would a file's.

Threading and blocking. Every call arrives on the thread driving the demuxer, one call at a time, never concurrently. read MUST block until it has at least one byte; a source with nothing more to give returns -1. Failures are thrown, not encoded: any exception from these methods surfaces to FFmpeg as an I/O error on the operation that triggered the call.

Lifetime. The MediaSource opened over this owns it: close runs exactly once when that source closes, and the instance must stay valid until then.

Properties

Link copied to clipboard
open val location: String?

The address these bytes came from when that is not the address they were asked for, as after an HTTP redirect, or null, the default, when they came from that address (#167).

Link copied to clipboard
abstract val seekable: Boolean

False makes the whole input unseekable; seek is then never called.

Link copied to clipboard
abstract val size: Long?

Total size in bytes, or null when unknown (a live stream).

Functions

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
abstract fun read(into: ByteArray, offset: Int, length: Int): Int

Reads at most length bytes into into at offset, advancing the cursor.

Link copied to clipboard
abstract fun seek(position: Long)

Moves the cursor to position bytes from the start. Only called when seekable.

Link copied to clipboard
open fun takeTags(): Map<String, String>?

The tags that the bytes of the last read brought, such as the song an internet radio station names in a title block between its audio bytes, or null, the default, when that read brought none (#168).