From 50eefcbd5308f4d58cfa234b602dc82689bcc5c9 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 8 Sep 2023 15:53:01 +0200 Subject: [PATCH] fix: crash when scrubbing timebar on certain videos --- .../libretube/util/OnlineTimeFrameReceiver.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt b/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt index 3df46ee009..8c654d1d69 100644 --- a/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt +++ b/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt @@ -21,13 +21,12 @@ class OnlineTimeFrameReceiver( * Cut off a new bitmap from the image that contains multiple preview thumbnails */ private fun cutBitmapFromPreviewFrame(bitmap: Bitmap, previewFrame: PreviewFrame): Bitmap { - return Bitmap.createBitmap( - bitmap, - previewFrame.positionX * previewFrame.frameWidth, - previewFrame.positionY * previewFrame.frameHeight, - previewFrame.frameWidth, - previewFrame.frameHeight - ) + val positionX = previewFrame.positionX * previewFrame.frameWidth + val positionY = previewFrame.positionY * previewFrame.frameHeight + val width = minOf(previewFrame.frameWidth, bitmap.width - positionX) + val height = minOf(previewFrame.frameHeight, bitmap.height - positionY) + + return Bitmap.createBitmap(bitmap, positionX, positionY, width, height) } /**