API reference

VideoPlayer Class

Modifiers: final
Controls video playback on a wearable display.
Create a VideoPlayer with a VideoSource and VideoCodec, then pass it to ContentScope.video inside Display.sendContent. The player is bound to the display when the content is sent. After sending, call VideoPlayer.play to start playback.
Observe VideoPlayer.state for playback lifecycle changes and VideoPlayer.error for any failures.
Example:
val player = VideoPlayer(
    source = VideoSource.Url("https://example.com/video.mp4"),
    codec = VideoCodec.MP4,
)
// Observe state changes
scope.launch {
    player.state.collect { state ->
        when (state) {
            VideoPlayerState.PLAYING -> showPlayingUI()
            VideoPlayerState.ENDED -> showCompletedUI()
            else -> { /* handle other states */}
        }
    }
}
// Send content and start playback
display.sendContent { video(player = player) }
player.play()

See Also

Signature

class VideoPlayer(val source: VideoSource, val codec: VideoCodec)

Constructors

VideoPlayer ( source , codec )
Signature
constructor(source: VideoSource, codec: VideoCodec)
Parameters
source: VideoSource  The video data source (URL, byte array, or stream).
codec: VideoCodec  The codec format of the video data.

Properties

codec : VideoCodec
[Get]
The codec format of the video data.
Signature
val codec: VideoCodec
error : StateFlow<VideoPlayerError?>
[Get]
The most recent error, or null if no error has occurred.
Collect this flow to react to playback errors. The value is reset to null when a new playback operation starts successfully.
Signature
val error: StateFlow<VideoPlayerError?>
source : VideoSource
[Get]
The video data source (URL, byte array, or stream).
Signature
val source: VideoSource
state : StateFlow<VideoPlayerState>
[Get]
The current playback state of this player.
State transitions:
  • IDLE -> STARTING -> PLAYING (when playback begins)
  • PLAYING -> PAUSE (when playback is paused)
  • PLAYING -> ENDED (when playback completes)
  • Any state -> IDLE (on VideoPlayer.close)
Signature
val state: StateFlow<VideoPlayerState>

Methods

close ()
Stops playback and releases resources associated with this player.
After calling close(), the player transitions to VideoPlayerState.IDLE. This is a terminal state — the player cannot be restarted. Create a new VideoPlayer instance for subsequent playback.
Signature
fun close()
play ()
Starts video playback on the wearable display.
The player must first be bound to a display by passing it to video() inside sendContent. Calling play() before binding emits VideoPlayerError.NOT_BOUND.
Signature
fun play()