Twelve: Generate audio session id in application
diff --git a/app/src/main/java/org/lineageos/twelve/TwelveApplication.kt b/app/src/main/java/org/lineageos/twelve/TwelveApplication.kt
index 82bc5b9..45fbeb2 100644
--- a/app/src/main/java/org/lineageos/twelve/TwelveApplication.kt
+++ b/app/src/main/java/org/lineageos/twelve/TwelveApplication.kt
@@ -6,15 +6,17 @@
package org.lineageos.twelve
import android.app.Application
+import androidx.media3.common.util.UnstableApi
+import androidx.media3.common.util.Util
import com.google.android.material.color.DynamicColors
import org.lineageos.twelve.database.TwelveDatabase
import org.lineageos.twelve.repositories.MediaRepository
-import kotlin.properties.Delegates
+@UnstableApi
class TwelveApplication : Application() {
private val database by lazy { TwelveDatabase.getInstance(applicationContext) }
val mediaRepository by lazy { MediaRepository(applicationContext, database) }
- var audioSessionId by Delegates.notNull<Int>()
+ val audioSessionId by lazy { Util.generateAudioSessionIdV21(applicationContext) }
override fun onCreate() {
super.onCreate()
diff --git a/app/src/main/java/org/lineageos/twelve/services/PlaybackService.kt b/app/src/main/java/org/lineageos/twelve/services/PlaybackService.kt
index 5b58244..d93dca5 100644
--- a/app/src/main/java/org/lineageos/twelve/services/PlaybackService.kt
+++ b/app/src/main/java/org/lineageos/twelve/services/PlaybackService.kt
@@ -20,7 +20,6 @@
import androidx.media3.common.Player
import androidx.media3.common.TrackSelectionParameters.AudioOffloadPreferences
import androidx.media3.common.util.UnstableApi
-import androidx.media3.common.util.Util
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.session.DefaultMediaNotificationProvider
import androidx.media3.session.LibraryResult
@@ -174,9 +173,7 @@
}
)
- Util.generateAudioSessionIdV21(this).let {
- exoPlayer.audioSessionId = it
- }
+ exoPlayer.audioSessionId = (application as TwelveApplication).audioSessionId
}
override fun onBind(intent: Intent?): IBinder? {
@@ -210,10 +207,6 @@
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo) = mediaLibrarySession
- override fun onAudioSessionIdChanged(audioSessionId: Int) {
- (application as TwelveApplication).audioSessionId = audioSessionId
- }
-
override fun onEvents(player: Player, events: Player.Events) {
if (events.containsAny(
Player.EVENT_PLAYBACK_STATE_CHANGED,