package com.google.android.exoplayer2.ui; import android.R; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Matrix; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.os.Looper; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.SurfaceView; import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import com.google.android.exoplayer2.ControlDispatcher; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Timeline$Period; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.StyledPlayerControlView; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.ErrorMessageProvider; import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView; import com.google.android.exoplayer2.video.VideoSize; import com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView; /* loaded from: classes2.dex */ public class StyledPlayerView extends FrameLayout { public final FrameLayout adOverlayFrameLayout; public final ImageView artworkView; public final View bufferingView; public final ComponentListener componentListener; public final AspectRatioFrameLayout contentFrame; public final StyledPlayerControlView controller; public boolean controllerAutoShow; public boolean controllerHideDuringAds; public boolean controllerHideOnTouch; public int controllerShowTimeoutMs; public StyledPlayerControlView.VisibilityListener controllerVisibilityListener; public CharSequence customErrorMessage; public Drawable defaultArtwork; public final TextView errorMessageView; public boolean keepContentOnPlayerReset; public final FrameLayout overlayFrameLayout; public int showBuffering; public final View shutterView; public final SubtitleView subtitleView; public final View surfaceView; public final boolean surfaceViewIgnoresVideoAspectRatio; public int textureViewRotation; public boolean useArtwork; public boolean useController; public final boolean isDpadKey(int i) { return i == 19 || i == 270 || i == 22 || i == 271 || i == 20 || i == 269 || i == 21 || i == 268 || i == 23; } public final boolean isPlayingAd() { return false; } public void setControllerAutoShow(boolean z) { this.controllerAutoShow = z; } public void setControllerHideDuringAds(boolean z) { this.controllerHideDuringAds = z; } public final boolean shouldShowControllerIndefinitely() { return true; } public StyledPlayerView(Context context) { this(context, null); } public StyledPlayerView(Context context, @Nullable AttributeSet attributeSet) { this(context, attributeSet, 0); } /* JADX WARN: Multi-variable type inference failed */ public StyledPlayerView(Context context, @Nullable AttributeSet attributeSet, int i) { super(context, attributeSet, i); int i2; boolean z; int i3; int i4; boolean z2; boolean z3; int i5; boolean z4; int i6; boolean z5; int i7; boolean z6; boolean z7; boolean z8; int i8; boolean z9; ComponentListener componentListener = new ComponentListener(); this.componentListener = componentListener; if (isInEditMode()) { this.contentFrame = null; this.shutterView = null; this.surfaceView = null; this.surfaceViewIgnoresVideoAspectRatio = false; this.artworkView = null; this.subtitleView = null; this.bufferingView = null; this.errorMessageView = null; this.controller = null; this.adOverlayFrameLayout = null; this.overlayFrameLayout = null; ImageView imageView = new ImageView(context); if (Util.SDK_INT >= 23) { configureEditModeLogoV23(getResources(), imageView); } else { configureEditModeLogo(getResources(), imageView); } addView(imageView); return; } int i9 = R$layout.exo_styled_player_view; if (attributeSet != null) { TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet, R$styleable.StyledPlayerView, i, 0); try { boolean hasValue = obtainStyledAttributes.hasValue(R$styleable.StyledPlayerView_shutter_background_color); int color = obtainStyledAttributes.getColor(R$styleable.StyledPlayerView_shutter_background_color, 0); int resourceId = obtainStyledAttributes.getResourceId(R$styleable.StyledPlayerView_player_layout_id, i9); boolean z10 = obtainStyledAttributes.getBoolean(R$styleable.StyledPlayerView_use_artwork, true); int resourceId2 = obtainStyledAttributes.getResourceId(R$styleable.StyledPlayerView_default_artwork, 0); boolean z11 = obtainStyledAttributes.getBoolean(R$styleable.StyledPlayerView_use_controller, true); int i10 = obtainStyledAttributes.getInt(R$styleable.StyledPlayerView_surface_type, 1); int i11 = obtainStyledAttributes.getInt(R$styleable.StyledPlayerView_resize_mode, 0); int i12 = obtainStyledAttributes.getInt(R$styleable.StyledPlayerView_show_timeout, 5000); boolean z12 = obtainStyledAttributes.getBoolean(R$styleable.StyledPlayerView_hide_on_touch, true); boolean z13 = obtainStyledAttributes.getBoolean(R$styleable.StyledPlayerView_auto_show, true); i4 = obtainStyledAttributes.getInteger(R$styleable.StyledPlayerView_show_buffering, 0); this.keepContentOnPlayerReset = obtainStyledAttributes.getBoolean(R$styleable.StyledPlayerView_keep_content_on_player_reset, this.keepContentOnPlayerReset); boolean z14 = obtainStyledAttributes.getBoolean(R$styleable.StyledPlayerView_hide_during_ads, true); obtainStyledAttributes.recycle(); z3 = z12; z = z13; i3 = i11; z6 = z11; i7 = resourceId2; z5 = z10; i6 = color; z4 = hasValue; i5 = i10; i9 = resourceId; i2 = i12; z2 = z14; } catch (Throwable th) { obtainStyledAttributes.recycle(); throw th; } } else { i2 = 5000; z = true; i3 = 0; i4 = 0; z2 = true; z3 = true; i5 = 1; z4 = false; i6 = 0; z5 = true; i7 = 0; z6 = true; } LayoutInflater.from(context).inflate(i9, this); setDescendantFocusability(262144); AspectRatioFrameLayout aspectRatioFrameLayout = (AspectRatioFrameLayout) findViewById(R$id.exo_content_frame); this.contentFrame = aspectRatioFrameLayout; if (aspectRatioFrameLayout != null) { setResizeModeRaw(aspectRatioFrameLayout, i3); } View findViewById = findViewById(R$id.exo_shutter); this.shutterView = findViewById; if (findViewById != null && z4) { findViewById.setBackgroundColor(i6); } if (aspectRatioFrameLayout == null || i5 == 0) { z7 = true; this.surfaceView = null; z8 = false; } else { ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-1, -1); if (i5 == 2) { z7 = true; this.surfaceView = new TextureView(context); } else if (i5 != 3) { if (i5 == 4) { try { int i13 = VideoDecoderGLSurfaceView.$r8$clinit; this.surfaceView = (View) VideoDecoderGLSurfaceView.class.getConstructor(Context.class).newInstance(context); } catch (Exception e) { throw new IllegalStateException("video_decoder_gl_surface_view requires an ExoPlayer dependency", e); } } else { this.surfaceView = new SurfaceView(context); } z7 = true; } else { try { int i14 = SphericalGLSurfaceView.$r8$clinit; z7 = true; this.surfaceView = (View) SphericalGLSurfaceView.class.getConstructor(Context.class).newInstance(context); z9 = true; this.surfaceView.setLayoutParams(layoutParams); this.surfaceView.setOnClickListener(componentListener); this.surfaceView.setClickable(false); aspectRatioFrameLayout.addView(this.surfaceView, 0); z8 = z9; } catch (Exception e2) { throw new IllegalStateException("spherical_gl_surface_view requires an ExoPlayer dependency", e2); } } z9 = false; this.surfaceView.setLayoutParams(layoutParams); this.surfaceView.setOnClickListener(componentListener); this.surfaceView.setClickable(false); aspectRatioFrameLayout.addView(this.surfaceView, 0); z8 = z9; } this.surfaceViewIgnoresVideoAspectRatio = z8; this.adOverlayFrameLayout = (FrameLayout) findViewById(R$id.exo_ad_overlay); this.overlayFrameLayout = (FrameLayout) findViewById(R$id.exo_overlay); ImageView imageView2 = (ImageView) findViewById(R$id.exo_artwork); this.artworkView = imageView2; this.useArtwork = (!z5 || imageView2 == null) ? false : z7; if (i7 != 0) { this.defaultArtwork = ContextCompat.getDrawable(getContext(), i7); } SubtitleView subtitleView = (SubtitleView) findViewById(R$id.exo_subtitles); this.subtitleView = subtitleView; if (subtitleView != null) { subtitleView.setUserDefaultStyle(); subtitleView.setUserDefaultTextSize(); } View findViewById2 = findViewById(R$id.exo_buffering); this.bufferingView = findViewById2; if (findViewById2 != null) { findViewById2.setVisibility(8); } this.showBuffering = i4; TextView textView = (TextView) findViewById(R$id.exo_error_message); this.errorMessageView = textView; if (textView != null) { textView.setVisibility(8); } StyledPlayerControlView styledPlayerControlView = (StyledPlayerControlView) findViewById(R$id.exo_controller); View findViewById3 = findViewById(R$id.exo_controller_placeholder); if (styledPlayerControlView != null) { this.controller = styledPlayerControlView; i8 = 0; } else if (findViewById3 != null) { i8 = 0; StyledPlayerControlView styledPlayerControlView2 = new StyledPlayerControlView(context, null, 0, attributeSet); this.controller = styledPlayerControlView2; styledPlayerControlView2.setId(R$id.exo_controller); styledPlayerControlView2.setLayoutParams(findViewById3.getLayoutParams()); ViewGroup viewGroup = (ViewGroup) findViewById3.getParent(); int indexOfChild = viewGroup.indexOfChild(findViewById3); viewGroup.removeView(findViewById3); viewGroup.addView(styledPlayerControlView2, indexOfChild); } else { i8 = 0; this.controller = null; } StyledPlayerControlView styledPlayerControlView3 = this.controller; this.controllerShowTimeoutMs = styledPlayerControlView3 != null ? i2 : i8; this.controllerHideOnTouch = z3; this.controllerAutoShow = z; this.controllerHideDuringAds = z2; this.useController = (!z6 || styledPlayerControlView3 == null) ? i8 : z7; if (styledPlayerControlView3 != null) { styledPlayerControlView3.hideImmediately(); this.controller.addVisibilityListener(componentListener); } updateContentDescription(); } public void setPlayer(@Nullable Player player) { Assertions.checkState(Looper.myLooper() == Looper.getMainLooper()); Assertions.checkArgument(player == null || player.getApplicationLooper() == Looper.getMainLooper()); if (player == null) { return; } SubtitleView subtitleView = this.subtitleView; if (subtitleView != null) { subtitleView.setCues(null); } if (useController()) { this.controller.setPlayer(player); } updateBuffering(); updateErrorMessage(); updateForCurrentTrackSelections(true); if (player != null) { if (player.isCommandAvailable(26)) { View view = this.surfaceView; if (view instanceof TextureView) { player.setVideoTextureView((TextureView) view); } else if (view instanceof SurfaceView) { player.setVideoSurfaceView((SurfaceView) view); } updateAspectRatio(); } if (this.subtitleView != null && player.isCommandAvailable(27)) { this.subtitleView.setCues(player.getCurrentCues()); } player.addListener(this.componentListener); maybeShowController(false); return; } hideController(); } @Override // android.view.View public void setVisibility(int i) { super.setVisibility(i); View view = this.surfaceView; if (view instanceof SurfaceView) { view.setVisibility(i); } } public void setResizeMode(int i) { Assertions.checkStateNotNull(this.contentFrame); this.contentFrame.setResizeMode(i); } public void setUseArtwork(boolean z) { Assertions.checkState((z && this.artworkView == null) ? false : true); if (this.useArtwork != z) { this.useArtwork = z; updateForCurrentTrackSelections(false); } } public void setDefaultArtwork(@Nullable Drawable drawable) { if (this.defaultArtwork != drawable) { this.defaultArtwork = drawable; updateForCurrentTrackSelections(false); } } public void setUseController(boolean z) { Assertions.checkState((z && this.controller == null) ? false : true); if (this.useController == z) { return; } this.useController = z; if (useController()) { this.controller.setPlayer(null); } else { StyledPlayerControlView styledPlayerControlView = this.controller; if (styledPlayerControlView != null) { styledPlayerControlView.hide(); this.controller.setPlayer(null); } } updateContentDescription(); } public void setShutterBackgroundColor(int i) { View view = this.shutterView; if (view != null) { view.setBackgroundColor(i); } } public void setKeepContentOnPlayerReset(boolean z) { if (this.keepContentOnPlayerReset != z) { this.keepContentOnPlayerReset = z; updateForCurrentTrackSelections(false); } } public void setShowBuffering(int i) { if (this.showBuffering != i) { this.showBuffering = i; updateBuffering(); } } public void setErrorMessageProvider(@Nullable ErrorMessageProvider errorMessageProvider) { if (errorMessageProvider != null) { updateErrorMessage(); } } public void setCustomErrorMessage(@Nullable CharSequence charSequence) { Assertions.checkState(this.errorMessageView != null); this.customErrorMessage = charSequence; updateErrorMessage(); } @Override // android.view.ViewGroup, android.view.View public boolean dispatchKeyEvent(KeyEvent keyEvent) { boolean isDpadKey = isDpadKey(keyEvent.getKeyCode()); if (isDpadKey && useController() && !this.controller.isFullyVisible()) { maybeShowController(true); return true; } if (dispatchMediaKeyEvent(keyEvent) || super.dispatchKeyEvent(keyEvent)) { maybeShowController(true); return true; } if (isDpadKey && useController()) { maybeShowController(true); } return false; } public boolean dispatchMediaKeyEvent(KeyEvent keyEvent) { return useController() && this.controller.dispatchMediaKeyEvent(keyEvent); } public void showController() { showController(shouldShowControllerIndefinitely()); } public void hideController() { StyledPlayerControlView styledPlayerControlView = this.controller; if (styledPlayerControlView != null) { styledPlayerControlView.hide(); } } public void setControllerShowTimeoutMs(int i) { Assertions.checkStateNotNull(this.controller); this.controllerShowTimeoutMs = i; if (this.controller.isFullyVisible()) { showController(); } } public void setControllerHideOnTouch(boolean z) { Assertions.checkStateNotNull(this.controller); this.controllerHideOnTouch = z; updateContentDescription(); } public void setControllerVisibilityListener(@Nullable StyledPlayerControlView.VisibilityListener visibilityListener) { Assertions.checkStateNotNull(this.controller); StyledPlayerControlView.VisibilityListener visibilityListener2 = this.controllerVisibilityListener; if (visibilityListener2 == visibilityListener) { return; } if (visibilityListener2 != null) { this.controller.removeVisibilityListener(visibilityListener2); } this.controllerVisibilityListener = visibilityListener; if (visibilityListener != null) { this.controller.addVisibilityListener(visibilityListener); } } public void setControllerOnFullScreenModeChangedListener(@Nullable StyledPlayerControlView.OnFullScreenModeChangedListener onFullScreenModeChangedListener) { Assertions.checkStateNotNull(this.controller); this.controller.setOnFullScreenModeChangedListener(onFullScreenModeChangedListener); } @Deprecated public void setControlDispatcher(ControlDispatcher controlDispatcher) { Assertions.checkStateNotNull(this.controller); this.controller.setControlDispatcher(controlDispatcher); } public void setShowRewindButton(boolean z) { Assertions.checkStateNotNull(this.controller); this.controller.setShowRewindButton(z); } public void setShowFastForwardButton(boolean z) { Assertions.checkStateNotNull(this.controller); this.controller.setShowFastForwardButton(z); } public void setShowPreviousButton(boolean z) { Assertions.checkStateNotNull(this.controller); this.controller.setShowPreviousButton(z); } public void setShowNextButton(boolean z) { Assertions.checkStateNotNull(this.controller); this.controller.setShowNextButton(z); } public void setRepeatToggleModes(int i) { Assertions.checkStateNotNull(this.controller); this.controller.setRepeatToggleModes(i); } public void setShowShuffleButton(boolean z) { Assertions.checkStateNotNull(this.controller); this.controller.setShowShuffleButton(z); } public void setShowSubtitleButton(boolean z) { Assertions.checkStateNotNull(this.controller); this.controller.setShowSubtitleButton(z); } public void setShowVrButton(boolean z) { Assertions.checkStateNotNull(this.controller); this.controller.setShowVrButton(z); } public void setShowMultiWindowTimeBar(boolean z) { Assertions.checkStateNotNull(this.controller); this.controller.setShowMultiWindowTimeBar(z); } public void setExtraAdGroupMarkers(@Nullable long[] jArr, @Nullable boolean[] zArr) { Assertions.checkStateNotNull(this.controller); this.controller.setExtraAdGroupMarkers(jArr, zArr); } public void setAspectRatioListener(@Nullable AspectRatioFrameLayout.AspectRatioListener aspectRatioListener) { Assertions.checkStateNotNull(this.contentFrame); this.contentFrame.setAspectRatioListener(aspectRatioListener); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { useController(); return false; } @Override // android.view.View public boolean performClick() { super.performClick(); return toggleControllerVisibility(); } @Override // android.view.View public boolean onTrackballEvent(MotionEvent motionEvent) { useController(); return false; } public void onContentAspectRatioChanged(AspectRatioFrameLayout aspectRatioFrameLayout, float f) { if (aspectRatioFrameLayout != null) { aspectRatioFrameLayout.setAspectRatio(f); } } public final boolean useController() { if (!this.useController) { return false; } Assertions.checkStateNotNull(this.controller); return true; } public final boolean toggleControllerVisibility() { useController(); return false; } public final void maybeShowController(boolean z) { if (!(isPlayingAd() && this.controllerHideDuringAds) && useController()) { boolean z2 = this.controller.isFullyVisible() && this.controller.getShowTimeoutMs() <= 0; boolean shouldShowControllerIndefinitely = shouldShowControllerIndefinitely(); if (z || z2 || shouldShowControllerIndefinitely) { showController(shouldShowControllerIndefinitely); } } } public final void showController(boolean z) { if (useController()) { this.controller.setShowTimeoutMs(z ? 0 : this.controllerShowTimeoutMs); this.controller.show(); } } public final void updateForCurrentTrackSelections(boolean z) { if (this.keepContentOnPlayerReset) { return; } hideArtwork(); closeShutter(); } public final void hideArtwork() { ImageView imageView = this.artworkView; if (imageView != null) { imageView.setImageResource(R.color.transparent); this.artworkView.setVisibility(4); } } public final void closeShutter() { View view = this.shutterView; if (view != null) { view.setVisibility(0); } } public final void updateBuffering() { View view = this.bufferingView; if (view != null) { view.setVisibility(8); } } public final void updateErrorMessage() { TextView textView = this.errorMessageView; if (textView != null) { CharSequence charSequence = this.customErrorMessage; if (charSequence != null) { textView.setText(charSequence); this.errorMessageView.setVisibility(0); } else { textView.setVisibility(8); } } } public final void updateContentDescription() { StyledPlayerControlView styledPlayerControlView = this.controller; if (styledPlayerControlView == null || !this.useController) { setContentDescription(null); } else if (styledPlayerControlView.isFullyVisible()) { setContentDescription(this.controllerHideOnTouch ? getResources().getString(R$string.exo_controls_hide) : null); } else { setContentDescription(getResources().getString(R$string.exo_controls_show)); } } public final void updateAspectRatio() { VideoSize videoSize = VideoSize.UNKNOWN; int i = videoSize.width; int i2 = videoSize.height; int i3 = videoSize.unappliedRotationDegrees; float f = (i2 == 0 || i == 0) ? 0.0f : (i * videoSize.pixelWidthHeightRatio) / i2; View view = this.surfaceView; if (view instanceof TextureView) { if (f > 0.0f && (i3 == 90 || i3 == 270)) { f = 1.0f / f; } if (this.textureViewRotation != 0) { view.removeOnLayoutChangeListener(this.componentListener); } this.textureViewRotation = i3; if (i3 != 0) { this.surfaceView.addOnLayoutChangeListener(this.componentListener); } applyTextureViewRotation((TextureView) this.surfaceView, this.textureViewRotation); } onContentAspectRatioChanged(this.contentFrame, this.surfaceViewIgnoresVideoAspectRatio ? 0.0f : f); } public static void configureEditModeLogoV23(Resources resources, ImageView imageView) { imageView.setImageDrawable(resources.getDrawable(R$drawable.exo_edit_mode_logo, null)); imageView.setBackgroundColor(resources.getColor(R$color.exo_edit_mode_background_color, null)); } public static void configureEditModeLogo(Resources resources, ImageView imageView) { imageView.setImageDrawable(resources.getDrawable(R$drawable.exo_edit_mode_logo)); imageView.setBackgroundColor(resources.getColor(R$color.exo_edit_mode_background_color)); } public static void setResizeModeRaw(AspectRatioFrameLayout aspectRatioFrameLayout, int i) { aspectRatioFrameLayout.setResizeMode(i); } public static void applyTextureViewRotation(TextureView textureView, int i) { Matrix matrix = new Matrix(); float width = textureView.getWidth(); float height = textureView.getHeight(); if (width != 0.0f && height != 0.0f && i != 0) { float f = width / 2.0f; float f2 = height / 2.0f; matrix.postRotate(i, f, f2); RectF rectF = new RectF(0.0f, 0.0f, width, height); RectF rectF2 = new RectF(); matrix.mapRect(rectF2, rectF); matrix.postScale(width / rectF2.width(), height / rectF2.height(), f, f2); } textureView.setTransform(matrix); } public final class ComponentListener implements Player.Listener, View.OnLayoutChangeListener, View.OnClickListener, StyledPlayerControlView.VisibilityListener { public final Timeline$Period period = new Timeline$Period(); public ComponentListener() { } @Override // android.view.View.OnLayoutChangeListener public void onLayoutChange(View view, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) { StyledPlayerView.applyTextureViewRotation((TextureView) view, StyledPlayerView.this.textureViewRotation); } @Override // android.view.View.OnClickListener public void onClick(View view) { StyledPlayerView.this.toggleControllerVisibility(); } @Override // com.google.android.exoplayer2.ui.StyledPlayerControlView.VisibilityListener public void onVisibilityChange(int i) { StyledPlayerView.this.updateContentDescription(); } } }