Better icons in the now playing notification

This commit is contained in:
Bnyro 2023-01-16 14:23:36 +01:00
parent 90e87c596e
commit 6c750b51fa
3 changed files with 70 additions and 41 deletions

View File

@ -14,7 +14,6 @@ import android.support.v4.media.MediaDescriptionCompat
import android.support.v4.media.MediaMetadataCompat import android.support.v4.media.MediaMetadataCompat
import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat import android.support.v4.media.session.PlaybackStateCompat
import android.util.Log
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import coil.request.ImageRequest import coil.request.ImageRequest
@ -134,8 +133,8 @@ class NowPlayingNotification(
instanceId: Int instanceId: Int
): MutableMap<String, NotificationCompat.Action> { ): MutableMap<String, NotificationCompat.Action> {
return mutableMapOf( return mutableMapOf(
PREV to createNotificationAction(R.drawable.ic_prev, PREV, instanceId), PREV to createNotificationAction(R.drawable.ic_prev_outlined, PREV, instanceId),
NEXT to createNotificationAction(R.drawable.ic_next, NEXT, instanceId), NEXT to createNotificationAction(R.drawable.ic_next_outlined, NEXT, instanceId),
REWIND to createNotificationAction(R.drawable.ic_rewind, REWIND, instanceId), REWIND to createNotificationAction(R.drawable.ic_rewind, REWIND, instanceId),
FORWARD to createNotificationAction(R.drawable.ic_forward, FORWARD, instanceId) FORWARD to createNotificationAction(R.drawable.ic_forward, FORWARD, instanceId)
) )
@ -178,11 +177,13 @@ class NowPlayingNotification(
*/ */
private fun createMediaSession() { private fun createMediaSession() {
if (this::mediaSession.isInitialized) return if (this::mediaSession.isInitialized) return
mediaSession = MediaSessionCompat(context, this.javaClass.name) mediaSession = MediaSessionCompat(context, this.javaClass.name).apply {
mediaSession.isActive = true isActive = true
}
mediaSessionConnector = MediaSessionConnector(mediaSession) mediaSessionConnector = MediaSessionConnector(mediaSession).apply {
mediaSessionConnector.setQueueNavigator(object : TimelineQueueNavigator(mediaSession) { setPlayer(player)
setQueueNavigator(object : TimelineQueueNavigator(mediaSession) {
override fun getMediaDescription( override fun getMediaDescription(
player: Player, player: Player,
windowIndex: Int windowIndex: Int
@ -203,28 +204,36 @@ class NowPlayingNotification(
setExtras(extras) setExtras(extras)
}.build() }.build()
} }
override fun getSupportedQueueNavigatorActions(player: Player): Long {
return PlaybackStateCompat.ACTION_PLAY_PAUSE
}
}) })
mediaSessionConnector.setCustomActionProviders( setCustomActionProviders(
createMediaSessionAction(R.drawable.ic_prev, PREV), createMediaSessionAction(R.drawable.ic_prev_outlined, PREV),
createMediaSessionAction(R.drawable.ic_next, NEXT), createMediaSessionAction(R.drawable.ic_next_outlined, NEXT),
createMediaSessionAction(R.drawable.ic_rewind, REWIND), createMediaSessionAction(R.drawable.ic_rewind, REWIND),
createMediaSessionAction(R.drawable.ic_forward, FORWARD) createMediaSessionAction(R.drawable.ic_forward, FORWARD)
) )
mediaSessionConnector.setPlayer(player) }
} }
private fun handlePlayerAction(action: String) { private fun handlePlayerAction(action: String) {
when (action) { when (action) {
NEXT -> { NEXT -> {
if (PlayingQueue.hasNext()) PlayingQueue.onQueueItemSelected( if (PlayingQueue.hasNext()) {
PlayingQueue.onQueueItemSelected(
PlayingQueue.currentIndex() + 1 PlayingQueue.currentIndex() + 1
) )
} }
}
PREV -> { PREV -> {
if (PlayingQueue.hasPrev()) PlayingQueue.onQueueItemSelected( if (PlayingQueue.hasPrev()) {
PlayingQueue.onQueueItemSelected(
PlayingQueue.currentIndex() - 1 PlayingQueue.currentIndex() - 1
) )
} }
}
REWIND -> { REWIND -> {
player.seekTo(player.currentPosition - PlayerHelper.seekIncrement) player.seekTo(player.currentPosition - PlayerHelper.seekIncrement)
} }

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,18l8.5,-6L6,6v12zM8,9.86L11.03,12 8,14.14L8,9.86zM16,6h2v12h-2z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,6h2v12L6,18zM9.5,12l8.5,6L18,6l-8.5,6zM16,14.14L12.97,12 16,9.86v4.28z" />
</vector>