From b8f166cd889af238689b4b5fe6ca225395301769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20St=C3=A4hli?= Date: Thu, 21 Dec 2023 09:00:04 +0100 Subject: [PATCH] Fix crash when decode bitmap throw an exception (#383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gaƫtan Muller --- .../notification/PillarboxMediaDescriptionAdapter.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/notification/PillarboxMediaDescriptionAdapter.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/notification/PillarboxMediaDescriptionAdapter.kt index ffb56a3a2..135a0a4ad 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/notification/PillarboxMediaDescriptionAdapter.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/notification/PillarboxMediaDescriptionAdapter.kt @@ -86,8 +86,12 @@ class PillarboxMediaDescriptionAdapter( outHeight = imageMaxHeight } runBlocking(Dispatchers.IO) { - val bitmap = BitmapFactory.decodeStream(imageUrl.openStream(), null, opts) - bitmap?.let { + val result = runCatching { + imageUrl.openStream().use { + BitmapFactory.decodeStream(it, null, opts) + } + } + result.getOrNull()?.let { bitmapCache.put(imageUri, it) callback.onBitmap(it) }