From e823f2fcee0cc6f157dc8e95bb47b6c623a5ef8f Mon Sep 17 00:00:00 2001 From: Hawk <28853569+WebF1yin@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:57:23 -0800 Subject: [PATCH] Autoplay waits until the music can reach the car, so a song started on connect no longer loses its first seconds to the capture consent Co-Authored-By: Claude Opus 5.5 --- .../app/seb3thehacker/gearslip/car/CarHomeScreen.kt | 4 +++- .../app/seb3thehacker/gearslip/car/CarServices.kt | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarHomeScreen.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarHomeScreen.kt index b60ee0d..0f1fbff 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarHomeScreen.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarHomeScreen.kt @@ -26,6 +26,7 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.vectorResource import android.support.v4.media.session.PlaybackStateCompat import app.seb3thehacker.gearslip.R +import app.seb3thehacker.gearslip.audio.CarAudio import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -82,9 +83,10 @@ fun CarHome() { val navStatus by CarServices.nav.status.collectAsStateWithLifecycle() val phase by CarServices.media.phase.collectAsStateWithLifecycle() val now by CarServices.media.now.collectAsStateWithLifecycle() + val capture by CarAudio.capture.collectAsStateWithLifecycle() LaunchedEffect(Unit) { CarServices.autostart(frame) } - LaunchedEffect(phase) { if (phase == CarMedia.Phase.READY) CarServices.autoplayIfDue() } + LaunchedEffect(phase, capture) { if (phase == CarMedia.Phase.READY) CarServices.autoplayIfDue() } val navigator = LocalCarNavigator.current val panel = navigator.sidePanel diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt index f92f993..51e3541 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt @@ -195,9 +195,18 @@ object CarServices { stillPlaying = null } - /** Called once the media app is connected: starts playback if that was asked for. */ + /** + * Called once the media app is connected, and again once the music can reach the car: starts + * playback if that was asked for. Not before the capture is on, when the music goes through + * Gearslip: a song started while the consent dialog was still up lost its first seconds. + */ fun autoplayIfDue() { if (!autoplayPending) return + if (CarSettings.pipesNow && CarAudio.capture.value != CarAudio.Capture.ON) { + // Refused: no music for this drive, and none later from a capture the driver starts. + if (CarAudio.capture.value == CarAudio.Capture.DENIED) autoplayPending = false + return + } autoplayPending = false if (!media.now.value.playing) media.togglePlay() }