scale imgages differently

This commit is contained in:
Bnyro 2022-11-13 13:18:11 +01:00
parent 588f99edba
commit 91fc986f41

View File

@ -105,28 +105,33 @@ class NowPlayingNotification(
callback: PlayerNotificationManager.BitmapCallback
): Bitmap? {
var bitmap: Bitmap? = null
var resizedBitmap: Bitmap? = null
val request = ImageRequest.Builder(context)
.data(streams?.thumbnailUrl)
.target { result ->
bitmap = (result as BitmapDrawable).bitmap
resizedBitmap = Bitmap.createScaledBitmap(
bitmap!!,
bitmap!!.width,
bitmap!!.width,
false
)
}
.build()
ImageHelper.imageLoader.enqueue(request)
// returns the scaled bitmap if it got fetched successfully
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) resizedBitmap else bitmap
// returns the bitmap on Android 13+, for everything below scaled down to a square
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) getSquareBitmap(bitmap) else bitmap
}
}
private fun getSquareBitmap(bitmap: Bitmap?): Bitmap? {
bitmap ?: return null
val newSize = minOf(bitmap.width, bitmap.height)
return Bitmap.createBitmap(
bitmap,
(bitmap.width - newSize) / 2,
(bitmap.height - newSize) / 2,
newSize,
newSize
)
}
/**
* Creates a [MediaSessionCompat] amd a [MediaSessionConnector] for the player
*/