LibreTube/app/src/main/java/com/github/libretube/util/DescriptionAdapter.kt

54 lines
1.6 KiB
Kotlin
Raw Normal View History

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
// used to show title and thumbnail of the video in the notification
class DescriptionAdapter(
private val title: String,
private val channelName: String,
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 {
val inputStream = URL(thumbnailUrl).openStream()
bitmap = BitmapFactory.decodeStream(inputStream)
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
}
thread.start()
thread.join()
return try {
bitmap
} catch (e: Exception) {
null
}
}
}