Skip to content

Commit

Permalink
Set Android notification media metadata (closes #393)
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterofbread committed Nov 9, 2024
1 parent fbafb61 commit 1dd18b9
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ComponentName
import android.content.Intent
import android.graphics.Bitmap
import android.media.MediaMetadata
import android.media.session.MediaSession
Expand All @@ -20,6 +18,7 @@ import androidx.media3.ui.PlayerNotificationManager
import app.cash.sqldelight.Query
import com.toasterofbread.spmp.model.mediaitem.loader.MediaItemThumbnailLoader
import com.toasterofbread.spmp.model.mediaitem.loader.SongLikedLoader
import com.toasterofbread.spmp.model.mediaitem.playlist.RemotePlaylist
import com.toasterofbread.spmp.model.mediaitem.song.Song
import com.toasterofbread.spmp.platform.AppContext
import com.toasterofbread.spmp.platform.PlayerListener
Expand Down Expand Up @@ -91,6 +90,16 @@ class PlayerServiceNotificationManager(
position_ms = player.currentPosition
)

updateMetadata {
putString(MediaMetadata.METADATA_KEY_TITLE, song?.getActiveTitle(context.database))
putString(MediaMetadata.METADATA_KEY_ARTIST, song?.Artists?.get(context.database)?.firstOrNull()?.getActiveTitle(context.database))
putString(MediaMetadata.METADATA_KEY_ART_URI, song?.thumbnail_provider?.getThumbnailUrl(ThumbnailProvider.Quality.HIGH))

val album: RemotePlaylist? = song?.Album?.get(context.database)
putString(MediaMetadata.METADATA_KEY_ALBUM, album?.getActiveTitle(context.database))
putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, album?.thumbnail_provider?.getThumbnailUrl(ThumbnailProvider.Quality.HIGH))
}

if (song != null) {
context.database.songQueries.likedById(song.id).addListener(song_liked_listener)

Expand Down

0 comments on commit 1dd18b9

Please sign in to comment.