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() {
|
class RadioPlaybackService : MediaLibraryService() {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "RadioPlayback"
|
private const val TAG = "RadioPlayback"
|
||||||
private const val FOREGROUND_CHANNEL_ID = "radio_playback"
|
private const val FOREGROUND_CHANNEL_ID = "default_channel_id"
|
||||||
private const val FOREGROUND_NOTIFICATION_ID = 1
|
private const val FOREGROUND_NOTIFICATION_ID = 1001
|
||||||
const val ACTION_PLAY = "xyz.cottongin.radio247.PLAY"
|
const val ACTION_PLAY = "xyz.cottongin.radio247.PLAY"
|
||||||
const val ACTION_STOP = "xyz.cottongin.radio247.STOP"
|
const val ACTION_STOP = "xyz.cottongin.radio247.STOP"
|
||||||
const val ACTION_PAUSE = "xyz.cottongin.radio247.PAUSE"
|
const val ACTION_PAUSE = "xyz.cottongin.radio247.PAUSE"
|
||||||
@@ -122,6 +122,8 @@ class RadioPlaybackService : MediaLibraryService() {
|
|||||||
return mediaSession
|
return mediaSession
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
ensureForegroundChannel()
|
ensureForegroundChannel()
|
||||||
@@ -130,7 +132,7 @@ class RadioPlaybackService : MediaLibraryService() {
|
|||||||
|
|
||||||
private fun ensureForegroundChannel() {
|
private fun ensureForegroundChannel() {
|
||||||
val channel = NotificationChannel(
|
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)
|
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
@@ -333,6 +335,8 @@ class RadioPlaybackService : MediaLibraryService() {
|
|||||||
}
|
}
|
||||||
.setCustomLayout(listOf(seekToLiveButton))
|
.setCustomLayout(listOf(seekToLiveButton))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
addSession(mediaSession!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class LibrarySessionCallback : MediaLibraryService.MediaLibrarySession.Callback {
|
private inner class LibrarySessionCallback : MediaLibraryService.MediaLibrarySession.Callback {
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class RadioPlayerAdapter(
|
|||||||
} else {
|
} else {
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
return SimpleBasePlayer.State.Builder()
|
return SimpleBasePlayer.State.Builder()
|
||||||
.setAvailableCommands(commands)
|
.setAvailableCommands(commands)
|
||||||
.setPlaybackState(_playbackState)
|
.setPlaybackState(_playbackState)
|
||||||
|
|||||||
Reference in New Issue
Block a user