KitePlayerJava

A KitePlayer for a Java app, on the JVM and Android (#394).

The player speaks in coroutines and flows, and a Java app can call neither. This adds what Java lacks, beside the Kotlin API rather than instead of it:

  • addListener and removeListener, for the state, the progress, the events and the warnings, called on an Executor the app names. An Android app passes its main executor.

  • A CompletableFuture version of every call that suspends, named with Async. Cancelling the future cancels the call, as cancelling the coroutine does in Kotlin.

  • Millisecond versions of the calls that take or give a kotlin.time.Duration, which Java cannot call by name.

Everything else is on player, whose other calls Java can make directly: play(), pause(), setVolume(float) and the rest. The data the player publishes has Java names for the values a player screen reads: Progress.positionMillis, PlayerSnapshot.durationMillis, PlayerEvent.SeekCompleted.landedAtMillis and Tracks.selectedTrack. Tracks are named by their TrackInfo here, because Java cannot read or make a TrackId.

KitePlayerJava player = KitePlayerJava.create();
player.addListener(listener, ContextCompat.getMainExecutor(context));
player.openAsync(new MediaItemBuilder("https://example.com/movie.mp4").build())
.thenRun(() -> player.getPlayer().play());

This holds no state of the player's own. Every listener call comes from collecting the player's flows, and every future from launching its suspending call, so a future completes exactly once, with the answer the call gives.

Constructors

Link copied to clipboard
constructor(player: KitePlayer)

Types

Link copied to clipboard
fun interface AudioBlockSink

What scanAudioAsync hands the decoded sound to, on a background thread.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The player itself, for every call that Java can make on it directly.

Functions

Link copied to clipboard

KitePlayer.addExternalSubtitle. Completes once the file's track shows, selected; it is then the subtitle track of Tracks.selectedTrack.

Link copied to clipboard
fun addListener(listener: KitePlayerListener, executor: Executor)

Calls listener on executor with the state, the progress, the events and the warnings, until removeListener. Adding a listener that is already added does nothing.

Link copied to clipboard

KitePlayer.addToQueue with item, at index or at the end for null.

KitePlayer.addToQueue with items, at index or at the end for null.

Link copied to clipboard

KitePlayer.attachRendererAndAwait.

Link copied to clipboard

KitePlayer.awaitClose. Completes once the player is asked to close, by anyone.

Link copied to clipboard

KitePlayer.captureFrame.

Link copied to clipboard
fun chapterAt(positionMillis: Long): Chapter?

KitePlayer.chapterAt the position positionMillis.

Link copied to clipboard

KitePlayer.clearQueue.

Link copied to clipboard
open override fun close()

KitePlayer.close: asks the player to close and returns at once. closeAsync completes when it has. Listeners stay until removeListener, so they hear the closing state.

Link copied to clipboard

KitePlayer.closeAndAwait. Completes once the player has closed and released everything.

Link copied to clipboard

KitePlayer.inspect.

Link copied to clipboard

KitePlayer.moveInQueue.

Link copied to clipboard

KitePlayer.next.

Link copied to clipboard

KitePlayer.nextChapter.

Link copied to clipboard

KitePlayer.open. Completes once media is open and paused on its first frame.

Link copied to clipboard

KitePlayer.openQueue.

Link copied to clipboard

KitePlayer.position, in milliseconds.

Link copied to clipboard

KitePlayer.previous.

Link copied to clipboard

KitePlayer.previousChapter.

Link copied to clipboard

KitePlayer.reloadExternalSubtitle: reads the file of track again, in encoding, or by the guess for null. Completes once the track holds the new reading, in the same place and with the same selection.

Link copied to clipboard

KitePlayer.removeFromQueue.

Link copied to clipboard

Stops calling listener. Calls already handed to its executor are dropped; one that has already begun on another thread may still finish.

Link copied to clipboard
fun requestSeek(positionMillis: Long, mode: SeekMode = SeekMode.KeyframeThenRefine)

KitePlayer.requestSeek to positionMillis. Returns at once.

Link copied to clipboard

KitePlayer.restore, with a memento from KitePlayer.memento().

Link copied to clipboard
fun scanAudioAsync(media: MediaItem, track: TrackInfo?, sink: KitePlayerJava.AudioBlockSink, fromMillis: Long? = null, untilMillis: Long? = null): CompletableFuture<AudioScanResult>

KitePlayer.scanAudio: decodes the sound of track of media, or of the track an open would pick for null, from fromMillis to untilMillis, and hands it to sink. Null bounds scan from the start or to the end.

Link copied to clipboard
fun seekAsync(positionMillis: Long, mode: SeekMode = SeekMode.Precise): CompletableFuture<Void?>

KitePlayer.seek to positionMillis with mode. Completes once the player has landed there.

Link copied to clipboard

KitePlayer.seekToChapter.

Link copied to clipboard

KitePlayer.selectProgram: the channel numbered number, or the automatic choice for null.

Link copied to clipboard

KitePlayer.selectSecondarySubtitle: track, or none for null.

Link copied to clipboard

KitePlayer.selectTrack: track of kind, or none of that kind for null.

Link copied to clipboard

KitePlayer.selectVariant: the variant with index, or the automatic choice for null.

Link copied to clipboard
fun setAbLoop(aMillis: Long?, bMillis: Long? = null)

KitePlayer.setAbLoop between aMillis and bMillis. Null for A clears the loop.

Link copied to clipboard
fun setAudioDelay(millis: Long)

KitePlayer.setAudioDelay, in milliseconds.

Link copied to clipboard
fun setSleepTimer(timer: SleepTimer?, fadeMillis: Long = KitePlayer.DEFAULT_SLEEP_FADE.inWholeMilliseconds)

KitePlayer.setSleepTimer, fading for fadeMillis. Make the timer with sleepAfter, sleepAt or SleepTimer.EndOfItem.INSTANCE, or pass null to clear it.

Link copied to clipboard
fun setSubtitleDelay(millis: Long)

KitePlayer.setSubtitleDelay, in milliseconds.

Link copied to clipboard

KitePlayer.startRecording.

Link copied to clipboard
fun stepFrameAsync(direction: StepDirection = StepDirection.Forward): CompletableFuture<Void?>

KitePlayer.stepFrame.

Link copied to clipboard

KitePlayer.stop.

Link copied to clipboard

KitePlayer.stopRecording.