From dd0981a5b68e46abf685723996cb2cea38d2dee8 Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 4 May 2021 00:12:32 +0100 Subject: [PATCH] Access ExoPlayer specific UI components via reflection PiperOrigin-RevId: 371799441 --- library/ui/proguard-rules.txt | 10 +++++++ .../android/exoplayer2/ui/PlayerView.java | 27 ++++++++++++++----- .../exoplayer2/ui/StyledPlayerView.java | 27 ++++++++++++++----- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/library/ui/proguard-rules.txt b/library/ui/proguard-rules.txt index f18183637b..2e6ea621db 100644 --- a/library/ui/proguard-rules.txt +++ b/library/ui/proguard-rules.txt @@ -1,5 +1,15 @@ # Proguard rules specific to the UI module. +# Constructor method accessed via reflection in StyledPlayerView and PlayerView +-dontnote com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView +-keepclassmembers class com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView { + (android.content.Context); +} +-dontnote com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView +-keepclassmembers class com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView { + (android.content.Context); +} + # Constructor method accessed via reflection in TrackSelectionDialogBuilder -dontnote androidx.appcompat.app.AlertDialog.Builder -keepclassmembers class androidx.appcompat.app.AlertDialog$Builder { 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 4d26df9d28..c95f99d0e3 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 @@ -65,8 +65,6 @@ import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.ErrorMessageProvider; import com.google.android.exoplayer2.util.RepeatModeUtil; import com.google.android.exoplayer2.util.Util; -import com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView; -import com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView; import com.google.common.collect.ImmutableList; import java.lang.annotation.Documented; import java.lang.annotation.Retention; @@ -420,11 +418,26 @@ public class PlayerView extends FrameLayout implements AdViewProvider { surfaceView = new TextureView(context); break; case SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW: - surfaceView = new SphericalGLSurfaceView(context); + try { + Class clazz = + Class.forName( + "com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView"); + surfaceView = (View) clazz.getConstructor(Context.class).newInstance(context); + } catch (Exception e) { + throw new IllegalStateException( + "spherical_gl_surface_view requires an ExoPlayer dependency", e); + } surfaceViewIgnoresVideoAspectRatio = true; break; case SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW: - surfaceView = new VideoDecoderGLSurfaceView(context); + try { + Class clazz = + Class.forName("com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView"); + surfaceView = (View) clazz.getConstructor(Context.class).newInstance(context); + } catch (Exception e) { + throw new IllegalStateException( + "video_decoder_gl_surface_view requires an ExoPlayer dependency", e); + } break; default: surfaceView = new SurfaceView(context); @@ -1049,14 +1062,14 @@ public class PlayerView extends FrameLayout implements AdViewProvider { *
  • {@link SurfaceView} by default, or if the {@code surface_type} attribute is set to {@code * surface_view}. *
  • {@link TextureView} if {@code surface_type} is {@code texture_view}. - *
  • {@link SphericalGLSurfaceView} if {@code surface_type} is {@code + *
  • {@code SphericalGLSurfaceView} if {@code surface_type} is {@code * spherical_gl_surface_view}. - *
  • {@link VideoDecoderGLSurfaceView} if {@code surface_type} is {@code + *
  • {@code VideoDecoderGLSurfaceView} if {@code surface_type} is {@code * video_decoder_gl_surface_view}. *
  • {@code null} if {@code surface_type} is {@code none}. * * - * @return The {@link SurfaceView}, {@link TextureView}, {@link SphericalGLSurfaceView}, {@link + * @return The {@link SurfaceView}, {@link TextureView}, {@code SphericalGLSurfaceView}, {@code * VideoDecoderGLSurfaceView} or {@code null}. */ @Nullable 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 043a4b8920..6330094eea 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 @@ -65,8 +65,6 @@ import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.ErrorMessageProvider; import com.google.android.exoplayer2.util.RepeatModeUtil; import com.google.android.exoplayer2.util.Util; -import com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView; -import com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView; import com.google.common.collect.ImmutableList; import java.lang.annotation.Documented; import java.lang.annotation.Retention; @@ -425,11 +423,26 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { surfaceView = new TextureView(context); break; case SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW: - surfaceView = new SphericalGLSurfaceView(context); + try { + Class clazz = + Class.forName( + "com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView"); + surfaceView = (View) clazz.getConstructor(Context.class).newInstance(context); + } catch (Exception e) { + throw new IllegalStateException( + "spherical_gl_surface_view requires an ExoPlayer dependency", e); + } surfaceViewIgnoresVideoAspectRatio = true; break; case SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW: - surfaceView = new VideoDecoderGLSurfaceView(context); + try { + Class clazz = + Class.forName("com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView"); + surfaceView = (View) clazz.getConstructor(Context.class).newInstance(context); + } catch (Exception e) { + throw new IllegalStateException( + "video_decoder_gl_surface_view requires an ExoPlayer dependency", e); + } break; default: surfaceView = new SurfaceView(context); @@ -1063,14 +1076,14 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { *
  • {@link SurfaceView} by default, or if the {@code surface_type} attribute is set to {@code * surface_view}. *
  • {@link TextureView} if {@code surface_type} is {@code texture_view}. - *
  • {@link SphericalGLSurfaceView} if {@code surface_type} is {@code + *
  • {@code SphericalGLSurfaceView} if {@code surface_type} is {@code * spherical_gl_surface_view}. - *
  • {@link VideoDecoderGLSurfaceView} if {@code surface_type} is {@code + *
  • {@code VideoDecoderGLSurfaceView} if {@code surface_type} is {@code * video_decoder_gl_surface_view}. *
  • {@code null} if {@code surface_type} is {@code none}. * * - * @return The {@link SurfaceView}, {@link TextureView}, {@link SphericalGLSurfaceView}, {@link + * @return The {@link SurfaceView}, {@link TextureView}, {@code SphericalGLSurfaceView}, {@code * VideoDecoderGLSurfaceView} or {@code null}. */ @Nullable