package e5;

import A2.u;
import W.T;
import a.AbstractC0212a;
import android.os.Build;
import d4.C0545d;
import d4.C0546e;
import e4.AbstractC0577u;
import io.sentry.C0732k1;
import r4.AbstractC0983h;

/* JADX INFO: loaded from: classes.dex */
public final class n {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final d5.e f6295a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final d5.f f6296b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public d5.a f6297c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final io.sentry.internal.debugmeta.c f6298d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public h f6299e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public f5.c f6300f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public float f6301g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public float f6302h;
    public float i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public d5.h f6303j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public d5.g f6304k;

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f6308o;
    public final A1.h p;

    public n(d5.e eVar, d5.f fVar, d5.a aVar, io.sentry.internal.debugmeta.c cVar) {
        AbstractC0983h.e("ref", eVar);
        AbstractC0983h.e("soundPoolManager", cVar);
        this.f6295a = eVar;
        this.f6296b = fVar;
        this.f6297c = aVar;
        this.f6298d = cVar;
        this.f6301g = 1.0f;
        this.i = 1.0f;
        this.f6303j = d5.h.f6163k;
        this.f6304k = d5.g.f6161k;
        this.f6305l = true;
        this.f6308o = -1;
        T t4 = new T(2, this);
        O0.a aVar2 = new O0.a(4, this);
        this.p = Build.VERSION.SDK_INT >= 26 ? new b(this, t4, aVar2, 1) : new b(this, t4, aVar2, 0);
    }

    public static void j(h hVar, float f6, float f7) {
        hVar.B(Math.min(1.0f, 1.0f - f7) * f6, Math.min(1.0f, f7 + 1.0f) * f6);
    }

    public final void a(h hVar) {
        j(hVar, this.f6301g, this.f6302h);
        hVar.b(this.f6303j == d5.h.f6164l);
        hVar.n();
    }

    public final h b() {
        int iOrdinal = this.f6304k.ordinal();
        if (iOrdinal == 0) {
            return new C0732k1(this);
        }
        if (iOrdinal == 1) {
            return new l(this, this.f6298d);
        }
        throw new u();
    }

    public final void c(String str) {
        AbstractC0983h.e("message", str);
        this.f6295a.getClass();
        this.f6296b.a("audio.onLog", AbstractC0577u.n(new C0545d("value", str)));
    }

    public final void d() {
        h hVar;
        if (this.f6307n) {
            this.f6307n = false;
            if (!this.f6306m || (hVar = this.f6299e) == null) {
                return;
            }
            hVar.pause();
        }
    }

    public final void e() {
        h hVar;
        this.p.v();
        if (this.f6305l) {
            return;
        }
        if (this.f6307n && (hVar = this.f6299e) != null) {
            hVar.stop();
        }
        i(null);
        this.f6299e = null;
    }

    public final void f() {
        A1.h hVar = this.p;
        if (!AbstractC0983h.a(hVar.n(), hVar.s().f6297c)) {
            hVar.E(hVar.s().f6297c);
            hVar.I();
        }
        if (hVar.w()) {
            hVar.C();
        } else {
            hVar.q().invoke();
        }
    }

    public final void g(d5.g gVar) {
        Object objE;
        if (this.f6304k != gVar) {
            this.f6304k = gVar;
            h hVar = this.f6299e;
            if (hVar != null) {
                try {
                    Integer numD = hVar.D();
                    if (numD == null) {
                        objE = numD;
                    } else {
                        int iIntValue = numD.intValue();
                        objE = numD;
                        if (iIntValue == 0) {
                            objE = null;
                        }
                    }
                } catch (Throwable th) {
                    objE = AbstractC0212a.e(th);
                }
                Integer num = (Integer) (objE instanceof C0546e ? null : objE);
                this.f6308o = num != null ? num.intValue() : -1;
                h(false);
                hVar.release();
            }
            h hVarB = b();
            this.f6299e = hVarB;
            f5.c cVar = this.f6300f;
            if (cVar != null) {
                hVarB.z(cVar);
                a(hVarB);
            }
        }
    }

    public final void h(boolean z5) {
        if (this.f6306m != z5) {
            this.f6306m = z5;
            this.f6295a.getClass();
            d5.e.c(this, z5);
        }
    }

    public final void i(f5.c cVar) {
        if (AbstractC0983h.a(this.f6300f, cVar)) {
            this.f6295a.getClass();
            d5.e.c(this, true);
            return;
        }
        if (cVar != null) {
            h hVarB = this.f6299e;
            if (this.f6305l || hVarB == null) {
                hVarB = b();
                this.f6299e = hVarB;
                this.f6305l = false;
            } else if (this.f6306m) {
                hVarB.E();
                h(false);
            }
            hVarB.z(cVar);
            a(hVarB);
        } else {
            this.f6305l = true;
            h(false);
            this.f6307n = false;
            h hVar = this.f6299e;
            if (hVar != null) {
                hVar.release();
            }
        }
        this.f6300f = cVar;
    }

    public final void k() {
        h hVar;
        this.p.v();
        if (this.f6305l) {
            return;
        }
        if (this.f6303j == d5.h.f6163k) {
            e();
            return;
        }
        d();
        if (this.f6306m) {
            h hVar2 = this.f6299e;
            int i = 0;
            if (hVar2 == null || !hVar2.u()) {
                if (this.f6306m && ((hVar = this.f6299e) == null || !hVar.u())) {
                    h hVar3 = this.f6299e;
                    if (hVar3 != null) {
                        hVar3.w(0);
                    }
                    i = -1;
                }
                this.f6308o = i;
                return;
            }
            h hVar4 = this.f6299e;
            if (hVar4 != null) {
                hVar4.stop();
            }
            h(false);
            h hVar5 = this.f6299e;
            if (hVar5 != null) {
                hVar5.n();
            }
        }
    }

    public final void l(d5.a aVar) {
        if (this.f6297c.equals(aVar)) {
            return;
        }
        if (this.f6297c.f6150e != 0 && aVar.f6150e == 0) {
            this.p.v();
        }
        this.f6297c = d5.a.b(aVar);
        d5.e eVar = this.f6295a;
        eVar.a().setMode(this.f6297c.f6151f);
        eVar.a().setSpeakerphoneOn(this.f6297c.f6146a);
        h hVar = this.f6299e;
        if (hVar != null) {
            hVar.stop();
            h(false);
            hVar.g(this.f6297c);
            f5.c cVar = this.f6300f;
            if (cVar != null) {
                hVar.z(cVar);
                a(hVar);
            }
        }
    }
}
