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 899ba57..8152735 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 b43339c..c661dea 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt @@ -202,9 +202,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() }