KitePlayerWorker
A player that runs in a Web Worker, so the page's own thread stays free while it opens, decodes and draws (#100).
val player = KitePlayerWorker.start(canvas)
player.open(MediaItem("https://example.com/movie.mp4"))
button.onclick = { player.play() }The worker holds the engine, the codec module, the libass module and the readers. The page keeps only what a worker cannot have: the audio device, whose sound goes from the worker to the device without passing through the page, and the canvas, whose drawing is handed to the worker. Frames, sound and subtitles never cross between the two threads; commands and state do.
An http, https or blob item plays here, read with range requests that only a worker may make. The page's own KitePlayer cannot open one. A relative address, of an item or of one of its subtitles, is read against the page's.
The same calls as KitePlayer
Every member below has the name, the parameters, the defaults and the meaning of the KitePlayer member of the same name, and a call that fails throws what KitePlayer would throw: PlaybackException, IllegalArgumentException, IllegalStateException or UnsupportedOperationException. state, progress, stats and events carry what the worker's player publishes, and state.media and state.queue hold the items this facade was given rather than copies of them.
Two differences come from the thread between the page and the player:
A setter, such as setSpeed, returns at once and is checked by the player in the worker, so the rule is written once. A value the player refuses does not throw at the call, as it does on
KitePlayer: it arrives on events as PlaybackWarning.CommandRefused, naming the setter. That warning is not in warningHistory, which is the worker player's own.diagnosticsDump, supportBundle and warningHistory ask the worker, so they suspend.
What does not cross
subtitleCues: the worker draws the subtitles on the canvas itself.coverArt: the media session of the page's own player shows it, and a worker has none.position()andaudioClock(): read progress instead.transportMarkandawaitClose.inspect,scanAudio,captureFrame,thumbnailAt, recording,mementoandrestore.Attaching or detaching a renderer or an audio tap, and
setExternalClock.An item, or an external subtitle or a thumbnail file, with its own reader: it is refused with PlaybackError.ConfigurationInvalid. Give it an address instead.
A
PlayerConfig: the worker builds its player on the default one.
The page's own KitePlayer is unchanged and stays the web default.
Properties
What happened in the player. A worker that dies sends PlayerEvent.Failed from here, and a setter the player refused sends PlaybackWarning.CommandRefused.
The player's state, as the worker last sent it. Position is not in it; see progress.
Diagnostics, as the worker last sent them, once a second by default.
Functions
Loads a subtitle file, selects it, and returns its id once it is showing. source needs an address: one with its own reader is refused with PlaybackError.ConfigurationInvalid.
Inserts one item. See the list overload.
Removes every queue item except the one playing.
Asks the worker to close the player and end, and returns at once. The worker ends when the player has closed. closeAndAwait waits for that.
close, returning once the worker has closed the player and ended.
The worker player's diagnostics dump.
Seeks to the start of the next chapter. The worker reads the position, so it is exact.
Picture in picture for the canvas this player draws on, or null when it was started without one or this browser has neither feature KitePlayerPictureInPicture uses. The canvas belongs to the worker, and both features still carry its frames: the document window takes the page's canvas element, and the video element's window plays a live capture of it. Its play and pause buttons play and pause this player. Call start from the viewer's click, as there.
Seeks to the start of this chapter, or the one before within its first three seconds.
Reads an external subtitle track's file again in encoding, or decided from its bytes for null, as KitePlayer.reloadExternalSubtitle does, and returns once the new reading shows.
Removes the queue item at index.
Asks for a seek and returns at once, for a seek bar being dragged.
Seeks to the start of chapter index.
Plays the channel numbered number of the tracks' programmes, or lets the player choose with null.
Shows a second subtitle track at the top of the picture, or clears it with null.
Selects a track, or deselects the kind with a null track, and says what happened.
Plays the variant at index of the tracks' variants, or lets the player choose with null.
Delays the sound against the picture.
Sets the stereo balance.
Raises or lowers the dialogue in a downmix, in decibels (#442).
Lowers the sound by level without touching the volume.
Sets the ten-band equaliser.
Draws only the forced pictures of a Blu-ray or DVD subtitle track, or every picture again.
Sets how HDR video reaches the screen.
Chooses which keyframe a SeekMode.Keyframe seek lands on; see KitePlayer.setKeyframeChoice.
Sets the positions to announce with PlayerEvent.MarkerReached.
Turns the night mode on or off (#442).
Chooses whether setSpeed keeps pitch.
Sets how much work the renderer spends on the picture.
Plays the queue in a shuffled order, or in the order it was given.
Shortens the silent stretches of a podcast or an audiobook (#429).
Stops playback later, fading the sound down first. Null cancels an armed timer.
Sets what the two front speakers play (#462).
Shifts subtitle timing. Positive shows cues later.
Moves the subtitles up the screen.
Keeps subtitles inside the safe area of the output.
Scales subtitle text over the authored size.
Overrides the authored subtitle style, or clears the override with null.
Sets the live picture controls.
Parks or resumes video decoding in place.
Sets how the picture occupies the canvas.
Sets the framing controls.
Steps a paused player by exactly one decoded frame.
The worker player's support bundle.
The worker player's last warnings, oldest first.