Skip to content

Commit 824fc8f

Browse files
authored
Merge pull request #12952 from TeamNewPipe/fix/NaN-on-minimize
fix(player): Fix scaleX being NaN on minimize to background app switch
2 parents 2dde0fe + 465979e commit 824fc8f

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,11 @@ void onResizeClicked() {
15541554
@Override
15551555
public void onVideoSizeChanged(@NonNull final VideoSize videoSize) {
15561556
super.onVideoSizeChanged(videoSize);
1557+
// Starting with ExoPlayer 2.19.0, the VideoSize will report a width and height of 0
1558+
// if the renderer is disabled. In that case, we skip updating the aspect ratio.
1559+
if (videoSize.width == 0 || videoSize.height == 0) {
1560+
return;
1561+
}
15571562
binding.surfaceView.setAspectRatio(((float) videoSize.width) / videoSize.height);
15581563
}
15591564
//endregion

app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec
3535
&& resizeMode != RESIZE_MODE_FIT
3636
&& verticalVideo ? maxHeight : baseHeight;
3737

38-
if (height == 0) {
38+
if (width == 0 || height == 0) {
3939
return;
4040
}
4141

4242
final float viewAspectRatio = width / ((float) height);
43-
final float aspectDeformation = videoAspectRatio / viewAspectRatio - 1;
43+
final float aspectDeformation = (videoAspectRatio / viewAspectRatio) - 1;
4444
scaleX = 1.0f;
4545
scaleY = 1.0f;
4646

@@ -100,7 +100,7 @@ public int getResizeMode() {
100100
}
101101

102102
public void setAspectRatio(final float aspectRatio) {
103-
if (videoAspectRatio == aspectRatio) {
103+
if (videoAspectRatio == aspectRatio || aspectRatio == 0 || !Float.isFinite(aspectRatio)) {
104104
return;
105105
}
106106

0 commit comments

Comments
 (0)