diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 6137c2c9..9b704ce0 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -4,6 +4,7 @@ gradle = "8.1.1"
navigation = "2.6.0"
gradlePlugin = "8.1.0"
+androidxcar = "1.2.0"
androidxcore = "1.10.1"
ktlint = "0.43.2"
ktlintGradle = "11.5.0"
@@ -49,6 +50,7 @@ kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin"
ktlintGradle = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlintGradle" }
detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
+car = { module = "androidx.car.app:app", version.ref = "androidxcar" }
core = { module = "androidx.core:core-ktx", version.ref = "androidxcore" }
design = { module = "com.google.android.material:material", version.ref = "materialDesign" }
annotations = { module = "androidx.annotation:annotation", version.ref = "androidSupport" }
@@ -103,4 +105,4 @@ apacheCodecs = { module = "commons-codec:commons-codec", version.ref
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
[plugins]
-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
\ No newline at end of file
+ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
diff --git a/ultrasonic/build.gradle b/ultrasonic/build.gradle
index 004d151c..08dd6559 100644
--- a/ultrasonic/build.gradle
+++ b/ultrasonic/build.gradle
@@ -100,6 +100,7 @@ dependencies {
exclude group: "com.android.support"
}
+ implementation libs.car
implementation libs.core
implementation libs.design
implementation libs.multidex
diff --git a/ultrasonic/src/main/AndroidManifest.xml b/ultrasonic/src/main/AndroidManifest.xml
index 711f13e2..0d25405d 100644
--- a/ultrasonic/src/main/AndroidManifest.xml
+++ b/ultrasonic/src/main/AndroidManifest.xml
@@ -12,6 +12,8 @@
+
+
= Build.VERSION_CODES.M) {
+ Timber.d("Car app library available, observing CarConnection")
+
+ val originalRepeatMode = player.repeatMode
+
+ var lastCarConnectionType = -1
+
+ CarConnection(applicationContext).type.observeForever {
+ if (lastCarConnectionType == it)
+ return@observeForever
+
+ lastCarConnectionType = it
+
+ Timber.d("CarConnection type changed to %s", it)
+
+ when (it) {
+ CarConnection.CONNECTION_TYPE_PROJECTION ->
+ if (!customRepeatModeSet) {
+ Timber.d("[CarConnection] Setting repeat mode to ALL")
+ player.repeatMode = Player.REPEAT_MODE_ALL
+ customRepeatModeSet = true
+ }
+
+ CarConnection.CONNECTION_TYPE_NOT_CONNECTED ->
+ if (customRepeatModeSet) {
+ Timber.d("[CarConnection] Resetting repeat mode")
+ player.repeatMode = originalRepeatMode
+ customRepeatModeSet = false
+ }
+ }
+ }
+ } else
+ Timber.d("Car app library not available")
+ }
+
override fun onPostConnect(session: MediaSession, controller: MediaSession.ControllerInfo) {
if (controller.controllerVersion != 0) {
// Let Media3 controller (for instance the MediaNotificationProvider)
@@ -369,6 +410,7 @@ class AutoMediaBrowserCallback : MediaLibraryService.MediaLibrarySession.Callbac
PlaybackService.CUSTOM_COMMAND_REPEAT_MODE -> {
customCommandFuture = Futures.immediateFuture(SessionResult(RESULT_SUCCESS))
+ customRepeatModeSet = true
session.player.setNextRepeatMode()
session.updateCustomCommands()