Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix that seekbar preview frames are sometimes cut off #4093

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ object PlayerHelper {
for (x in 0 until frames.framesPerPageX) {
val endPosition = startPosition + frames.durationPerFrame
if (position in startPosition until endPosition) {
return PreviewFrame(url, x, y, frames.framesPerPageX, frames.framesPerPageY)
return PreviewFrame(url, x, y, frames.frameWidth, frames.frameHeight)
}
startPosition = endPosition
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/github/libretube/obj/PreviewFrame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ data class PreviewFrame(
val previewUrl: String,
val positionX: Int,
val positionY: Int,
val framesPerPageX: Int,
val framesPerPageY: Int,
val frameWidth: Int,
val frameHeight: Int,
)
10 changes: 4 additions & 6 deletions app/src/main/java/com/github/libretube/util/BitmapUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ object BitmapUtil {
* Cut off a new bitmap from the image that contains multiple preview thumbnails
*/
fun cutBitmapFromPreviewFrame(bitmap: Bitmap, previewFrame: PreviewFrame): Bitmap {
val heightPerFrame = bitmap.height / previewFrame.framesPerPageY
val widthPerFrame = bitmap.width / previewFrame.framesPerPageX
return Bitmap.createBitmap(
bitmap,
previewFrame.positionX * widthPerFrame,
previewFrame.positionY * heightPerFrame,
widthPerFrame,
heightPerFrame,
previewFrame.positionX * previewFrame.frameWidth,
previewFrame.positionY * previewFrame.frameHeight,
previewFrame.frameWidth,
previewFrame.frameHeight,
)
}
}