2022-06-14 15:30:58 +05:30
|
|
|
package com.github.libretube.util
|
|
|
|
|
|
|
|
import android.app.PendingIntent
|
|
|
|
import android.graphics.Bitmap
|
|
|
|
import android.graphics.BitmapFactory
|
|
|
|
import com.google.android.exoplayer2.Player
|
|
|
|
import com.google.android.exoplayer2.ui.PlayerNotificationManager
|
|
|
|
import java.net.URL
|
|
|
|
|
2022-06-14 22:38:02 +05:30
|
|
|
/**
|
|
|
|
* The [DescriptionAdapter] is used to show title, uploaderName and thumbnail of the video in the notification
|
|
|
|
* Basic example [here](https://github.com/AnthonyMarkD/AudioPlayerSampleTest)
|
|
|
|
*/
|
2022-06-14 15:30:58 +05:30
|
|
|
class DescriptionAdapter(
|
|
|
|
private val title: String,
|
|
|
|
private val channelName: String,
|
2022-06-14 15:51:18 +05:30
|
|
|
private val thumbnailUrl: String
|
|
|
|
) :
|
2022-06-14 15:30:58 +05:30
|
|
|
PlayerNotificationManager.MediaDescriptionAdapter {
|
|
|
|
override fun getCurrentContentTitle(player: Player): CharSequence {
|
|
|
|
// return controller.metadata.description.title.toString()
|
|
|
|
return title
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun createCurrentContentIntent(player: Player): PendingIntent? {
|
|
|
|
// return controller.sessionActivity
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getCurrentContentText(player: Player): CharSequence? {
|
|
|
|
// return controller.metadata.description.subtitle.toString()
|
|
|
|
return channelName
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getCurrentLargeIcon(
|
|
|
|
player: Player,
|
|
|
|
callback: PlayerNotificationManager.BitmapCallback
|
|
|
|
): Bitmap? {
|
|
|
|
lateinit var bitmap: Bitmap
|
|
|
|
val thread = Thread {
|
|
|
|
try {
|
2022-06-14 18:10:16 +05:30
|
|
|
// try to parse the thumbnailUrl to a Bitmap
|
2022-06-14 15:30:58 +05:30
|
|
|
val inputStream = URL(thumbnailUrl).openStream()
|
|
|
|
bitmap = BitmapFactory.decodeStream(inputStream)
|
|
|
|
} catch (ex: java.lang.Exception) {
|
|
|
|
ex.printStackTrace()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
thread.start()
|
|
|
|
thread.join()
|
2022-06-14 18:10:16 +05:30
|
|
|
// return bitmap if initialized
|
2022-06-14 15:30:58 +05:30
|
|
|
return try {
|
|
|
|
bitmap
|
|
|
|
} catch (e: Exception) {
|
|
|
|
null
|
|
|
|
}
|
|
|
|
}
|
2022-06-14 15:51:18 +05:30
|
|
|
}
|