mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Add the MediaMetadata
Settings the metadata, the notification shows the title aswell.
This commit is contained in:
parent
72e14e7430
commit
486be2ec63
@ -1,10 +1,10 @@
|
||||
package com.github.libretube
|
||||
|
||||
import android.content.Context
|
||||
import com.github.libretube.adapters.MediaDescriptionAdapter
|
||||
import com.github.libretube.obj.Streams
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.MediaMetadata
|
||||
import com.google.android.exoplayer2.ui.PlayerNotificationManager
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
@ -39,9 +39,7 @@ class BackgroundMode {
|
||||
*/
|
||||
private fun initializePlayerNotification(c: Context) {
|
||||
playerNotificationManager =
|
||||
PlayerNotificationManager.Builder(c, 1, "background_mode")
|
||||
.setMediaDescriptionAdapter(MediaDescriptionAdapter(response!!.title!!))
|
||||
.build()
|
||||
PlayerNotificationManager.Builder(c, 1, "background_mode").build()
|
||||
playerNotificationManager?.setPlayer(player)
|
||||
}
|
||||
|
||||
@ -50,7 +48,16 @@ class BackgroundMode {
|
||||
*/
|
||||
private fun setMediaItem() {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user