Fix: Player progress bar freezes on Bluetooth#278
Conversation
The UI progress slider (`WavySlider`) would get stuck at the beginning of the track (0:00) when audio playback was routed through a Bluetooth device. The root cause was a desynchronization between the `MediaSession` and the `MediaController` after an audio output change. The `MediaController` was repeatedly querying a stale position, which remained at 0. To resolve this, a more direct and robust progress reporting mechanism has been implemented: 1. A custom `SessionCommand` (`GET_POSITION`) has been added to `MusicService.kt`. This command allows the `PlayerViewModel` to directly query the `ExoPlayer` instance's current position, bypassing any potential state desynchronization. 2. The `startProgressUpdates` loop in `PlayerViewModel.kt` has been modified to use this custom command, ensuring the UI always reflects the true playback position. 3. The `DualPlayerEngine`'s extension renderer mode has been set to `PREFER` to improve stability.
There was a problem hiding this comment.
💡 Codex Review
https://github.com/theovilardo/PixelPlay/blob/ab83d9da8772b6075a7cb50e0c9e7e92aff41183/app/src/main/java/com/theveloper/pixelplay/presentation/viewmodel/PlayerViewModel.kt#L2133-L2134
Import classes used in progress polling command
startProgressUpdates now references SessionCommand and Bundle.EMPTY, but this file does not import either symbol. The compiler will fail with unresolved references when building PlayerViewModel. Add import androidx.media3.session.SessionCommand and import android.os.Bundle (or use fully-qualified names) so the app can compile.
https://github.com/theovilardo/PixelPlay/blob/ab83d9da8772b6075a7cb50e0c9e7e92aff41183/app/src/main/java/com/theveloper/pixelplay/data/service/MusicService.kt#L92-L105
Expose custom command to controllers
MusicService handles CUSTOM_COMMAND_GET_POSITION in onCustomCommand, but the service never advertises this custom command in onConnect. Without adding it to the session’s available command group, MediaController.sendCustomCommand will return RESULT_ERROR_NOT_SUPPORTED and the progress polling in PlayerViewModel will never receive a position update. Add the command in onConnect when constructing the MediaSession so controllers are permitted to call it.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The UI progress slider (
WavySlider) would get stuck at the beginning of the track (0:00) when audio playback was routed through a Bluetooth device.The root cause was a desynchronization between the
MediaSessionand theMediaControllerafter an audio output change. TheMediaControllerwas repeatedly querying a stale position, which remained at 0.To resolve this, a more direct and robust progress reporting mechanism has been implemented:
SessionCommand(GET_POSITION) has been added toMusicService.kt. This command allows thePlayerViewModelto directly query theExoPlayerinstance's current position, bypassing any potential state desynchronization.startProgressUpdatesloop inPlayerViewModel.kthas been modified to use this custom command, ensuring the UI always reflects the true playback position.DualPlayerEngine's extension renderer mode has been set toPREFERto improve stability.