mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Fix the notification thumbnail vanishing
This commit is contained in:
parent
c2f0d68ddf
commit
a5c3132916
@ -38,6 +38,7 @@ class NowPlayingNotification(
|
|||||||
) {
|
) {
|
||||||
private var videoId: String? = null
|
private var videoId: String? = null
|
||||||
private var streams: Streams? = null
|
private var streams: Streams? = null
|
||||||
|
private var bitmap: Bitmap? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The [MediaSessionCompat] for the [streams].
|
* The [MediaSessionCompat] for the [streams].
|
||||||
@ -105,24 +106,7 @@ class NowPlayingNotification(
|
|||||||
): Bitmap? {
|
): Bitmap? {
|
||||||
if (DataSaverMode.isEnabled(context)) return null
|
if (DataSaverMode.isEnabled(context)) return null
|
||||||
|
|
||||||
var bitmap: Bitmap? = null
|
if (bitmap == null) enqueueThumbnailRequest(callback)
|
||||||
|
|
||||||
val request = ImageRequest.Builder(context)
|
|
||||||
.data(streams?.thumbnailUrl)
|
|
||||||
.target { result ->
|
|
||||||
val bm = (result as BitmapDrawable).bitmap
|
|
||||||
// returns the bitmap on Android 13+, for everything below scaled down to a square
|
|
||||||
bitmap = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
ImageHelper.getSquareBitmap(bm)
|
|
||||||
} else {
|
|
||||||
bm
|
|
||||||
}
|
|
||||||
callback.onBitmap(bitmap!!)
|
|
||||||
}
|
|
||||||
.build()
|
|
||||||
|
|
||||||
// enqueue the thumbnail loading request
|
|
||||||
ImageHelper.imageLoader.enqueue(request)
|
|
||||||
|
|
||||||
return bitmap
|
return bitmap
|
||||||
}
|
}
|
||||||
@ -132,6 +116,25 @@ class NowPlayingNotification(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun enqueueThumbnailRequest(callback: PlayerNotificationManager.BitmapCallback) {
|
||||||
|
val request = ImageRequest.Builder(context)
|
||||||
|
.data(streams?.thumbnailUrl)
|
||||||
|
.target { result ->
|
||||||
|
val bm = (result as BitmapDrawable).bitmap
|
||||||
|
// returns the bitmap on Android 13+, for everything below scaled down to a square
|
||||||
|
bitmap = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
ImageHelper.getSquareBitmap(bm)
|
||||||
|
} else {
|
||||||
|
bm
|
||||||
|
}
|
||||||
|
callback.onBitmap(bitmap!!)
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
|
||||||
|
// enqueue the thumbnail loading request
|
||||||
|
ImageHelper.imageLoader.enqueue(request)
|
||||||
|
}
|
||||||
|
|
||||||
private val customActionReceiver = object : CustomActionReceiver {
|
private val customActionReceiver = object : CustomActionReceiver {
|
||||||
override fun createCustomActions(
|
override fun createCustomActions(
|
||||||
context: Context,
|
context: Context,
|
||||||
@ -257,6 +260,8 @@ class NowPlayingNotification(
|
|||||||
) {
|
) {
|
||||||
this.videoId = videoId
|
this.videoId = videoId
|
||||||
this.streams = streams
|
this.streams = streams
|
||||||
|
// reset the thumbnail bitmap in order to become reloaded for the new video
|
||||||
|
this.bitmap = null
|
||||||
|
|
||||||
if (playerNotification == null) {
|
if (playerNotification == null) {
|
||||||
createMediaSession()
|
createMediaSession()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user