package androidx.media3.ui;

import B0.C0030q;
import B0.F;
import B0.I;
import B0.m0;
import C3.G;
import D1.A;
import D1.B;
import D1.C;
import D1.C0093s;
import D1.E;
import D1.InterfaceC0076a;
import D1.InterfaceC0084i;
import D1.r;
import D1.x;
import K4.c;
import O3.e;
import R0.s;
import S0.l;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
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 android.window.SurfaceSyncGroup;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.image.ImageOutput;
import androidx.media3.ui.PlayerView;
import com.martsnew.tv.R;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import l6.C1139a;
import u0.InterfaceC1576l;
import u0.M;
import u0.Y;
import u0.Z;
import u0.d0;
import x0.AbstractC1709a;
import x0.v;

/* JADX INFO: loaded from: classes.dex */
public class PlayerView extends FrameLayout {

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    public static final /* synthetic */ int f8926W = 0;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final TextView f8927A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final C0093s f8928B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public final FrameLayout f8929C;
    public final FrameLayout D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public final Handler f8930E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final Class f8931F;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public final Method f8932G;
    public final Object H;

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public M f8933I;

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public boolean f8934J;

    /* JADX INFO: renamed from: K, reason: collision with root package name */
    public r f8935K;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public int f8936L;

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public int f8937M;

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    public Drawable f8938N;

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public int f8939O;

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    public boolean f8940P;

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    public CharSequence f8941Q;

    /* JADX INFO: renamed from: R, reason: collision with root package name */
    public int f8942R;

    /* JADX INFO: renamed from: S, reason: collision with root package name */
    public boolean f8943S;

    /* JADX INFO: renamed from: T, reason: collision with root package name */
    public boolean f8944T;

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    public boolean f8945U;

    /* JADX INFO: renamed from: V, reason: collision with root package name */
    public boolean f8946V;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final A f8947q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final AspectRatioFrameLayout f8948r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final View f8949s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final View f8950t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final boolean f8951u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final c f8952v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final ImageView f8953w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final ImageView f8954x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final SubtitleView f8955y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final View f8956z;

    /* JADX WARN: Multi-variable type inference failed */
    public PlayerView(Context context, AttributeSet attributeSet) {
        int i;
        int i5;
        int i8;
        boolean z8;
        boolean z9;
        boolean z10;
        int i9;
        int i10;
        int i11;
        int i12;
        int i13;
        boolean z11;
        boolean z12;
        int i14;
        boolean z13;
        boolean z14;
        boolean z15;
        int i15;
        Class<ExoPlayer> cls;
        Object objNewProxyInstance;
        Method method;
        Class<?>[] clsArr;
        super(context, attributeSet, 0);
        A a3 = new A(this);
        this.f8947q = a3;
        this.f8930E = new Handler(Looper.getMainLooper());
        if (isInEditMode()) {
            this.f8948r = null;
            this.f8949s = null;
            this.f8950t = null;
            this.f8951u = false;
            this.f8952v = null;
            this.f8953w = null;
            this.f8954x = null;
            this.f8955y = null;
            this.f8956z = null;
            this.f8927A = null;
            this.f8928B = null;
            this.f8929C = null;
            this.D = null;
            this.f8931F = null;
            this.f8932G = null;
            this.H = null;
            ImageView imageView = new ImageView(context);
            if (v.f18553a >= 23) {
                Resources resources = getResources();
                imageView.setImageDrawable(resources.getDrawable(R.drawable.exo_edit_mode_logo, context.getTheme()));
                imageView.setBackgroundColor(resources.getColor(R.color.exo_edit_mode_background_color, null));
            } else {
                Resources resources2 = getResources();
                imageView.setImageDrawable(resources2.getDrawable(R.drawable.exo_edit_mode_logo, context.getTheme()));
                imageView.setBackgroundColor(resources2.getColor(R.color.exo_edit_mode_background_color));
            }
            addView(imageView);
            return;
        }
        if (attributeSet != null) {
            TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet, E.f1658d, 0, 0);
            try {
                boolean zHasValue = typedArrayObtainStyledAttributes.hasValue(42);
                int color = typedArrayObtainStyledAttributes.getColor(42, 0);
                int resourceId = typedArrayObtainStyledAttributes.getResourceId(22, R.layout.exo_player_view);
                boolean z16 = typedArrayObtainStyledAttributes.getBoolean(49, true);
                int i16 = typedArrayObtainStyledAttributes.getInt(3, 1);
                int resourceId2 = typedArrayObtainStyledAttributes.getResourceId(9, 0);
                int i17 = typedArrayObtainStyledAttributes.getInt(15, 0);
                boolean z17 = typedArrayObtainStyledAttributes.getBoolean(50, true);
                int i18 = typedArrayObtainStyledAttributes.getInt(45, 1);
                int i19 = typedArrayObtainStyledAttributes.getInt(28, 0);
                int i20 = typedArrayObtainStyledAttributes.getInt(38, 5000);
                z9 = typedArrayObtainStyledAttributes.getBoolean(14, true);
                boolean z18 = typedArrayObtainStyledAttributes.getBoolean(4, true);
                int integer = typedArrayObtainStyledAttributes.getInteger(35, 0);
                this.f8940P = typedArrayObtainStyledAttributes.getBoolean(16, this.f8940P);
                boolean z19 = typedArrayObtainStyledAttributes.getBoolean(13, true);
                typedArrayObtainStyledAttributes.recycle();
                z10 = z19;
                i8 = resourceId2;
                z12 = z16;
                i13 = color;
                i = resourceId;
                i11 = i18;
                i12 = i17;
                i9 = i19;
                i14 = i16;
                z11 = zHasValue;
                i5 = i20;
                z8 = z18;
                z13 = z17;
                i10 = integer;
            } catch (Throwable th) {
                typedArrayObtainStyledAttributes.recycle();
                throw th;
            }
        } else {
            i = R.layout.exo_player_view;
            i5 = 5000;
            i8 = 0;
            z8 = true;
            z9 = true;
            z10 = true;
            i9 = 0;
            i10 = 0;
            i11 = 1;
            i12 = 0;
            i13 = 0;
            z11 = false;
            z12 = true;
            i14 = 1;
            z13 = true;
        }
        LayoutInflater.from(context).inflate(i, this);
        setDescendantFocusability(262144);
        AspectRatioFrameLayout aspectRatioFrameLayout = (AspectRatioFrameLayout) findViewById(R.id.exo_content_frame);
        this.f8948r = aspectRatioFrameLayout;
        if (aspectRatioFrameLayout != null) {
            aspectRatioFrameLayout.setResizeMode(i9);
        }
        View viewFindViewById = findViewById(R.id.exo_shutter);
        this.f8949s = viewFindViewById;
        if (viewFindViewById != null && z11) {
            viewFindViewById.setBackgroundColor(i13);
        }
        if (aspectRatioFrameLayout == null || i11 == 0) {
            z14 = false;
            this.f8950t = null;
            z15 = false;
        } else {
            ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-1, -1);
            if (i11 == 2) {
                this.f8950t = new TextureView(context);
            } else if (i11 == 3) {
                try {
                    int i21 = l.f6258B;
                    this.f8950t = (View) l.class.getConstructor(Context.class).newInstance(context);
                    z15 = true;
                    this.f8950t.setLayoutParams(layoutParams);
                    this.f8950t.setOnClickListener(a3);
                    z14 = false;
                    this.f8950t.setClickable(false);
                    aspectRatioFrameLayout.addView(this.f8950t, 0);
                } catch (Exception e8) {
                    throw new IllegalStateException("spherical_gl_surface_view requires an ExoPlayer dependency", e8);
                }
            } else if (i11 != 4) {
                SurfaceView surfaceView = new SurfaceView(context);
                if (v.f18553a >= 34) {
                    surfaceView.setSurfaceLifecycle(2);
                }
                this.f8950t = surfaceView;
            } else {
                try {
                    int i22 = R0.r.f5979r;
                    this.f8950t = (View) R0.r.class.getConstructor(Context.class).newInstance(context);
                } catch (Exception e9) {
                    throw new IllegalStateException("video_decoder_gl_surface_view requires an ExoPlayer dependency", e9);
                }
            }
            z15 = false;
            this.f8950t.setLayoutParams(layoutParams);
            this.f8950t.setOnClickListener(a3);
            z14 = false;
            this.f8950t.setClickable(false);
            aspectRatioFrameLayout.addView(this.f8950t, 0);
        }
        this.f8951u = z15;
        this.f8952v = v.f18553a == 34 ? new c(8, z14) : null;
        this.f8929C = (FrameLayout) findViewById(R.id.exo_ad_overlay);
        this.D = (FrameLayout) findViewById(R.id.exo_overlay);
        this.f8953w = (ImageView) findViewById(R.id.exo_image);
        this.f8937M = i12;
        try {
            cls = ExoPlayer.class;
            clsArr = new Class[1];
            i15 = 0;
        } catch (ClassNotFoundException | NoSuchMethodException unused) {
            i15 = 0;
        }
        try {
            clsArr[0] = ImageOutput.class;
            method = cls.getMethod("setImageOutput", clsArr);
            objNewProxyInstance = Proxy.newProxyInstance(ImageOutput.class.getClassLoader(), new Class[]{ImageOutput.class}, new InvocationHandler() { // from class: D1.y
                @Override // java.lang.reflect.InvocationHandler
                public final Object invoke(Object obj, Method method2, Object[] objArr) {
                    int i23 = PlayerView.f8926W;
                    PlayerView playerView = this.f1870a;
                    if (!method2.getName().equals("onImageAvailable")) {
                        return null;
                    }
                    playerView.f8930E.post(new B0.A(playerView, 9, (Bitmap) objArr[1]));
                    return null;
                }
            });
        } catch (ClassNotFoundException | NoSuchMethodException unused2) {
            cls = null;
            objNewProxyInstance = null;
            method = null;
        }
        this.f8931F = cls;
        this.f8932G = method;
        this.H = objNewProxyInstance;
        ImageView imageView2 = (ImageView) findViewById(R.id.exo_artwork);
        this.f8954x = imageView2;
        this.f8936L = (!z12 || i14 == 0 || imageView2 == null) ? i15 : i14;
        if (i8 != 0) {
            this.f8938N = getContext().getDrawable(i8);
        }
        SubtitleView subtitleView = (SubtitleView) findViewById(R.id.exo_subtitles);
        this.f8955y = subtitleView;
        if (subtitleView != null) {
            subtitleView.a();
            subtitleView.b();
        }
        View viewFindViewById2 = findViewById(R.id.exo_buffering);
        this.f8956z = viewFindViewById2;
        if (viewFindViewById2 != null) {
            viewFindViewById2.setVisibility(8);
        }
        this.f8939O = i10;
        TextView textView = (TextView) findViewById(R.id.exo_error_message);
        this.f8927A = textView;
        if (textView != null) {
            textView.setVisibility(8);
        }
        C0093s c0093s = (C0093s) findViewById(R.id.exo_controller);
        View viewFindViewById3 = findViewById(R.id.exo_controller_placeholder);
        if (c0093s != null) {
            this.f8928B = c0093s;
        } else if (viewFindViewById3 != null) {
            C0093s c0093s2 = new C0093s(context, attributeSet);
            this.f8928B = c0093s2;
            c0093s2.setId(R.id.exo_controller);
            c0093s2.setLayoutParams(viewFindViewById3.getLayoutParams());
            ViewGroup viewGroup = (ViewGroup) viewFindViewById3.getParent();
            int iIndexOfChild = viewGroup.indexOfChild(viewFindViewById3);
            viewGroup.removeView(viewFindViewById3);
            viewGroup.addView(c0093s2, iIndexOfChild);
        } else {
            this.f8928B = null;
        }
        C0093s c0093s3 = this.f8928B;
        this.f8942R = c0093s3 == null ? i15 : i5;
        this.f8945U = z9;
        this.f8943S = z8;
        this.f8944T = z10;
        this.f8934J = (!z13 || c0093s3 == null) ? i15 : 1;
        if (c0093s3 != null) {
            x xVar = c0093s3.f1814q;
            int i23 = xVar.f1869z;
            if (i23 != 3 && i23 != 2) {
                xVar.f();
                xVar.i(2);
            }
            C0093s c0093s4 = this.f8928B;
            A a8 = this.f8947q;
            c0093s4.getClass();
            a8.getClass();
            c0093s4.f1819t.add(a8);
        }
        if (z13) {
            setClickable(true);
        }
        m();
    }

    public static void a(PlayerView playerView, Bitmap bitmap) {
        playerView.setImage(new BitmapDrawable(playerView.getResources(), bitmap));
        if (playerView.c()) {
            return;
        }
        ImageView imageView = playerView.f8953w;
        if (imageView != null) {
            imageView.setVisibility(0);
            playerView.p();
        }
        View view = playerView.f8949s;
        if (view != null) {
            view.setVisibility(0);
        }
    }

    private void setImage(Drawable drawable) {
        ImageView imageView = this.f8953w;
        if (imageView == null) {
            return;
        }
        imageView.setImageDrawable(drawable);
        p();
    }

    private void setImageOutput(M m8) {
        Class cls = this.f8931F;
        if (cls == null || !cls.isAssignableFrom(m8.getClass())) {
            return;
        }
        try {
            Method method = this.f8932G;
            method.getClass();
            Object obj = this.H;
            obj.getClass();
            method.invoke(m8, obj);
        } catch (IllegalAccessException | InvocationTargetException e8) {
            throw new RuntimeException(e8);
        }
    }

    public final boolean b() {
        M m8 = this.f8933I;
        return m8 != null && this.H != null && ((e) m8).o(30) && ((I) m8).P().a(4);
    }

    public final boolean c() {
        M m8 = this.f8933I;
        return m8 != null && ((e) m8).o(30) && ((I) m8).P().a(2);
    }

    public final void d() {
        ImageView imageView = this.f8953w;
        if (imageView != null) {
            imageView.setVisibility(4);
        }
        if (imageView != null) {
            imageView.setImageResource(android.R.color.transparent);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void dispatchDraw(Canvas canvas) {
        c cVar;
        SurfaceSyncGroup surfaceSyncGroup;
        super.dispatchDraw(canvas);
        if (v.f18553a != 34 || (cVar = this.f8952v) == null || !this.f8946V || (surfaceSyncGroup = (SurfaceSyncGroup) cVar.f3604r) == null) {
            return;
        }
        surfaceSyncGroup.markSyncReady();
        cVar.f3604r = null;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final boolean dispatchKeyEvent(KeyEvent keyEvent) {
        M m8 = this.f8933I;
        if (m8 != null && ((e) m8).o(16) && ((I) this.f8933I).W()) {
            return super.dispatchKeyEvent(keyEvent);
        }
        int keyCode = keyEvent.getKeyCode();
        boolean z8 = keyCode == 19 || keyCode == 270 || keyCode == 22 || keyCode == 271 || keyCode == 20 || keyCode == 269 || keyCode == 21 || keyCode == 268 || keyCode == 23;
        C0093s c0093s = this.f8928B;
        if (z8 && q() && !c0093s.g()) {
            f(true);
            return true;
        }
        if ((q() && c0093s.c(keyEvent)) || super.dispatchKeyEvent(keyEvent)) {
            f(true);
            return true;
        }
        if (z8 && q()) {
            f(true);
        }
        return false;
    }

    public final boolean e() {
        M m8 = this.f8933I;
        return m8 != null && ((e) m8).o(16) && ((I) this.f8933I).W() && ((I) this.f8933I).S();
    }

    public final void f(boolean z8) {
        if (!(e() && this.f8944T) && q()) {
            C0093s c0093s = this.f8928B;
            boolean z9 = c0093s.g() && c0093s.getShowTimeoutMs() <= 0;
            boolean zH = h();
            if (z8 || z9 || zH) {
                i(zH);
            }
        }
    }

    public final boolean g(Drawable drawable) {
        ImageView imageView = this.f8954x;
        if (imageView != null && drawable != null) {
            int intrinsicWidth = drawable.getIntrinsicWidth();
            int intrinsicHeight = drawable.getIntrinsicHeight();
            if (intrinsicWidth > 0 && intrinsicHeight > 0) {
                float width = intrinsicWidth / intrinsicHeight;
                ImageView.ScaleType scaleType = ImageView.ScaleType.FIT_XY;
                if (this.f8936L == 2) {
                    width = getWidth() / getHeight();
                    scaleType = ImageView.ScaleType.CENTER_CROP;
                }
                AspectRatioFrameLayout aspectRatioFrameLayout = this.f8948r;
                if (aspectRatioFrameLayout != null) {
                    aspectRatioFrameLayout.setAspectRatio(width);
                }
                imageView.setScaleType(scaleType);
                imageView.setImageDrawable(drawable);
                imageView.setVisibility(0);
                return true;
            }
        }
        return false;
    }

    public List<C1139a> getAdOverlayInfos() {
        ArrayList arrayList = new ArrayList();
        FrameLayout frameLayout = this.D;
        if (frameLayout != null) {
            arrayList.add(new C1139a(frameLayout));
        }
        C0093s c0093s = this.f8928B;
        if (c0093s != null) {
            arrayList.add(new C1139a(c0093s));
        }
        return G.k(arrayList);
    }

    public ViewGroup getAdViewGroup() {
        FrameLayout frameLayout = this.f8929C;
        AbstractC1709a.l(frameLayout, "exo_ad_overlay must be present for ad playback");
        return frameLayout;
    }

    public int getArtworkDisplayMode() {
        return this.f8936L;
    }

    public boolean getControllerAutoShow() {
        return this.f8943S;
    }

    public boolean getControllerHideOnTouch() {
        return this.f8945U;
    }

    public int getControllerShowTimeoutMs() {
        return this.f8942R;
    }

    public Drawable getDefaultArtwork() {
        return this.f8938N;
    }

    public int getImageDisplayMode() {
        return this.f8937M;
    }

    public FrameLayout getOverlayFrameLayout() {
        return this.D;
    }

    public M getPlayer() {
        return this.f8933I;
    }

    public int getResizeMode() {
        AspectRatioFrameLayout aspectRatioFrameLayout = this.f8948r;
        AbstractC1709a.k(aspectRatioFrameLayout);
        return aspectRatioFrameLayout.getResizeMode();
    }

    public SubtitleView getSubtitleView() {
        return this.f8955y;
    }

    @Deprecated
    public boolean getUseArtwork() {
        return this.f8936L != 0;
    }

    public boolean getUseController() {
        return this.f8934J;
    }

    public View getVideoSurfaceView() {
        return this.f8950t;
    }

    public final boolean h() {
        M m8 = this.f8933I;
        if (m8 == null) {
            return true;
        }
        int iT = ((I) m8).T();
        if (!this.f8943S) {
            return false;
        }
        if (((e) this.f8933I).o(17) && ((I) this.f8933I).O().p()) {
            return false;
        }
        if (iT != 1 && iT != 4) {
            M m9 = this.f8933I;
            m9.getClass();
            if (((I) m9).S()) {
                return false;
            }
        }
        return true;
    }

    public final void i(boolean z8) {
        if (q()) {
            int i = z8 ? 0 : this.f8942R;
            C0093s c0093s = this.f8928B;
            c0093s.setShowTimeoutMs(i);
            x xVar = c0093s.f1814q;
            C0093s c0093s2 = xVar.f1845a;
            if (!c0093s2.h()) {
                c0093s2.setVisibility(0);
                c0093s2.i();
                ImageView imageView = c0093s2.f1770E;
                if (imageView != null) {
                    imageView.requestFocus();
                }
            }
            xVar.k();
        }
    }

    public final void j() {
        if (!q() || this.f8933I == null) {
            return;
        }
        C0093s c0093s = this.f8928B;
        if (!c0093s.g()) {
            f(true);
        } else if (this.f8945U) {
            c0093s.f();
        }
    }

    public final void k() {
        d0 d0Var;
        M m8 = this.f8933I;
        if (m8 != null) {
            I i = (I) m8;
            i.p0();
            d0Var = i.f576u0;
        } else {
            d0Var = d0.f17268d;
        }
        int i5 = d0Var.f17269a;
        int i8 = d0Var.f17270b;
        float f3 = this.f8951u ? 0.0f : (i8 == 0 || i5 == 0) ? 0.0f : (i5 * d0Var.f17271c) / i8;
        AspectRatioFrameLayout aspectRatioFrameLayout = this.f8948r;
        if (aspectRatioFrameLayout != null) {
            aspectRatioFrameLayout.setAspectRatio(f3);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void l() {
        boolean z8;
        View view = this.f8956z;
        if (view != null) {
            M m8 = this.f8933I;
            if (m8 == null || ((I) m8).T() != 2) {
                z8 = false;
            } else {
                int i = this.f8939O;
                z8 = true;
                if (i != 2 && (i != 1 || !((I) this.f8933I).S())) {
                }
            }
            view.setVisibility(z8 ? 0 : 8);
        }
    }

    public final void m() {
        C0093s c0093s = this.f8928B;
        if (c0093s == null || !this.f8934J) {
            setContentDescription(null);
        } else if (c0093s.g()) {
            setContentDescription(this.f8945U ? getResources().getString(R.string.exo_controls_hide) : null);
        } else {
            setContentDescription(getResources().getString(R.string.exo_controls_show));
        }
    }

    public final void n() {
        TextView textView = this.f8927A;
        if (textView != null) {
            CharSequence charSequence = this.f8941Q;
            if (charSequence != null) {
                textView.setText(charSequence);
                textView.setVisibility(0);
                return;
            }
            M m8 = this.f8933I;
            if (m8 != null) {
                I i = (I) m8;
                i.p0();
                C0030q c0030q = i.f580w0.f820f;
            }
            textView.setVisibility(8);
        }
    }

    public final void o(boolean z8) {
        Drawable drawable;
        M m8 = this.f8933I;
        boolean zG = false;
        boolean z9 = (m8 == null || !((e) m8).o(30) || ((I) m8).P().f17252a.isEmpty()) ? false : true;
        boolean z10 = this.f8940P;
        ImageView imageView = this.f8954x;
        View view = this.f8949s;
        if (!z10 && (!z9 || z8)) {
            if (imageView != null) {
                imageView.setImageResource(android.R.color.transparent);
                imageView.setVisibility(4);
            }
            if (view != null) {
                view.setVisibility(0);
            }
            d();
        }
        if (z9) {
            boolean zC = c();
            boolean zB = b();
            if (!zC && !zB) {
                if (view != null) {
                    view.setVisibility(0);
                }
                d();
            }
            ImageView imageView2 = this.f8953w;
            boolean z11 = (view == null || view.getVisibility() != 4 || imageView2 == null || (drawable = imageView2.getDrawable()) == null || drawable.getAlpha() == 0) ? false : true;
            if (zB && !zC && z11) {
                if (view != null) {
                    view.setVisibility(0);
                }
                if (imageView2 != null) {
                    imageView2.setVisibility(0);
                    p();
                }
            } else if (zC && !zB && z11) {
                d();
            }
            if (!zC && !zB && this.f8936L != 0) {
                AbstractC1709a.k(imageView);
                if (m8 != null && ((e) m8).o(18)) {
                    I i = (I) m8;
                    i.p0();
                    byte[] bArr = i.f558f0.f17130f;
                    if (bArr != null) {
                        zG = g(new BitmapDrawable(getResources(), BitmapFactory.decodeByteArray(bArr, 0, bArr.length)));
                    }
                }
                if (zG || g(this.f8938N)) {
                    return;
                }
            }
            if (imageView != null) {
                imageView.setImageResource(android.R.color.transparent);
                imageView.setVisibility(4);
            }
        }
    }

    @Override // android.view.View
    public final boolean onTrackballEvent(MotionEvent motionEvent) {
        if (!q() || this.f8933I == null) {
            return false;
        }
        f(true);
        return true;
    }

    public final void p() {
        Drawable drawable;
        AspectRatioFrameLayout aspectRatioFrameLayout;
        ImageView imageView = this.f8953w;
        if (imageView == null || (drawable = imageView.getDrawable()) == null) {
            return;
        }
        int intrinsicWidth = drawable.getIntrinsicWidth();
        int intrinsicHeight = drawable.getIntrinsicHeight();
        if (intrinsicWidth <= 0 || intrinsicHeight <= 0) {
            return;
        }
        float width = intrinsicWidth / intrinsicHeight;
        ImageView.ScaleType scaleType = ImageView.ScaleType.FIT_XY;
        if (this.f8937M == 1) {
            width = getWidth() / getHeight();
            scaleType = ImageView.ScaleType.CENTER_CROP;
        }
        if (imageView.getVisibility() == 0 && (aspectRatioFrameLayout = this.f8948r) != null) {
            aspectRatioFrameLayout.setAspectRatio(width);
        }
        imageView.setScaleType(scaleType);
    }

    @Override // android.view.View
    public final boolean performClick() {
        j();
        return super.performClick();
    }

    public final boolean q() {
        if (!this.f8934J) {
            return false;
        }
        AbstractC1709a.k(this.f8928B);
        return true;
    }

    public void setArtworkDisplayMode(int i) {
        AbstractC1709a.j(i == 0 || this.f8954x != null);
        if (this.f8936L != i) {
            this.f8936L = i;
            o(false);
        }
    }

    public void setAspectRatioListener(InterfaceC0076a interfaceC0076a) {
        AspectRatioFrameLayout aspectRatioFrameLayout = this.f8948r;
        AbstractC1709a.k(aspectRatioFrameLayout);
        aspectRatioFrameLayout.setAspectRatioListener(interfaceC0076a);
    }

    public void setControllerAnimationEnabled(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setAnimationEnabled(z8);
    }

    public void setControllerAutoShow(boolean z8) {
        this.f8943S = z8;
    }

    public void setControllerHideDuringAds(boolean z8) {
        this.f8944T = z8;
    }

    public void setControllerHideOnTouch(boolean z8) {
        AbstractC1709a.k(this.f8928B);
        this.f8945U = z8;
        m();
    }

    @Deprecated
    public void setControllerOnFullScreenModeChangedListener(InterfaceC0084i interfaceC0084i) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setOnFullScreenModeChangedListener(interfaceC0084i);
    }

    public void setControllerShowTimeoutMs(int i) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        this.f8942R = i;
        if (c0093s.g()) {
            i(h());
        }
    }

    public void setControllerVisibilityListener(B b8) {
        if (b8 != null) {
            setControllerVisibilityListener((r) null);
        }
    }

    public void setCustomErrorMessage(CharSequence charSequence) {
        AbstractC1709a.j(this.f8927A != null);
        this.f8941Q = charSequence;
        n();
    }

    public void setDefaultArtwork(Drawable drawable) {
        if (this.f8938N != drawable) {
            this.f8938N = drawable;
            o(false);
        }
    }

    public void setEnableComposeSurfaceSyncWorkaround(boolean z8) {
        this.f8946V = z8;
    }

    public void setErrorMessageProvider(InterfaceC1576l interfaceC1576l) {
        if (interfaceC1576l != null) {
            n();
        }
    }

    public void setFullscreenButtonClickListener(C c3) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setOnFullScreenModeChangedListener(this.f8947q);
    }

    public void setFullscreenButtonState(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.k(z8);
    }

    public void setImageDisplayMode(int i) {
        AbstractC1709a.j(this.f8953w != null);
        if (this.f8937M != i) {
            this.f8937M = i;
            p();
        }
    }

    public void setKeepContentOnPlayerReset(boolean z8) {
        if (this.f8940P != z8) {
            this.f8940P = z8;
            o(false);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:111:0x01fa  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void setPlayer(M m8) {
        boolean z8 = true;
        AbstractC1709a.j(Looper.myLooper() == Looper.getMainLooper());
        AbstractC1709a.d(m8 == null || ((I) m8).f537J == Looper.getMainLooper());
        M m9 = this.f8933I;
        if (m9 == m8) {
            return;
        }
        View view = this.f8950t;
        A a3 = this.f8947q;
        if (m9 != null) {
            I i = (I) m9;
            i.c0(a3);
            if (((e) m9).o(27)) {
                if (view instanceof TextureView) {
                    TextureView textureView = (TextureView) view;
                    i.p0();
                    if (textureView != null && textureView == i.f564l0) {
                        i.G();
                    }
                } else if (view instanceof SurfaceView) {
                    SurfaceView surfaceView = (SurfaceView) view;
                    i.p0();
                    SurfaceHolder holder = surfaceView == null ? null : surfaceView.getHolder();
                    i.p0();
                    if (holder != null && holder == i.f561i0) {
                        i.G();
                    }
                }
            }
            Class cls = this.f8931F;
            if (cls != null && cls.isAssignableFrom(m9.getClass())) {
                try {
                    Method method = this.f8932G;
                    method.getClass();
                    method.invoke(m9, null);
                } catch (IllegalAccessException | InvocationTargetException e8) {
                    throw new RuntimeException(e8);
                }
            }
        }
        SubtitleView subtitleView = this.f8955y;
        if (subtitleView != null) {
            subtitleView.setCues(null);
        }
        this.f8933I = m8;
        boolean zQ = q();
        C0093s c0093s = this.f8928B;
        if (zQ) {
            c0093s.setPlayer(m8);
        }
        l();
        n();
        o(true);
        if (m8 == null) {
            if (c0093s != null) {
                c0093s.f();
                return;
            }
            return;
        }
        e eVar = (e) m8;
        if (eVar.o(27)) {
            if (view instanceof TextureView) {
                TextureView textureView2 = (TextureView) view;
                I i5 = (I) m8;
                i5.p0();
                if (textureView2 == null) {
                    i5.G();
                } else {
                    i5.e0();
                    i5.f564l0 = textureView2;
                    if (textureView2.getSurfaceTextureListener() != null) {
                        AbstractC1709a.B("ExoPlayerImpl", "Replacing existing SurfaceTextureListener.");
                    }
                    textureView2.setSurfaceTextureListener(i5.f543P);
                    SurfaceTexture surfaceTexture = textureView2.isAvailable() ? textureView2.getSurfaceTexture() : null;
                    if (surfaceTexture == null) {
                        i5.j0(null);
                        i5.a0(0, 0);
                    } else {
                        Surface surface = new Surface(surfaceTexture);
                        i5.j0(surface);
                        i5.f560h0 = surface;
                        i5.a0(textureView2.getWidth(), textureView2.getHeight());
                    }
                }
            } else if (view instanceof SurfaceView) {
                SurfaceView surfaceView2 = (SurfaceView) view;
                I i8 = (I) m8;
                i8.p0();
                if (surfaceView2 instanceof s) {
                    i8.e0();
                    i8.j0(surfaceView2);
                    i8.g0(surfaceView2.getHolder());
                } else {
                    boolean z9 = surfaceView2 instanceof l;
                    F f3 = i8.f543P;
                    if (z9) {
                        i8.e0();
                        i8.f562j0 = (l) surfaceView2;
                        m0 m0VarH = i8.H(i8.f544Q);
                        AbstractC1709a.j(!m0VarH.f855f);
                        m0VarH.f852c = 10000;
                        l lVar = i8.f562j0;
                        AbstractC1709a.j(!m0VarH.f855f);
                        m0VarH.f853d = lVar;
                        m0VarH.b();
                        i8.f562j0.f6260q.add(f3);
                        i8.j0(i8.f562j0.getVideoSurface());
                        i8.g0(surfaceView2.getHolder());
                    } else {
                        SurfaceHolder holder2 = surfaceView2 == null ? null : surfaceView2.getHolder();
                        i8.p0();
                        if (holder2 == null) {
                            i8.G();
                        } else {
                            i8.e0();
                            i8.f563k0 = true;
                            i8.f561i0 = holder2;
                            holder2.addCallback(f3);
                            Surface surface2 = holder2.getSurface();
                            if (surface2 == null || !surface2.isValid()) {
                                i8.j0(null);
                                i8.a0(0, 0);
                            } else {
                                i8.j0(surface2);
                                Rect surfaceFrame = holder2.getSurfaceFrame();
                                i8.a0(surfaceFrame.width(), surfaceFrame.height());
                            }
                        }
                    }
                }
            }
            if (eVar.o(30)) {
                Z zP = ((I) m8).P();
                int i9 = 0;
                loop0: while (true) {
                    G g8 = zP.f17252a;
                    if (i9 >= g8.size()) {
                        z8 = false;
                        break;
                    }
                    if (((Y) g8.get(i9)).f17247b.f17202c == 2) {
                        Y y8 = (Y) g8.get(i9);
                        for (int i10 = 0; i10 < y8.f17249d.length; i10++) {
                            if (y8.a(i10)) {
                                break loop0;
                            }
                        }
                    }
                    i9++;
                }
                if (z8) {
                    k();
                }
            }
        }
        if (subtitleView != null && eVar.o(28)) {
            I i11 = (I) m8;
            i11.p0();
            subtitleView.setCues(i11.q0.f18214a);
        }
        a3.getClass();
        ((I) m8).f532C.a(a3);
        setImageOutput(m8);
        f(false);
    }

    public void setRepeatToggleModes(int i) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setRepeatToggleModes(i);
    }

    public void setResizeMode(int i) {
        AspectRatioFrameLayout aspectRatioFrameLayout = this.f8948r;
        AbstractC1709a.k(aspectRatioFrameLayout);
        aspectRatioFrameLayout.setResizeMode(i);
    }

    public void setShowBuffering(int i) {
        if (this.f8939O != i) {
            this.f8939O = i;
            l();
        }
    }

    public void setShowFastForwardButton(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowFastForwardButton(z8);
    }

    @Deprecated
    public void setShowMultiWindowTimeBar(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowMultiWindowTimeBar(z8);
    }

    public void setShowNextButton(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowNextButton(z8);
    }

    public void setShowPlayButtonIfPlaybackIsSuppressed(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowPlayButtonIfPlaybackIsSuppressed(z8);
    }

    public void setShowPreviousButton(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowPreviousButton(z8);
    }

    public void setShowRewindButton(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowRewindButton(z8);
    }

    public void setShowShuffleButton(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowShuffleButton(z8);
    }

    public void setShowSubtitleButton(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowSubtitleButton(z8);
    }

    public void setShowVrButton(boolean z8) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        c0093s.setShowVrButton(z8);
    }

    public void setShutterBackgroundColor(int i) {
        View view = this.f8949s;
        if (view != null) {
            view.setBackgroundColor(i);
        }
    }

    @Deprecated
    public void setUseArtwork(boolean z8) {
        setArtworkDisplayMode(!z8 ? 1 : 0);
    }

    public void setUseController(boolean z8) {
        boolean z9 = true;
        C0093s c0093s = this.f8928B;
        AbstractC1709a.j((z8 && c0093s == null) ? false : true);
        if (!z8 && !hasOnClickListeners()) {
            z9 = false;
        }
        setClickable(z9);
        if (this.f8934J == z8) {
            return;
        }
        this.f8934J = z8;
        if (q()) {
            c0093s.setPlayer(this.f8933I);
        } else if (c0093s != null) {
            c0093s.f();
            c0093s.setPlayer(null);
        }
        m();
    }

    @Override // android.view.View
    public void setVisibility(int i) {
        super.setVisibility(i);
        View view = this.f8950t;
        if (view instanceof SurfaceView) {
            view.setVisibility(i);
        }
    }

    @Deprecated
    public void setControllerVisibilityListener(r rVar) {
        C0093s c0093s = this.f8928B;
        AbstractC1709a.k(c0093s);
        r rVar2 = this.f8935K;
        if (rVar2 == rVar) {
            return;
        }
        CopyOnWriteArrayList copyOnWriteArrayList = c0093s.f1819t;
        if (rVar2 != null) {
            copyOnWriteArrayList.remove(rVar2);
        }
        this.f8935K = rVar;
        if (rVar != null) {
            copyOnWriteArrayList.add(rVar);
            setControllerVisibilityListener((B) null);
        }
    }
}
