From 718335d7334522fa208406ea911f7701e22fe376 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Fri, 26 Dec 2025 20:23:15 +0100 Subject: [PATCH 1/3] fix(player): Fix scaleX being NaN on minimize to background app switch This aims to fix the following Exception which might occour when watching a live stream and switching the app while 'minimize to backgorund' is enabled: java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN at android.view.View.sanitizeFloatPropertyValue(View.java:17479) at android.view.View.sanitizeFloatPropertyValue(View.java:17453) at android.view.View.setScaleX(View.java:16822) at org.schabi.newpipe.views.ExpandableSurfaceView.onLayout(ExpandableSurfaceView.java:71) scaleX is set in onMeasure() in which width could be 0 in theory and this leading to a division by zero of a float which results in an assignment of Float.NaN. --- .../java/org/schabi/newpipe/views/ExpandableSurfaceView.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java index 175c81e46..36380b650 100644 --- a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java +++ b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java @@ -35,12 +35,12 @@ public class ExpandableSurfaceView extends SurfaceView { && resizeMode != RESIZE_MODE_FIT && verticalVideo ? maxHeight : baseHeight; - if (height == 0) { + if (width == 0 || height == 0) { return; } final float viewAspectRatio = width / ((float) height); - final float aspectDeformation = videoAspectRatio / viewAspectRatio - 1; + final float aspectDeformation = (videoAspectRatio / viewAspectRatio) - 1; scaleX = 1.0f; scaleY = 1.0f; From 7101aecc98aa80291c231e2c7a9425aef60cece4 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Fri, 26 Dec 2025 23:49:30 +0100 Subject: [PATCH 2/3] Try to prevent invalid aspectRatio of SurfaceView If the video's hieght is 0, the aspectRatio is set to Float.NaN which can cause further issues. Do not assign invalid values for the aspectRatio. --- .../java/org/schabi/newpipe/views/ExpandableSurfaceView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java index 36380b650..7452fff09 100644 --- a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java +++ b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java @@ -100,7 +100,7 @@ public class ExpandableSurfaceView extends SurfaceView { } public void setAspectRatio(final float aspectRatio) { - if (videoAspectRatio == aspectRatio) { + if (videoAspectRatio == aspectRatio || aspectRatio == 0 || !Float.isFinite(aspectRatio)) { return; } From 465979e677beb5bdba7c2c0bd5d1d3f9f24b3cec Mon Sep 17 00:00:00 2001 From: tobigr Date: Mon, 29 Dec 2025 16:36:43 +0100 Subject: [PATCH 3/3] Do not change the aspectRation if the renderer is disabled --- .../java/org/schabi/newpipe/player/ui/VideoPlayerUi.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java b/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java index 7157d6af2..b68d3d94d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java +++ b/app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java @@ -1554,6 +1554,11 @@ public abstract class VideoPlayerUi extends PlayerUi implements SeekBar.OnSeekBa @Override public void onVideoSizeChanged(@NonNull final VideoSize videoSize) { super.onVideoSizeChanged(videoSize); + // Starting with ExoPlayer 2.19.0, the VideoSize will report a width and height of 0 + // if the renderer is disabled. In that case, we skip updating the aspect ratio. + if (videoSize.width == 0 || videoSize.height == 0) { + return; + } binding.surfaceView.setAspectRatio(((float) videoSize.width) / videoSize.height); } //endregion