CastConnector

interface CastConnector

SPI for Chromecast support (sender side). Apps construct a connector from the cast module (OGCastConnector) and pass it to OGPlayer.Builder.setCastConnector. When a cast session starts, the player hands playback off to the receiver at the current position and takes it back when the session ends — listeners and UI keep working.

The SDK is a Cast sender only: what plays on the receiver (DRM, ads, custom UI) is defined by the receiver application. By default Google's default media receiver is used; apps with their own hosted Web Receiver configure its ID via the cast module.

Properties

Link copied to clipboard

Whether a cast session is already active — one that started before this player existed (a second screen of the app while casting). The player then hands playback to the receiver straight away instead of waiting for a session change that never comes. Default false.

Functions

Link copied to clipboard
abstract fun createCastPlayer(listener: CastSessionListener): Any?

Creates the cast playback engine (androidx.media3.cast.CastPlayer), reporting session availability through listener. Returns null when cast is unavailable on this device (e.g. missing Play Services).

Link copied to clipboard
abstract fun release()

Releases every cast resource this connector holds. Called from OGPlayer.release() when the player never got a CastPlayer, and by hosts tearing the connector down themselves.

Link copied to clipboard
open fun releaseCastPlayer(castPlayer: Any)

Releases the resources this connector created for ONE player — the object createCastPlayer returned for it. Called from OGPlayer.release() so that a connector shared by several players (a second screen, a feed) outlives the first player to go: releasing everything there would take the other players' live CastPlayer, session listener and cast-state listener with it.

Link copied to clipboard
open fun showCastDialog(context: Context)

Opens the Cast device picker (device scanning happens inside the dialog); when a session is already active, shows the session controller for disconnecting instead. The player's built-in controls call this from the cast button.