From bd654279d71001a52e086c455b79a91ce5ea57eb Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 14 Apr 2021 14:52:49 +0100 Subject: [PATCH] Core/UI decoupling: Remove SphericalGLSurfaceView cast PiperOrigin-RevId: 368420961 --- .../android/exoplayer2/ui/PlayerView.java | 26 +++++++++---------- .../exoplayer2/ui/StyledPlayerView.java | 26 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java index 5da2d2f7d5..b1fd0aa0a6 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java @@ -295,6 +295,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider { @Nullable private final AspectRatioFrameLayout contentFrame; @Nullable private final View shutterView; @Nullable private final View surfaceView; + private final boolean surfaceViewIgnoresVideoAspectRatio; @Nullable private final ImageView artworkView; @Nullable private final SubtitleView subtitleView; @Nullable private final View bufferingView; @@ -339,6 +340,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider { contentFrame = null; shutterView = null; surfaceView = null; + surfaceViewIgnoresVideoAspectRatio = false; artworkView = null; subtitleView = null; bufferingView = null; @@ -413,6 +415,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider { } // Create a surface view and insert it into the content frame, if there is one. + boolean surfaceViewIgnoresVideoAspectRatio = false; if (contentFrame != null && surfaceType != SURFACE_TYPE_NONE) { ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( @@ -425,6 +428,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider { SphericalGLSurfaceView sphericalGLSurfaceView = new SphericalGLSurfaceView(context); sphericalGLSurfaceView.setSingleTapListener(componentListener); surfaceView = sphericalGLSurfaceView; + surfaceViewIgnoresVideoAspectRatio = true; break; case SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW: surfaceView = new VideoDecoderGLSurfaceView(context); @@ -438,6 +442,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider { } else { surfaceView = null; } + this.surfaceViewIgnoresVideoAspectRatio = surfaceViewIgnoresVideoAspectRatio; // Ad overlay frame layout. adOverlayFrameLayout = findViewById(R.id.exo_ad_overlay); @@ -1178,22 +1183,16 @@ public class PlayerView extends FrameLayout implements AdViewProvider { } /** - * 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 SphericalGLSurfaceView} in which case the frame's aspect ratio is - * cleared. + * Called when there's a change in the desired aspect ratio of the content frame. The default + * implementation sets the aspect ratio of the content frame to the specified value. * - * @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}. + * @param aspectRatio The aspect ratio to apply. */ protected void onContentAspectRatioChanged( - float contentAspectRatio, - @Nullable AspectRatioFrameLayout contentFrame, - @Nullable View contentView) { + @Nullable AspectRatioFrameLayout contentFrame, float aspectRatio) { if (contentFrame != null) { - contentFrame.setAspectRatio( - contentView instanceof SphericalGLSurfaceView ? 0 : contentAspectRatio); + contentFrame.setAspectRatio(aspectRatio); } } @@ -1366,7 +1365,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider { int drawableHeight = drawable.getIntrinsicHeight(); if (drawableWidth > 0 && drawableHeight > 0) { float artworkAspectRatio = (float) drawableWidth / drawableHeight; - onContentAspectRatioChanged(artworkAspectRatio, contentFrame, artworkView); + onContentAspectRatioChanged(contentFrame, artworkAspectRatio); artworkView.setImageDrawable(drawable); artworkView.setVisibility(VISIBLE); return true; @@ -1542,7 +1541,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider { applyTextureViewRotation((TextureView) surfaceView, textureViewRotation); } - onContentAspectRatioChanged(videoAspectRatio, contentFrame, surfaceView); + onContentAspectRatioChanged( + contentFrame, surfaceViewIgnoresVideoAspectRatio ? 0 : videoAspectRatio); } @Override diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java index ebd28f9e15..8f7269b2ef 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java @@ -297,6 +297,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { @Nullable private final AspectRatioFrameLayout contentFrame; @Nullable private final View shutterView; @Nullable private final View surfaceView; + private final boolean surfaceViewIgnoresVideoAspectRatio; @Nullable private final ImageView artworkView; @Nullable private final SubtitleView subtitleView; @Nullable private final View bufferingView; @@ -341,6 +342,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { contentFrame = null; shutterView = null; surfaceView = null; + surfaceViewIgnoresVideoAspectRatio = false; artworkView = null; subtitleView = null; bufferingView = null; @@ -420,6 +422,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { } // Create a surface view and insert it into the content frame, if there is one. + boolean surfaceViewIgnoresVideoAspectRatio = false; if (contentFrame != null && surfaceType != SURFACE_TYPE_NONE) { ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( @@ -432,6 +435,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { SphericalGLSurfaceView sphericalGLSurfaceView = new SphericalGLSurfaceView(context); sphericalGLSurfaceView.setSingleTapListener(componentListener); surfaceView = sphericalGLSurfaceView; + surfaceViewIgnoresVideoAspectRatio = true; break; case SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW: surfaceView = new VideoDecoderGLSurfaceView(context); @@ -445,6 +449,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { } else { surfaceView = null; } + this.surfaceViewIgnoresVideoAspectRatio = surfaceViewIgnoresVideoAspectRatio; // Ad overlay frame layout. adOverlayFrameLayout = findViewById(R.id.exo_ad_overlay); @@ -1196,22 +1201,16 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { } /** - * 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 SphericalGLSurfaceView} in which case the frame's aspect ratio is - * cleared. + * Called when there's a change in the desired aspect ratio of the content frame. The default + * implementation sets the aspect ratio of the content frame to the specified value. * - * @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}. + * @param aspectRatio The aspect ratio to apply. */ protected void onContentAspectRatioChanged( - float contentAspectRatio, - @Nullable AspectRatioFrameLayout contentFrame, - @Nullable View contentView) { + @Nullable AspectRatioFrameLayout contentFrame, float aspectRatio) { if (contentFrame != null) { - contentFrame.setAspectRatio( - contentView instanceof SphericalGLSurfaceView ? 0 : contentAspectRatio); + contentFrame.setAspectRatio(aspectRatio); } } @@ -1388,7 +1387,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { int drawableHeight = drawable.getIntrinsicHeight(); if (drawableWidth > 0 && drawableHeight > 0) { float artworkAspectRatio = (float) drawableWidth / drawableHeight; - onContentAspectRatioChanged(artworkAspectRatio, contentFrame, artworkView); + onContentAspectRatioChanged(contentFrame, artworkAspectRatio); artworkView.setImageDrawable(drawable); artworkView.setVisibility(VISIBLE); return true; @@ -1564,7 +1563,8 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { applyTextureViewRotation((TextureView) surfaceView, textureViewRotation); } - onContentAspectRatioChanged(videoAspectRatio, contentFrame, surfaceView); + onContentAspectRatioChanged( + contentFrame, surfaceViewIgnoresVideoAspectRatio ? 0 : videoAspectRatio); } @Override