Skip to content

Casting

// Chromecast via the ogplayer-cast module (Media3 CastPlayer under the hood)
val player = OGPlayer.Builder(context)
.setCastConnector(
OGCastConnector(context) {
mapOf("platform" to "android", "playSessionId" to sessionId) // customData
},
)
.build()
// chrome: setShowCastButton(true) is the default; position via setCastButtonSlot(...)

The connector uses your receiver app id from the manifest (com.ogplayer.cast.RECEIVER_APP_ID), falling back to Google’s default media receiver. If Play Services is unavailable, casting simply disappears — no crash, no dialog.

HLS segment format: the receiver cannot detect the segment container and assumes MPEG-TS unless told otherwise — with CMAF/fMP4 packaging it would buffer forever. OGPlayer declares fMP4 by default (the packaging the SDK recommends everywhere); if your HLS uses TS segments, pass OGCastConnector(context, hlsSegmentFormat = CastHlsSegmentFormat.TS).

Connection state: player.castState reports NO_DEVICES / NOT_CONNECTED / CONNECTING / CONNECTED (also via PlaybackListener.onCastStateChanged), player.castDeviceName names the receiver, and player.isCasting says who is playing. The chrome reacts on its own: the cast icon pulses while connecting and switches to a connected glyph once live (override with setCastConnectedIcon(...)), and the player surface shows a “Casting to …” device layer while the TV has the video — with the controls still live, driving the receiver (play, pause, seek).

Session lifecycle: playback hands off at the current position when the session connects, events (onStateChanged, onProgress, buffering) follow whichever engine is actually playing, and on disconnect playback returns to the device at the receiver’s last position. Tapping the cast button during a session opens the standard Cast controller dialog (volume, device, stop).

One behavioral note for ad integrations: starting a cast session ends a slot-ad (FreeWheel) session on Android — ads don’t follow onto the TV.