package com.applovin.impl; import android.content.Context; import android.net.Uri; import com.applovin.impl.d6; import com.applovin.impl.i5; import com.mbridge.msdk.playercommon.exoplayer2.upstream.RawResourceDataSource; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ public final class v5 implements i5 { private final Context a; private final List b = new ArrayList(); private final i5 c; private i5 d; private i5 e; private i5 f; private i5 g; private i5 h; private i5 i; private i5 j; private i5 k; public static final class a implements i5.a { private final Context a; private final i5.a b; private xo c; public a(Context context) { this(context, new d6.b()); } @Override // com.applovin.impl.i5.a /* renamed from: b, reason: merged with bridge method [inline-methods] */ public v5 a() { v5 v5Var = new v5(this.a, this.b.a()); xo xoVar = this.c; if (xoVar != null) { v5Var.a(xoVar); } return v5Var; } public a(Context context, i5.a aVar) { this.a = context.getApplicationContext(); this.b = aVar; } } public v5(Context context, i5 i5Var) { this.a = context.getApplicationContext(); this.c = (i5) b1.a(i5Var); } @Override // com.applovin.impl.i5 public Uri c() { i5 i5Var = this.k; if (i5Var == null) { return null; } return i5Var.c(); } @Override // com.applovin.impl.i5 public Map e() { i5 i5Var = this.k; return i5Var == null ? Collections.emptyMap() : i5Var.e(); } @Override // com.applovin.impl.i5 public void close() { i5 i5Var = this.k; if (i5Var != null) { try { i5Var.close(); } finally { this.k = null; } } } private i5 m() { if (this.h == null) { np npVar = new np(); this.h = npVar; a(npVar); } return this.h; } private i5 j() { if (this.d == null) { p8 p8Var = new p8(); this.d = p8Var; a(p8Var); } return this.d; } private i5 g() { if (this.e == null) { c1 c1Var = new c1(this.a); this.e = c1Var; a(c1Var); } return this.e; } private i5 h() { if (this.f == null) { s4 s4Var = new s4(this.a); this.f = s4Var; a(s4Var); } return this.f; } private i5 l() { if (this.g == null) { try { i5 i5Var = (i5) Class.forName("com.applovin.exoplayer2.ext.rtmp.RtmpDataSource").getConstructor(new Class[0]).newInstance(new Object[0]); this.g = i5Var; a(i5Var); } catch (ClassNotFoundException unused) { pc.d("DefaultDataSource", "Attempting to play RTMP stream without depending on the RTMP extension"); } catch (Exception e) { throw new RuntimeException("Error instantiating RTMP extension", e); } if (this.g == null) { this.g = this.c; } } return this.g; } private i5 i() { if (this.i == null) { h5 h5Var = new h5(); this.i = h5Var; a(h5Var); } return this.i; } private i5 k() { if (this.j == null) { li liVar = new li(this.a); this.j = liVar; a(liVar); } return this.j; } private void a(i5 i5Var) { for (int i = 0; i < this.b.size(); i++) { i5Var.a((xo) this.b.get(i)); } } @Override // com.applovin.impl.i5 public void a(xo xoVar) { b1.a(xoVar); this.c.a(xoVar); this.b.add(xoVar); a(this.d, xoVar); a(this.e, xoVar); a(this.f, xoVar); a(this.g, xoVar); a(this.h, xoVar); a(this.i, xoVar); a(this.j, xoVar); } private void a(i5 i5Var, xo xoVar) { if (i5Var != null) { i5Var.a(xoVar); } } @Override // com.applovin.impl.i5 public long a(l5 l5Var) { b1.b(this.k == null); String scheme = l5Var.a.getScheme(); if (xp.a(l5Var.a)) { String path = l5Var.a.getPath(); if (path != null && path.startsWith("/android_asset/")) { this.k = g(); } else { this.k = j(); } } else if ("asset".equals(scheme)) { this.k = g(); } else if ("content".equals(scheme)) { this.k = h(); } else if ("rtmp".equals(scheme)) { this.k = l(); } else if ("udp".equals(scheme)) { this.k = m(); } else if ("data".equals(scheme)) { this.k = i(); } else if (RawResourceDataSource.RAW_RESOURCE_SCHEME.equals(scheme) || "android.resource".equals(scheme)) { this.k = k(); } else { this.k = this.c; } return this.k.a(l5Var); } @Override // com.applovin.impl.g5 public int a(byte[] bArr, int i, int i2) { return ((i5) b1.a(this.k)).a(bArr, i, i2); } }