1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

Fixed player's ZOOM mode for KitKat devices

This commit is contained in:
Avently 2020-09-27 04:25:06 +03:00
parent df9823988e
commit d0fc9fda71
2 changed files with 27 additions and 22 deletions

View File

@ -1946,7 +1946,13 @@ public class VideoDetailFragment
} }
scrollToTop(); scrollToTop();
addVideoPlayerView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
addVideoPlayerView();
} else {
// KitKat needs a delay before addVideoPlayerView call or it reports wrong height in
// activity.getWindow().getDecorView().getHeight()
new Handler().post(this::addVideoPlayerView);
}
} }
@Override @Override

View File

@ -1,14 +1,17 @@
package org.schabi.newpipe.views; package org.schabi.newpipe.views;
import android.content.Context; import android.content.Context;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.SurfaceView; import android.view.SurfaceView;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FIT;
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM; import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM;
public class ExpandableSurfaceView extends SurfaceView { public class ExpandableSurfaceView extends SurfaceView {
private int resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT; private int resizeMode = RESIZE_MODE_FIT;
private int baseHeight = 0; private int baseHeight = 0;
private int maxHeight = 0; private int maxHeight = 0;
private float videoAspectRatio = 0.0f; private float videoAspectRatio = 0.0f;
@ -30,7 +33,7 @@ public class ExpandableSurfaceView extends SurfaceView {
final boolean verticalVideo = videoAspectRatio < 1; final boolean verticalVideo = videoAspectRatio < 1;
// Use maxHeight only on non-fit resize mode and in vertical videos // Use maxHeight only on non-fit resize mode and in vertical videos
int height = maxHeight != 0 int height = maxHeight != 0
&& resizeMode != AspectRatioFrameLayout.RESIZE_MODE_FIT && resizeMode != RESIZE_MODE_FIT
&& verticalVideo ? maxHeight : baseHeight; && verticalVideo ? maxHeight : baseHeight;
if (height == 0) { if (height == 0) {
@ -42,26 +45,22 @@ public class ExpandableSurfaceView extends SurfaceView {
scaleX = 1.0f; scaleX = 1.0f;
scaleY = 1.0f; scaleY = 1.0f;
switch (resizeMode) { if (resizeMode == RESIZE_MODE_FIT
case AspectRatioFrameLayout.RESIZE_MODE_FIT: // KitKat doesn't work well when a view has a scale like needed for ZOOM
if (aspectDeformation > 0) { || (resizeMode == RESIZE_MODE_ZOOM && VERSION.SDK_INT < VERSION_CODES.LOLLIPOP)) {
height = (int) (width / videoAspectRatio); if (aspectDeformation > 0) {
} else { height = (int) (width / videoAspectRatio);
width = (int) (height * videoAspectRatio); } else {
} width = (int) (height * videoAspectRatio);
}
break; } else if (resizeMode == RESIZE_MODE_ZOOM) {
case RESIZE_MODE_ZOOM: if (aspectDeformation < 0) {
if (aspectDeformation < 0) { scaleY = viewAspectRatio / videoAspectRatio;
scaleY = viewAspectRatio / videoAspectRatio; } else {
} else { scaleX = videoAspectRatio / viewAspectRatio;
scaleX = videoAspectRatio / viewAspectRatio; }
}
break;
default:
break;
} }
super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
} }