OpenInterrupt

A cancel request that can reach MediaSource.open while it runs.

MediaSource.interrupt exists only on the source an open returns, so a caller could not stop an open that stalls, for example on a server that accepts the connection and then sends nothing. Create an OpenInterrupt before the open, pass it in, and call interrupt from any thread:

val cancel = OpenInterrupt()
// From another thread, when the user gives up: cancel.interrupt()
val source = MediaSource.open("http://example.com/film.mkv", emptyMap(), cancel)

The open then fails with FFmpegError.Interrupted at FFmpeg's next check. The source the open returns keeps the same request, so an interrupt after the open stops every later read, exactly like MediaSource.interrupt. A request raised before the open starts makes the open fail at once. One request may serve several opens. It is one-way: an interrupted request stays interrupted.

What it can reach: FFmpeg checks for it inside its network protocols and during stream discovery, and this library checks it between the reads of a MediaByteSource. A wait anywhere else, such as inside a caller's own MediaByteSource.read, finishes before the request is seen. On the web nothing can run while an open runs, so there the request is seen only before and after the open.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

True once interrupt was called.

Functions

Link copied to clipboard
fun interrupt()

Requests that every open and source using this request stop. Safe from any thread.