Skip to content

Cast synchronize tracks#1151

Merged
StaehliJ merged 7 commits into928-custom-castplayerfrom
cast-synchronize-tracks
Sep 1, 2025
Merged

Cast synchronize tracks#1151
StaehliJ merged 7 commits into928-custom-castplayerfrom
cast-synchronize-tracks

Conversation

@StaehliJ
Copy link
Contributor

Pull request

Description

The goal of this PR is to help integrators to managed transition between local and remote playback. The audio and text track selection can be transferred between remote and local. The current default behavior tries to select the first track that matches the same language.

Changes made

  • Introduction of CastPlayerSynchronizer that handle the transition between remote and local player.
  • Introduction of PlayerSynchronizer to customize player states when the transition occured.

Checklist

  • APIs have been properly documented (if relevant).
  • The documentation has been updated (if relevant).
  • New unit tests have been written (if relevant).
  • The demo has been updated (if relevant).

@StaehliJ StaehliJ linked an issue Aug 29, 2025 that may be closed by this pull request
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Pillarbox Aug 29, 2025
@StaehliJ StaehliJ requested a review from MGaetan89 August 29, 2025 08:31
@StaehliJ StaehliJ changed the base branch from main to 928-custom-castplayer August 29, 2025 09:45
Copy link
Contributor

@MGaetan89 MGaetan89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor suggestions, but looks good to me otherwise 👍🏻

import ch.srgssr.pillarbox.demo.ui.player.DemoPlayerView
import ch.srgssr.pillarbox.demo.ui.player.playlist.PlaylistView
import ch.srgssr.pillarbox.ui.exoplayer.ExoPlayerView
import androidx.compose.ui.graphics.Color as ComposeColor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we don't use android.graphics.Color anymore, you can remove the alias here.

.map { if (it) castPlayer else localPlayer }
.distinctUntilChanged()
.onEach { switchPlayer(it) }
.stateIn(coroutineScope, SharingStarted.Companion.WhileSubscribed(5_000), if (castContext.isConnected()) castPlayer else localPlayer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.stateIn(coroutineScope, SharingStarted.Companion.WhileSubscribed(5_000), if (castContext.isConnected()) castPlayer else localPlayer)
.stateIn(coroutineScope, SharingStarted.WhileSubscribed(5_000), if (castContext.isConnected()) castPlayer else localPlayer)

private fun switchPlayer(player: PillarboxPlayer) {
val oldPlayer = if (player is PillarboxCastPlayer) localPlayer else castPlayer
if (oldPlayer == player || (oldPlayer == localPlayer && oldPlayer.playbackState == Player.STATE_IDLE)) return
val selectedAudio = oldPlayer.currentTracks.audioTracks.firstOrNull { it.isSelected }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val selectedAudio = oldPlayer.currentTracks.audioTracks.firstOrNull { it.isSelected }
val selectedAudioTrack = oldPlayer.currentTracks.audioTracks.firstOrNull { it.isSelected }

@github-actions
Copy link

github-actions bot commented Aug 29, 2025

Code Coverage

Overall Project 46.81% -0.72% 🟢
Files changed 0% 🟢

Module Coverage
:pillarbox-cast 29.06% -6.54% 🟢
Files
Module File Coverage
:pillarbox-cast CastPlayerSynchronizer.kt 0% 🟢

@StaehliJ StaehliJ merged commit 52cb6f2 into 928-custom-castplayer Sep 1, 2025
28 of 30 checks passed
@StaehliJ StaehliJ deleted the cast-synchronize-tracks branch September 1, 2025 07:56
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Pillarbox Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Sync audio and subtitle setting in Cast

2 participants