package com.google.android.gms.internal.ads;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.media3.datasource.RawResourceDataSource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

/* JADX INFO: loaded from: classes2.dex */
public final class yy1 implements sv1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f19014a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f19015b = new ArrayList();

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

    @Nullable
    private sv1 zzd;

    @Nullable
    private sv1 zze;

    @Nullable
    private sv1 zzf;

    @Nullable
    private sv1 zzg;

    @Nullable
    private sv1 zzh;

    @Nullable
    private sv1 zzi;

    @Nullable
    private sv1 zzj;

    @Nullable
    private sv1 zzk;

    public yy1(Context context, sv1 sv1Var) {
        this.f19014a = context.getApplicationContext();
        this.f19016c = sv1Var;
    }

    private static final void zzh(@Nullable sv1 sv1Var, u92 u92Var) {
        if (sv1Var != null) {
            sv1Var.g(u92Var);
        }
    }

    @Override // com.google.android.gms.internal.ads.sv1
    public final long b(dy1 dy1Var) {
        ih1.b1(this.zzk == null);
        Uri uri = dy1Var.f10564a;
        String scheme = uri.getScheme();
        String str = bb1.f9474a;
        String scheme2 = uri.getScheme();
        boolean zIsEmpty = TextUtils.isEmpty(scheme2);
        Context context = this.f19014a;
        if (zIsEmpty || Objects.equals(scheme2, "file")) {
            String path = uri.getPath();
            if (path == null || !path.startsWith("/android_asset/")) {
                if (this.zzd == null) {
                    x22 x22Var = new x22(false);
                    this.zzd = x22Var;
                    l(x22Var);
                }
                this.zzk = this.zzd;
            } else {
                if (this.zze == null) {
                    xq1 xq1Var = new xq1(context);
                    this.zze = xq1Var;
                    l(xq1Var);
                }
                this.zzk = this.zze;
            }
        } else if ("asset".equals(scheme)) {
            if (this.zze == null) {
                xq1 xq1Var2 = new xq1(context);
                this.zze = xq1Var2;
                l(xq1Var2);
            }
            this.zzk = this.zze;
        } else if ("content".equals(scheme)) {
            if (this.zzf == null) {
                rt1 rt1Var = new rt1(context);
                this.zzf = rt1Var;
                l(rt1Var);
            }
            this.zzk = this.zzf;
        } else {
            boolean zEquals = "rtmp".equals(scheme);
            sv1 sv1Var = this.f19016c;
            if (zEquals) {
                if (this.zzg == null) {
                    try {
                        sv1 sv1Var2 = (sv1) Class.forName("androidx.media3.datasource.rtmp.RtmpDataSource").getConstructor(new Class[0]).newInstance(new Object[0]);
                        this.zzg = sv1Var2;
                        l(sv1Var2);
                    } catch (ClassNotFoundException unused) {
                        vt0.c("Attempting to play RTMP stream without depending on the RTMP extension");
                    } catch (Exception e10) {
                        throw new RuntimeException("Error instantiating RTMP extension", e10);
                    }
                    if (this.zzg == null) {
                        this.zzg = sv1Var;
                    }
                }
                this.zzk = this.zzg;
            } else if ("udp".equals(scheme)) {
                if (this.zzh == null) {
                    ta2 ta2Var = new ta2();
                    this.zzh = ta2Var;
                    l(ta2Var);
                }
                this.zzk = this.zzh;
            } else if ("data".equals(scheme)) {
                if (this.zzi == null) {
                    tu1 tu1Var = new tu1(false);
                    this.zzi = tu1Var;
                    l(tu1Var);
                }
                this.zzk = this.zzi;
            } else if (RawResourceDataSource.RAW_RESOURCE_SCHEME.equals(scheme) || "android.resource".equals(scheme)) {
                if (this.zzj == null) {
                    u82 u82Var = new u82(context);
                    this.zzj = u82Var;
                    l(u82Var);
                }
                this.zzk = this.zzj;
            } else {
                this.zzk = sv1Var;
            }
        }
        return this.zzk.b(dy1Var);
    }

    @Override // com.google.android.gms.internal.ads.eh2
    public final int d(byte[] bArr, int i10, int i11) {
        sv1 sv1Var = this.zzk;
        sv1Var.getClass();
        return sv1Var.d(bArr, i10, i11);
    }

    @Override // com.google.android.gms.internal.ads.sv1
    public final void g(u92 u92Var) {
        u92Var.getClass();
        this.f19016c.g(u92Var);
        this.f19015b.add(u92Var);
        zzh(this.zzd, u92Var);
        zzh(this.zze, u92Var);
        zzh(this.zzf, u92Var);
        zzh(this.zzg, u92Var);
        zzh(this.zzh, u92Var);
        zzh(this.zzi, u92Var);
        zzh(this.zzj, u92Var);
    }

    public final void l(sv1 sv1Var) {
        int i10 = 0;
        while (true) {
            ArrayList arrayList = this.f19015b;
            if (i10 >= arrayList.size()) {
                return;
            }
            sv1Var.g((u92) arrayList.get(i10));
            i10++;
        }
    }

    @Override // com.google.android.gms.internal.ads.sv1, com.google.android.gms.internal.ads.n72
    @Nullable
    public final Uri zzc() {
        sv1 sv1Var = this.zzk;
        if (sv1Var == null) {
            return null;
        }
        return sv1Var.zzc();
    }

    @Override // com.google.android.gms.internal.ads.sv1
    public final void zzd() {
        sv1 sv1Var = this.zzk;
        if (sv1Var != null) {
            try {
                sv1Var.zzd();
            } finally {
                this.zzk = null;
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.sv1, com.google.android.gms.internal.ads.n72
    public final Map zzj() {
        sv1 sv1Var = this.zzk;
        return sv1Var == null ? Collections.emptyMap() : sv1Var.zzj();
    }
}
