Add the MediaMetadata

Settings the metadata, the notification shows the title aswell.
This commit is contained in:
Relwi 2022-05-23 20:50:46 +02:00
parent 72e14e7430
commit 486be2ec63
No known key found for this signature in database
GPG Key ID: 3316DC3D260D0163
2 changed files with 12 additions and 36 deletions

View File

@ -1,10 +1,10 @@
package com.github.libretube package com.github.libretube
import android.content.Context import android.content.Context
import com.github.libretube.adapters.MediaDescriptionAdapter
import com.github.libretube.obj.Streams import com.github.libretube.obj.Streams
import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.MediaMetadata
import com.google.android.exoplayer2.ui.PlayerNotificationManager import com.google.android.exoplayer2.ui.PlayerNotificationManager
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@ -39,9 +39,7 @@ class BackgroundMode {
*/ */
private fun initializePlayerNotification(c: Context) { private fun initializePlayerNotification(c: Context) {
playerNotificationManager = playerNotificationManager =
PlayerNotificationManager.Builder(c, 1, "background_mode") PlayerNotificationManager.Builder(c, 1, "background_mode").build()
.setMediaDescriptionAdapter(MediaDescriptionAdapter(response!!.title!!))
.build()
playerNotificationManager?.setPlayer(player) playerNotificationManager?.setPlayer(player)
} }
@ -50,7 +48,16 @@ class BackgroundMode {
*/ */
private fun setMediaItem() { private fun setMediaItem() {
response?.let { response?.let {
val mediaItem = MediaItem.fromUri(it.hls!!) // Builds the song metadata
val metaData = MediaMetadata.Builder()
.setTitle(it.title)
.build()
// Builds the song item
val mediaItem = MediaItem.Builder()
.setUri(it.hls!!)
.setMediaMetadata(metaData)
.build()
player?.setMediaItem(mediaItem) player?.setMediaItem(mediaItem)
} }
} }

View File

@ -1,31 +0,0 @@
package com.github.libretube.adapters
import android.app.PendingIntent
import android.graphics.Bitmap
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ui.PlayerNotificationManager
/**
* Adapter for the media content of the notification area.
*/
class MediaDescriptionAdapter(private val title: String) :
PlayerNotificationManager.MediaDescriptionAdapter {
override fun getCurrentContentTitle(player: Player): CharSequence {
return title
}
override fun createCurrentContentIntent(player: Player): PendingIntent? {
return null
}
override fun getCurrentContentText(player: Player): CharSequence? {
return null
}
override fun getCurrentLargeIcon(
player: Player,
callback: PlayerNotificationManager.BitmapCallback
): Bitmap? {
return null
}
}