package com.strmr.ps.ui.player;

import androidx.media3.common.MediaItem;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.source.MediaSource;
import com.strmr.ps.StrmrApp;
import com.strmr.ps.data.model.StreamInfo;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e17;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.kq;
import defpackage.q38;
import defpackage.qo9;
import defpackage.s38;
import java.util.concurrent.ExecutorService;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.player.VideoPlayerActivity$reResolveCurrentStream$1", f = "VideoPlayerActivity.kt", i = {}, l = {6313}, m = "invokeSuspend", n = {}, s = {})
final class ac extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public int a;
    public final /* synthetic */ VideoPlayerActivity b;
    public final /* synthetic */ StreamInfo c;
    public final /* synthetic */ long d;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public ac(VideoPlayerActivity videoPlayerActivity, StreamInfo streamInfo, long j, Continuation continuation) {
        super(2, continuation);
        this.b = videoPlayerActivity;
        this.c = streamInfo;
        this.d = j;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new ac(this.b, this.c, this.d, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((ac) create((ak1) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x00b1 A[Catch: all -> 0x0010, Exception -> 0x0014, TryCatch #1 {Exception -> 0x0014, blocks: (B:5:0x000c, B:24:0x0051, B:26:0x0055, B:28:0x005b, B:30:0x006d, B:31:0x0074, B:33:0x0084, B:34:0x00b1, B:36:0x00be, B:14:0x0023, B:16:0x002a, B:18:0x0031, B:20:0x0037, B:21:0x003b), top: B:46:0x0008, outer: #0 }] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        ck1 ck1Var = ck1.a;
        int i = this.a;
        try {
            try {
                if (i == 0) {
                    s38.b(obj);
                    int i2 = this.b.bx;
                    Integer numBoxInt = i2 > 0 ? Boxing.boxInt(i2) : null;
                    int i3 = this.b.bz;
                    ab abVar = new ab(this.b, this.c, numBoxInt, i3 > 0 ? Boxing.boxInt(i3) : null, null);
                    this.a = 1;
                    obj = qo9.c(20000L, abVar, this);
                    if (obj == ck1Var) {
                        return ck1Var;
                    }
                } else {
                    if (i != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    s38.b(obj);
                }
                q38 q38Var = (q38) obj;
                if (q38Var != null) {
                    Object obj2 = q38Var.a;
                    if (obj2 instanceof q38.b) {
                        ExecutorService executorService = kq.a;
                        kq.h("VideoPlayer", "Re-resolve failed, resuming with existing URL");
                        ExoPlayer exoPlayer = this.b.bm;
                        if (exoPlayer != null) {
                            exoPlayer.setPlayWhenReady(true);
                        }
                    } else {
                        s38.b(obj2);
                        String str = (String) obj2;
                        ExecutorService executorService2 = kq.a;
                        kq.h("VideoPlayer", "Re-resolved debrid link successfully");
                        e17 e17Var = StrmrApp.w;
                        e17 e17Var2 = StrmrApp.w;
                        if (e17Var2 != null) {
                            e17Var2.b(this.b.bs);
                        }
                        VideoPlayerActivity videoPlayerActivity = this.b;
                        videoPlayerActivity.bs = str;
                        videoPlayerActivity.cn = System.currentTimeMillis();
                        VideoPlayerActivity videoPlayerActivity2 = this.b;
                        ExoPlayer exoPlayer2 = videoPlayerActivity2.bm;
                        if (exoPlayer2 != null) {
                            long j = this.d;
                            MediaItem mediaItemBuild = new MediaItem.Builder().setUri(videoPlayerActivity2.an(str)).build();
                            cr4.f(mediaItemBuild, "build(...)");
                            MediaSource mediaSourceAh = videoPlayerActivity2.ah(mediaItemBuild, str);
                            videoPlayerActivity2.bq = mediaSourceAh;
                            videoPlayerActivity2.br = mediaSourceAh;
                            exoPlayer2.setMediaSource(mediaSourceAh);
                            exoPlayer2.seekTo(j);
                            exoPlayer2.prepare();
                            exoPlayer2.setPlayWhenReady(true);
                        }
                    }
                }
            } catch (Exception e) {
                ExecutorService executorService3 = kq.a;
                kq.a("VideoPlayer", "Re-resolve error", e);
                ExoPlayer exoPlayer3 = this.b.bm;
                if (exoPlayer3 != null) {
                    exoPlayer3.setPlayWhenReady(true);
                }
            }
            this.b.cp = false;
            return e6a.a;
        } catch (Throwable th) {
            this.b.cp = false;
            throw th;
        }
    }
}
