-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Trying to set custom layout in the Media3 notification
Signed-off-by: Gabriel Fontán <gabilessto@gmail.com>
- Loading branch information
Showing
4 changed files
with
83 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../bobbyesp/mediaplayer/service/notifications/customLayout/MediaSessionLayoutHandlerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.bobbyesp.mediaplayer.service.notifications.customLayout | ||
|
||
import android.content.Context | ||
import androidx.core.content.ContextCompat.getString | ||
import androidx.media3.common.Player.REPEAT_MODE_ALL | ||
import androidx.media3.common.Player.REPEAT_MODE_OFF | ||
import androidx.media3.common.Player.REPEAT_MODE_ONE | ||
import androidx.media3.session.CommandButton | ||
import androidx.media3.session.MediaLibraryService | ||
import com.bobbyesp.mediaplayer.R | ||
import com.bobbyesp.mediaplayer.service.MediaLibrarySessionCallback | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.CommandToggleRepeatMode | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.CommandToggleShuffle | ||
import com.google.common.collect.ImmutableList | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import javax.inject.Inject | ||
|
||
class MediaSessionLayoutHandlerImpl @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
private val mediaSession: MediaLibraryService.MediaLibrarySession, | ||
private val mediaSessionCallback: MediaLibrarySessionCallback | ||
) : MediaSessionLayoutHandler { | ||
|
||
val commandButtons = ImmutableList.of<CommandButton>( | ||
CommandButton.Builder() | ||
.setDisplayName( | ||
getString( | ||
context, | ||
if (mediaSession.player.shuffleModeEnabled) R.string.action_shuffle_on else R.string.action_shuffle_off | ||
) | ||
) | ||
.setIconResId(if (mediaSession.player.shuffleModeEnabled) R.drawable.shuffle_on else R.drawable.shuffle) | ||
.setSessionCommand(CommandToggleShuffle).build(), | ||
CommandButton.Builder() | ||
.setDisplayName( | ||
getString( | ||
context, | ||
when (mediaSession.player.repeatMode) { | ||
REPEAT_MODE_OFF -> R.string.repeat_mode_off | ||
REPEAT_MODE_ONE -> R.string.repeat_mode_one | ||
REPEAT_MODE_ALL -> R.string.repeat_mode_all | ||
else -> throw IllegalStateException() | ||
} | ||
) | ||
).setIconResId( | ||
when (mediaSession.player.repeatMode) { | ||
REPEAT_MODE_OFF -> R.drawable.repeat | ||
REPEAT_MODE_ONE -> R.drawable.repeat_one_on | ||
REPEAT_MODE_ALL -> R.drawable.repeat_on | ||
else -> throw IllegalStateException() | ||
} | ||
).setSessionCommand(CommandToggleRepeatMode).build() | ||
) | ||
|
||
override fun updateNotificationLayout() { | ||
mediaSession.setCustomLayout(commandButtons) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters