fix: register session with addSession() to activate Media3 notifications
MediaSessionService only sets up its internal MediaNotificationManager when addSession() is called. This normally happens when a MediaController binds, but since we use custom intents, no controller ever connected. Calling addSession() after session creation activates the notification pipeline. Also removed debug logging. Made-with: Cursor
This commit is contained in:
@@ -59,8 +59,8 @@ class ConnectionFailedException(cause: Throwable) : Exception("Connection failed
|
||||
class RadioPlaybackService : MediaLibraryService() {
|
||||
companion object {
|
||||
private const val TAG = "RadioPlayback"
|
||||
private const val FOREGROUND_CHANNEL_ID = "radio_playback"
|
||||
private const val FOREGROUND_NOTIFICATION_ID = 1
|
||||
private const val FOREGROUND_CHANNEL_ID = "default_channel_id"
|
||||
private const val FOREGROUND_NOTIFICATION_ID = 1001
|
||||
const val ACTION_PLAY = "xyz.cottongin.radio247.PLAY"
|
||||
const val ACTION_STOP = "xyz.cottongin.radio247.STOP"
|
||||
const val ACTION_PAUSE = "xyz.cottongin.radio247.PAUSE"
|
||||
@@ -122,6 +122,8 @@ class RadioPlaybackService : MediaLibraryService() {
|
||||
return mediaSession
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
ensureForegroundChannel()
|
||||
@@ -130,7 +132,7 @@ class RadioPlaybackService : MediaLibraryService() {
|
||||
|
||||
private fun ensureForegroundChannel() {
|
||||
val channel = NotificationChannel(
|
||||
FOREGROUND_CHANNEL_ID, "Radio Playback", NotificationManager.IMPORTANCE_LOW
|
||||
FOREGROUND_CHANNEL_ID, "Now playing", NotificationManager.IMPORTANCE_LOW
|
||||
)
|
||||
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
|
||||
}
|
||||
@@ -333,6 +335,8 @@ class RadioPlaybackService : MediaLibraryService() {
|
||||
}
|
||||
.setCustomLayout(listOf(seekToLiveButton))
|
||||
.build()
|
||||
|
||||
addSession(mediaSession!!)
|
||||
}
|
||||
|
||||
private inner class LibrarySessionCallback : MediaLibraryService.MediaLibrarySession.Callback {
|
||||
|
||||
@@ -41,7 +41,6 @@ class RadioPlayerAdapter(
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
return SimpleBasePlayer.State.Builder()
|
||||
.setAvailableCommands(commands)
|
||||
.setPlaybackState(_playbackState)
|
||||
|
||||
Reference in New Issue
Block a user