diff --git a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java index 2db6d39b2..09c61b8b3 100644 --- a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java +++ b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java @@ -168,6 +168,18 @@ public class SeekbarPreviewThumbnailHolder { return null; } + // Under some rare circumstances the YouTube API returns slightly too small storyboards, + // (or not the matching frame width/height) + // This would lead to createBitmap cutting out a bitmap that is out of bounds, + // so we need to adjust the bounds accordingly + if (srcBitMap.getWidth() < bounds[1] + frameset.getFrameWidth()) { + bounds[1] = srcBitMap.getWidth() - frameset.getFrameWidth(); + } + + if (srcBitMap.getHeight() < bounds[2] + frameset.getFrameHeight()) { + bounds[2] = srcBitMap.getHeight() - frameset.getFrameHeight(); + } + // Cut out the corresponding bitmap form the "srcBitMap" final Bitmap cutOutBitmap = Bitmap.createBitmap(srcBitMap, bounds[1], bounds[2], frameset.getFrameWidth(), frameset.getFrameHeight());