mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Better icons in the now playing notification
This commit is contained in:
parent
90e87c596e
commit
6c750b51fa
@ -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,52 +177,62 @@ 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)
|
||||||
override fun getMediaDescription(
|
setQueueNavigator(object : TimelineQueueNavigator(mediaSession) {
|
||||||
player: Player,
|
override fun getMediaDescription(
|
||||||
windowIndex: Int
|
player: Player,
|
||||||
): MediaDescriptionCompat {
|
windowIndex: Int
|
||||||
return MediaDescriptionCompat.Builder().apply {
|
): MediaDescriptionCompat {
|
||||||
setTitle(streams?.title!!)
|
return MediaDescriptionCompat.Builder().apply {
|
||||||
setSubtitle(streams?.uploader)
|
setTitle(streams?.title!!)
|
||||||
val appIcon = BitmapFactory.decodeResource(
|
setSubtitle(streams?.uploader)
|
||||||
context.resources,
|
val appIcon = BitmapFactory.decodeResource(
|
||||||
R.drawable.ic_launcher_monochrome
|
context.resources,
|
||||||
)
|
R.drawable.ic_launcher_monochrome
|
||||||
val extras = Bundle().apply {
|
)
|
||||||
putParcelable(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, appIcon)
|
val extras = Bundle().apply {
|
||||||
putString(MediaMetadataCompat.METADATA_KEY_TITLE, streams?.title!!)
|
putParcelable(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, appIcon)
|
||||||
putString(MediaMetadataCompat.METADATA_KEY_ARTIST, streams?.uploader)
|
putString(MediaMetadataCompat.METADATA_KEY_TITLE, streams?.title!!)
|
||||||
}
|
putString(MediaMetadataCompat.METADATA_KEY_ARTIST, streams?.uploader)
|
||||||
setIconBitmap(appIcon)
|
}
|
||||||
setExtras(extras)
|
setIconBitmap(appIcon)
|
||||||
}.build()
|
setExtras(extras)
|
||||||
}
|
}.build()
|
||||||
})
|
}
|
||||||
mediaSessionConnector.setCustomActionProviders(
|
|
||||||
createMediaSessionAction(R.drawable.ic_prev, PREV),
|
override fun getSupportedQueueNavigatorActions(player: Player): Long {
|
||||||
createMediaSessionAction(R.drawable.ic_next, NEXT),
|
return PlaybackStateCompat.ACTION_PLAY_PAUSE
|
||||||
createMediaSessionAction(R.drawable.ic_rewind, REWIND),
|
}
|
||||||
createMediaSessionAction(R.drawable.ic_forward, FORWARD)
|
})
|
||||||
)
|
setCustomActionProviders(
|
||||||
mediaSessionConnector.setPlayer(player)
|
createMediaSessionAction(R.drawable.ic_prev_outlined, PREV),
|
||||||
|
createMediaSessionAction(R.drawable.ic_next_outlined, NEXT),
|
||||||
|
createMediaSessionAction(R.drawable.ic_rewind, REWIND),
|
||||||
|
createMediaSessionAction(R.drawable.ic_forward, FORWARD)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.currentIndex() + 1
|
PlayingQueue.onQueueItemSelected(
|
||||||
)
|
PlayingQueue.currentIndex() + 1
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PREV -> {
|
PREV -> {
|
||||||
if (PlayingQueue.hasPrev()) PlayingQueue.onQueueItemSelected(
|
if (PlayingQueue.hasPrev()) {
|
||||||
PlayingQueue.currentIndex() - 1
|
PlayingQueue.onQueueItemSelected(
|
||||||
)
|
PlayingQueue.currentIndex() - 1
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
REWIND -> {
|
REWIND -> {
|
||||||
player.seekTo(player.currentPosition - PlayerHelper.seekIncrement)
|
player.seekTo(player.currentPosition - PlayerHelper.seekIncrement)
|
||||||
|
10
app/src/main/res/drawable/ic_next_outlined.xml
Normal file
10
app/src/main/res/drawable/ic_next_outlined.xml
Normal 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>
|
10
app/src/main/res/drawable/ic_prev_outlined.xml
Normal file
10
app/src/main/res/drawable/ic_prev_outlined.xml
Normal 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>
|
Loading…
Reference in New Issue
Block a user