diff --git a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt index 55bd7e3fd..f6bf02eea 100644 --- a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt +++ b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt @@ -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 */