Skip to main content
Version: 11.7.0

Pass subtitle selection on to Chromecast on Android

Currently, it is intended behavior that when you start casting the player to a Chromecast device the subtitle selection setting isn't carried over. A new player is generated with the SourceConfiguration of the sender, but not any adjustments.

You can work around the default behavior by adding event listeners to the player.

The code adds an event on textTracks change. Whenever the subtitles change, this event is called and stores the current active textTrack in currentTextTrack by iterating over the textTracks array and checking whether .mode is showing. Once a Chromecast session is created, the code will check if the ID of the textTracks in the new player corresponds with the ID of the stored currentTextTrack. If so, it will activate that textTrack.

Solution

Here is how you pass the current active subtitle track to the Chromecast session:

var currentTextTrack: TextTrack? = null
val player = theoPlayerView.player
val chromecast = theoPlayerView.cast.chromecast

player.textTracks.addEventListener(TextTrackListEventTypes.TRACKLISTCHANGE) {
currentTextTrack = player.textTracks.firstOrNull { it.mode == TextTrackMode.SHOWING }
}

chromecast.addEventListener(ChromecastEventTypes.STATECHANGE) {
if (chromecast.state == PlayerCastState.CONNECTED) {
player.addEventListener(PlayerEventTypes.PLAYING) {
val tt = player.textTracks.firstOrNull { it.id == currentTextTrack?.id }
tt?.mode = TextTrackMode.SHOWING
}
}
}