Merge pull request #5245 from natario1:videosize-override

PiperOrigin-RevId: 225187852
This commit is contained in:
Oliver Woodman 2018-12-14 15:40:57 +00:00
commit 3bfe103b82

View File

@ -29,7 +29,6 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Looper; import android.os.Looper;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -271,13 +270,13 @@ public class PlayerView extends FrameLayout {
private static final int SURFACE_TYPE_MONO360_VIEW = 3; private static final int SURFACE_TYPE_MONO360_VIEW = 3;
// LINT.ThenChange(../../../../../../res/values/attrs.xml) // LINT.ThenChange(../../../../../../res/values/attrs.xml)
private final AspectRatioFrameLayout contentFrame; @Nullable private final AspectRatioFrameLayout contentFrame;
private final View shutterView; private final View shutterView;
private final View surfaceView; @Nullable private final View surfaceView;
private final ImageView artworkView; private final ImageView artworkView;
private final SubtitleView subtitleView; private final SubtitleView subtitleView;
private final @Nullable View bufferingView; @Nullable private final View bufferingView;
private final @Nullable TextView errorMessageView; @Nullable private final TextView errorMessageView;
private final PlayerControlView controller; private final PlayerControlView controller;
private final ComponentListener componentListener; private final ComponentListener componentListener;
private final FrameLayout overlayFrameLayout; private final FrameLayout overlayFrameLayout;
@ -285,11 +284,11 @@ public class PlayerView extends FrameLayout {
private Player player; private Player player;
private boolean useController; private boolean useController;
private boolean useArtwork; private boolean useArtwork;
private @Nullable Drawable defaultArtwork; @Nullable private Drawable defaultArtwork;
private @ShowBuffering int showBuffering; private @ShowBuffering int showBuffering;
private boolean keepContentOnPlayerReset; private boolean keepContentOnPlayerReset;
private @Nullable ErrorMessageProvider<? super ExoPlaybackException> errorMessageProvider; @Nullable private ErrorMessageProvider<? super ExoPlaybackException> errorMessageProvider;
private @Nullable CharSequence customErrorMessage; @Nullable private CharSequence customErrorMessage;
private int controllerShowTimeoutMs; private int controllerShowTimeoutMs;
private boolean controllerAutoShow; private boolean controllerAutoShow;
private boolean controllerHideDuringAds; private boolean controllerHideDuringAds;
@ -474,9 +473,7 @@ public class PlayerView extends FrameLayout {
* @param newPlayerView The new view to attach to the player. * @param newPlayerView The new view to attach to the player.
*/ */
public static void switchTargetView( public static void switchTargetView(
@NonNull Player player, Player player, @Nullable PlayerView oldPlayerView, @Nullable PlayerView newPlayerView) {
@Nullable PlayerView oldPlayerView,
@Nullable PlayerView newPlayerView) {
if (oldPlayerView == newPlayerView) { if (oldPlayerView == newPlayerView) {
return; return;
} }
@ -1080,6 +1077,26 @@ public class PlayerView extends FrameLayout {
} }
} }
/**
* Called when there's a change in the aspect ratio of the content being displayed. The default
* implementation sets the aspect ratio of the content frame to that of the content, unless the
* content view is a {@link SphericalSurfaceView} in which case the frame's aspect ratio is
* cleared.
*
* @param contentAspectRatio The aspect ratio of the content.
* @param contentFrame The content frame, or {@code null}.
* @param contentView The view that holds the content being displayed, or {@code null}.
*/
protected void onContentAspectRatioChanged(
float contentAspectRatio,
@Nullable AspectRatioFrameLayout contentFrame,
@Nullable View contentView) {
if (contentFrame != null) {
contentFrame.setAspectRatio(
contentView instanceof SphericalSurfaceView ? 0 : contentAspectRatio);
}
}
private boolean toggleControllerVisibility() { private boolean toggleControllerVisibility() {
if (!useController || player == null) { if (!useController || player == null) {
return false; return false;
@ -1193,9 +1210,8 @@ public class PlayerView extends FrameLayout {
int drawableWidth = drawable.getIntrinsicWidth(); int drawableWidth = drawable.getIntrinsicWidth();
int drawableHeight = drawable.getIntrinsicHeight(); int drawableHeight = drawable.getIntrinsicHeight();
if (drawableWidth > 0 && drawableHeight > 0) { if (drawableWidth > 0 && drawableHeight > 0) {
if (contentFrame != null) { float artworkAspectRatio = (float) drawableWidth / drawableHeight;
contentFrame.setAspectRatio((float) drawableWidth / drawableHeight); onContentAspectRatioChanged(artworkAspectRatio, contentFrame, artworkView);
}
artworkView.setImageDrawable(drawable); artworkView.setImageDrawable(drawable);
artworkView.setVisibility(VISIBLE); artworkView.setVisibility(VISIBLE);
return true; return true;
@ -1328,9 +1344,6 @@ public class PlayerView extends FrameLayout {
@Override @Override
public void onVideoSizeChanged( public void onVideoSizeChanged(
int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
if (contentFrame == null) {
return;
}
float videoAspectRatio = float videoAspectRatio =
(height == 0 || width == 0) ? 1 : (width * pixelWidthHeightRatio) / height; (height == 0 || width == 0) ? 1 : (width * pixelWidthHeightRatio) / height;
@ -1351,11 +1364,9 @@ public class PlayerView extends FrameLayout {
surfaceView.addOnLayoutChangeListener(this); surfaceView.addOnLayoutChangeListener(this);
} }
applyTextureViewRotation((TextureView) surfaceView, textureViewRotation); applyTextureViewRotation((TextureView) surfaceView, textureViewRotation);
} else if (surfaceView instanceof SphericalSurfaceView) {
videoAspectRatio = 0;
} }
contentFrame.setAspectRatio(videoAspectRatio); onContentAspectRatioChanged(videoAspectRatio, contentFrame, surfaceView);
} }
@Override @Override