盛康基办.apk(点击下载) / PlayerUtils.java


package im.guobwnxjuc.messenger.utils;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.Base64;
import android.view.MotionEvent;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.core.internal.view.SupportMenu;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.offline.DownloadAction;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.gms.common.internal.ImagesContract;
import com.king.zxing.util.LogUtils;
import im.guobwnxjuc.messenger.AndroidUtilities;
import im.guobwnxjuc.messenger.ApplicationLoader;
import im.guobwnxjuc.messenger.Bitmaps;
import im.guobwnxjuc.messenger.BuildVars;
import im.guobwnxjuc.messenger.FileLoader;
import im.guobwnxjuc.messenger.FileLog;
import im.guobwnxjuc.messenger.ImageLocation;
import im.guobwnxjuc.messenger.ImageReceiver;
import im.guobwnxjuc.messenger.R;
import im.guobwnxjuc.messenger.Utilities;
import im.guobwnxjuc.messenger.utils.PlayerUtils;
import im.guobwnxjuc.tgnet.TLRPC;
import im.guobwnxjuc.ui.components.LayoutHelper;
import im.guobwnxjuc.ui.components.RadialProgressView;
import im.guobwnxjuc.ui.components.VideoPlayer;
import im.guobwnxjuc.ui.hviews.ScaleTextureView;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.slf4j.Marker;

public class PlayerUtils extends ViewGroup implements VideoPlayer.VideoPlayerDelegate, AudioManager.OnAudioFocusChangeListener {
    private static final int AUDIO_FOCUSED = 2;
    private static final int AUDIO_NO_FOCUS_CAN_DUCK = 1;
    private static final int AUDIO_NO_FOCUS_NO_DUCK = 0;
    private static final Pattern aparatFileListPattern = Pattern.compile("fileList\\s*=\\s*JSON\\.parse\\('([^']+)'\\)");
    private static final Pattern aparatIdRegex = Pattern.compile("^https?://(?:www\\.)?aparat\\.com/(?:v/|video/video/embed/videohash/)([a-zA-Z0-9]+)");
    private static final Pattern coubIdRegex = Pattern.compile("(?:coub:|https?://(?:coub\\.com/(?:view|embed|coubs)/|c-cdn\\.coub\\.com/fb-player\\.swf\\?.*\\bcoub(?:ID|id)=))([\\da-z]+)");
    private static final String exprName = "[a-zA-Z_$][a-zA-Z_$0-9]*";
    private static final Pattern exprParensPattern = Pattern.compile("[()]");
    private static final Pattern jsPattern = Pattern.compile("\"assets\":.+?\"js\":\\s*(\"[^\"]+\")");
    private static int lastContainerId = 4001;
    private static PlayerUtils mPlayer;
    private static final Pattern playerIdPattern = Pattern.compile(".*?-([a-zA-Z0-9_-]+)(?:/watch_as3|/html5player(?:-new)?|(?:/[a-z]{2}_[A-Z]{2})?/base)?\\.([a-z]+)$");
    private static final Pattern sigPattern = Pattern.compile("\\.sig\\|\\|([a-zA-Z0-9$]+)\\(");
    private static final Pattern sigPattern2 = Pattern.compile("[\"']signature[\"']\\s*,\\s*([a-zA-Z0-9$]+)\\(");
    private static final Pattern stmtReturnPattern = Pattern.compile("return(?:\\s+|$)");
    private static final Pattern stmtVarPattern = Pattern.compile("var\\s");
    private static final Pattern stsPattern = Pattern.compile("\"sts\"\\s*:\\s*(\\d+)");
    private static final Pattern twitchClipFilePattern = Pattern.compile("clipInfo\\s*=\\s*(\\{[^']+\\});");
    private static final Pattern twitchClipIdRegex = Pattern.compile("https?://clips\\.twitch\\.tv/(?:[^/]+/)*([^/?#&]+)");
    private static final Pattern twitchStreamIdRegex = Pattern.compile("https?://(?:(?:www\\.)?twitch\\.tv/|player\\.twitch\\.tv/\\?.*?\\bchannel=)([^/#?]+)");
    private static final Pattern vimeoIdRegex = Pattern.compile("https?://(?:(?:www|(player))\\.)?vimeo(pro)?\\.com/(?!(?:channels|album)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/)(?:.*?/)?(?:(?:play_redirect_hls|moogaloop\\.swf)\\?clip_id=)?(?:videos?/)?([0-9]+)(?:/[\\da-f]+)?/?(?:[?&].*)?(?:[#].*)?$");
    private static final Pattern youtubeIdRegex = Pattern.compile("(?:youtube(?:-nocookie)?\\.com/(?:[^/\\n\\s]+/\\S+/|(?:v|e(?:mbed)?)/|\\S*?[?&]v=)|youtu\\.be/)([a-zA-Z0-9_-]{11})");
    private boolean allowInlineAnimation;
    private AspectRatioFrameLayout aspectRatioFrameLayout;
    private int audioFocus;
    private Paint backgroundPaint;
    private TextureView changedTextureView;
    private boolean changingTextureView;
    private ControlsView controlsView;
    private float currentAlpha;
    private Bitmap currentBitmap;
    private AsyncTask currentTask;
    private String currentYoutubeId;
    private WebPlayerViewDelegate delegate;
    private boolean drawImage;
    private boolean firstFrameRendered;
    private int fragment_container_id;
    private ImageView fullscreenButton;
    private boolean hasAudioFocus;
    private boolean inFullscreen;
    private boolean initFailed;
    private boolean initied;
    private ImageView inlineButton;
    private String interfaceName;
    private boolean isAutoplay;
    private boolean isCompleted;
    private boolean isInline;
    private boolean isLoading;
    private boolean isStream;
    private long lastUpdateTime;
    private String playAudioType;
    private String playAudioUrl;
    private ImageView playButton;
    private String playVideoType;
    private String playVideoUrl;
    private AnimatorSet progressAnimation;
    private Runnable progressRunnable;
    private RadialProgressView progressView;
    private boolean resumeAudioOnFocusGain;
    private int seekToTime;
    private ImageView shareButton;
    private TextureView.SurfaceTextureListener surfaceTextureListener;
    private Runnable switchToInlineRunnable;
    private boolean switchingInlineMode;
    private ImageView textureImageView;
    private ScaleTextureView textureView;
    private ViewGroup textureViewContainer;
    private VideoPlayer videoPlayer;
    private int waitingForFirstTextureUpload;
    private WebView webView;

    public interface CallJavaResultInterface {
        void jsCallFinished(String str);
    }

    public interface WebPlayerViewDelegate {
        boolean checkInlinePermissions();

        ViewGroup getTextureViewContainer();

        void onInitFailed();

        void onInlineSurfaceTextureReady();

        void onPlayStateChanged(PlayerUtils playerUtils, boolean z, int i);

        void onSharePressed();

        TextureView onSwitchInlineMode(View view, boolean z, float f, int i, boolean z2);

        TextureView onSwitchToFullscreen(View view, boolean z, float f, int i, boolean z2);

        void onVideoSizeChanged(float f, int i);

        void prepareToSwitchInlineMode(boolean z, Runnable runnable, float f, boolean z2);
    }

    private abstract class function {
        public abstract Object run(Object[] objArr);

        private function() {
        }
    }

    /* access modifiers changed from: private */
    public class JSExtractor {
        private String[] assign_operators = {"|=", "^=", "&=", ">>=", "<<=", "-=", "+=", "%=", "/=", "*=", "="};
        ArrayList<String> codeLines = new ArrayList<>();
        private String jsCode;
        private String[] operators = {LogUtils.VERTICAL, "^", "&", ">>", "<<", "-", Marker.ANY_NON_NULL_MARKER, "%", "/", "*"};

        public JSExtractor(String str) {
            this.jsCode = str;
        }

        private void interpretExpression(String str, HashMap<String, String> hashMap, int i) throws Exception {
            String[] split;
            String trim = str.trim();
            if (!TextUtils.isEmpty(trim)) {
                if (trim.charAt(0) == '(') {
                    Matcher matcher = PlayerUtils.exprParensPattern.matcher(trim);
                    int i2 = 0;
                    while (true) {
                        if (!matcher.find()) {
                            break;
                        } else if (matcher.group(0).indexOf(48) == 40) {
                            i2++;
                        } else {
                            i2--;
                            if (i2 == 0) {
                                interpretExpression(trim.substring(1, matcher.start()), hashMap, i);
                                trim = trim.substring(matcher.end()).trim();
                                if (TextUtils.isEmpty(trim)) {
                                    return;
                                }
                            }
                        }
                    }
                    if (i2 != 0) {
                        throw new Exception(String.format("Premature end of parens in %s", trim));
                    }
                }
                int i3 = 0;
                while (true) {
                    String[] strArr = this.assign_operators;
                    if (i3 < strArr.length) {
                        Matcher matcher2 = Pattern.compile(String.format(Locale.US, "(?x)(%s)(?:\\[([^\\]]+?)\\])?\\s*%s(.*)$", PlayerUtils.exprName, Pattern.quote(strArr[i3]))).matcher(trim);
                        if (!matcher2.find()) {
                            i3++;
                        } else {
                            interpretExpression(matcher2.group(3), hashMap, i - 1);
                            String group = matcher2.group(2);
                            if (!TextUtils.isEmpty(group)) {
                                interpretExpression(group, hashMap, i);
                                return;
                            } else {
                                hashMap.put(matcher2.group(1), "");
                                return;
                            }
                        }
                    } else {
                        try {
                            Integer.parseInt(trim);
                            return;
                        } catch (Exception unused) {
                            if (Pattern.compile(String.format(Locale.US, "(?!if|return|true|false)(%s)$", PlayerUtils.exprName)).matcher(trim).find()) {
                                return;
                            }
                            if (trim.charAt(0) != '\"' || trim.charAt(trim.length() - 1) != '\"') {
                                try {
                                    new JSONObject(trim).toString();
                                    return;
                                } catch (Exception unused2) {
                                    Matcher matcher3 = Pattern.compile(String.format(Locale.US, "(%s)\\[(.+)\\]$", PlayerUtils.exprName)).matcher(trim);
                                    if (matcher3.find()) {
                                        matcher3.group(1);
                                        interpretExpression(matcher3.group(2), hashMap, i - 1);
                                        return;
                                    }
                                    Matcher matcher4 = Pattern.compile(String.format(Locale.US, "(%s)(?:\\.([^(]+)|\\[([^]]+)\\])\\s*(?:\\(+([^()]*)\\))?$", PlayerUtils.exprName)).matcher(trim);
                                    if (matcher4.find()) {
                                        String group2 = matcher4.group(1);
                                        String group3 = matcher4.group(2);
                                        String group4 = matcher4.group(3);
                                        if (TextUtils.isEmpty(group3)) {
                                            group3 = group4;
                                        }
                                        group3.replace("\"", "");
                                        String group5 = matcher4.group(4);
                                        if (hashMap.get(group2) == null) {
                                            extractObject(group2);
                                        }
                                        if (group5 == null) {
                                            return;
                                        }
                                        if (trim.charAt(trim.length() - 1) != ')') {
                                            throw new Exception("last char not ')'");
                                        } else if (group5.length() != 0) {
                                            for (String str2 : group5.split(",")) {
                                                interpretExpression(str2, hashMap, i);
                                            }
                                            return;
                                        } else {
                                            return;
                                        }
                                    } else {
                                        Matcher matcher5 = Pattern.compile(String.format(Locale.US, "(%s)\\[(.+)\\]$", PlayerUtils.exprName)).matcher(trim);
                                        if (matcher5.find()) {
                                            hashMap.get(matcher5.group(1));
                                            interpretExpression(matcher5.group(2), hashMap, i - 1);
                                            return;
                                        }
                                        int i4 = 0;
                                        while (true) {
                                            String[] strArr2 = this.operators;
                                            if (i4 < strArr2.length) {
                                                String str3 = strArr2[i4];
                                                Matcher matcher6 = Pattern.compile(String.format(Locale.US, "(.+?)%s(.+)", Pattern.quote(str3))).matcher(trim);
                                                if (matcher6.find()) {
                                                    boolean[] zArr = new boolean[1];
                                                    int i5 = i - 1;
                                                    interpretStatement(matcher6.group(1), hashMap, zArr, i5);
                                                    if (!zArr[0]) {
                                                        interpretStatement(matcher6.group(2), hashMap, zArr, i5);
                                                        if (zArr[0]) {
                                                            throw new Exception(String.format("Premature right-side return of %s in %s", str3, trim));
                                                        }
                                                    } else {
                                                        throw new Exception(String.format("Premature left-side return of %s in %s", str3, trim));
                                                    }
                                                }
                                                i4++;
                                            } else {
                                                Matcher matcher7 = Pattern.compile(String.format(Locale.US, "^(%s)\\(([a-zA-Z0-9_$,]*)\\)$", PlayerUtils.exprName)).matcher(trim);
                                                if (matcher7.find()) {
                                                    extractFunction(matcher7.group(1));
                                                }
                                                throw new Exception(String.format("Unsupported JS expression %s", trim));
                                            }
                                        }
                                    }
                                }
                            } else {
                                return;
                            }
                        }
                    }
                }
            }
        }

        private void interpretStatement(String str, HashMap<String, String> hashMap, boolean[] zArr, int i) throws Exception {
            if (i >= 0) {
                zArr[0] = false;
                String trim = str.trim();
                Matcher matcher = PlayerUtils.stmtVarPattern.matcher(trim);
                if (matcher.find()) {
                    trim = trim.substring(matcher.group(0).length());
                } else {
                    Matcher matcher2 = PlayerUtils.stmtReturnPattern.matcher(trim);
                    if (matcher2.find()) {
                        trim = trim.substring(matcher2.group(0).length());
                        zArr[0] = true;
                    }
                }
                interpretExpression(trim, hashMap, i);
                return;
            }
            throw new Exception("recursion limit reached");
        }

        private HashMap<String, Object> extractObject(String str) throws Exception {
            HashMap<String, Object> hashMap = new HashMap<>();
            Matcher matcher = Pattern.compile(String.format(Locale.US, "(?:var\\s+)?%s\\s*=\\s*\\{\\s*((%s\\s*:\\s*function\\(.*?\\)\\s*\\{.*?\\}(?:,\\s*)?)*)\\}\\s*;", Pattern.quote(str), "(?:[a-zA-Z$0-9]+|\"[a-zA-Z$0-9]+\"|'[a-zA-Z$0-9]+')")).matcher(this.jsCode);
            String str2 = null;
            while (true) {
                if (!matcher.find()) {
                    break;
                }
                String group = matcher.group();
                String group2 = matcher.group(2);
                if (TextUtils.isEmpty(group2)) {
                    str2 = group2;
                } else {
                    if (!this.codeLines.contains(group)) {
                        this.codeLines.add(matcher.group());
                    }
                    str2 = group2;
                }
            }
            Matcher matcher2 = Pattern.compile(String.format("(%s)\\s*:\\s*function\\(([a-z,]+)\\)\\{([^}]+)\\}", "(?:[a-zA-Z$0-9]+|\"[a-zA-Z$0-9]+\"|'[a-zA-Z$0-9]+')")).matcher(str2);
            while (matcher2.find()) {
                buildFunction(matcher2.group(2).split(","), matcher2.group(3));
            }
            return hashMap;
        }

        private void buildFunction(String[] strArr, String str) throws Exception {
            HashMap<String, String> hashMap = new HashMap<>();
            for (String str2 : strArr) {
                hashMap.put(str2, "");
            }
            String[] split = str.split(";");
            boolean[] zArr = new boolean[1];
            for (String str3 : split) {
                interpretStatement(str3, hashMap, zArr, 100);
                if (zArr[0]) {
                    return;
                }
            }
        }

        /* access modifiers changed from: private */
        /* access modifiers changed from: public */
        private String extractFunction(String str) {
            try {
                String quote = Pattern.quote(str);
                Matcher matcher = Pattern.compile(String.format(Locale.US, "(?x)(?:function\\s+%s|[{;,]\\s*%s\\s*=\\s*function|var\\s+%s\\s*=\\s*function)\\s*\\(([^)]*)\\)\\s*\\{([^}]+)\\}", quote, quote, quote)).matcher(this.jsCode);
                if (matcher.find()) {
                    String group = matcher.group();
                    if (!this.codeLines.contains(group)) {
                        ArrayList<String> arrayList = this.codeLines;
                        arrayList.add(group + ";");
                    }
                    buildFunction(matcher.group(1).split(","), matcher.group(2));
                }
            } catch (Exception e) {
                this.codeLines.clear();
                FileLog.e(e);
            }
            return TextUtils.join("", this.codeLines);
        }
    }

    public class JavaScriptInterface {
        private final CallJavaResultInterface callJavaResultInterface;

        public JavaScriptInterface(CallJavaResultInterface callJavaResultInterface2) {
            this.callJavaResultInterface = callJavaResultInterface2;
        }

        @JavascriptInterface
        public void returnResultToJava(String str) {
            this.callJavaResultInterface.jsCallFinished(str);
        }
    }

    /* access modifiers changed from: protected */
    public String downloadUrlContent(AsyncTask asyncTask, String str) {
        return downloadUrlContent(asyncTask, str, null, true);
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Code restructure failed: missing block: B:89:0x016c, code lost:
        if (r3 == -1) goto L_0x0177;
     */
    /* JADX WARNING: Removed duplicated region for block: B:105:0x018a A[SYNTHETIC, Splitter:B:105:0x018a] */
    /* JADX WARNING: Removed duplicated region for block: B:109:0x0194  */
    /* JADX WARNING: Removed duplicated region for block: B:111:0x0199  */
    /* JADX WARNING: Removed duplicated region for block: B:112:0x019e A[ORIG_RETURN, RETURN, SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:60:0x0129 A[SYNTHETIC, Splitter:B:60:0x0129] */
    public String downloadUrlContent(AsyncTask asyncTask, String str, HashMap<String, String> hashMap, boolean z) {
        URLConnection uRLConnection;
        InputStream inputStream;
        boolean z2;
        boolean z3;
        StringBuilder sb;
        Throwable th;
        Exception e;
        Throwable th2;
        boolean z4;
        InputStream inputStream2;
        boolean z5 = true;
        try {
            URL url = new URL(str);
            uRLConnection = url.openConnection();
            try {
                uRLConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)");
                if (z) {
                    uRLConnection.addRequestProperty("Accept-Encoding", "gzip, deflate");
                }
                uRLConnection.addRequestProperty("Accept-Language", "en-us,en;q=0.5");
                uRLConnection.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                uRLConnection.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
                if (hashMap != null) {
                    for (Map.Entry<String, String> entry : hashMap.entrySet()) {
                        uRLConnection.addRequestProperty(entry.getKey(), entry.getValue());
                    }
                }
                uRLConnection.setConnectTimeout(5000);
                uRLConnection.setReadTimeout(5000);
                if (uRLConnection instanceof HttpURLConnection) {
                    HttpURLConnection httpURLConnection = (HttpURLConnection) uRLConnection;
                    httpURLConnection.setInstanceFollowRedirects(true);
                    int responseCode = httpURLConnection.getResponseCode();
                    if (responseCode == 302 || responseCode == 301 || responseCode == 303) {
                        String headerField = httpURLConnection.getHeaderField("Location");
                        String headerField2 = httpURLConnection.getHeaderField("Set-Cookie");
                        url = new URL(headerField);
                        uRLConnection = url.openConnection();
                        uRLConnection.setRequestProperty("Cookie", headerField2);
                        uRLConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)");
                        if (z) {
                            uRLConnection.addRequestProperty("Accept-Encoding", "gzip, deflate");
                        }
                        uRLConnection.addRequestProperty("Accept-Language", "en-us,en;q=0.5");
                        uRLConnection.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                        uRLConnection.addRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
                        if (hashMap != null) {
                            for (Map.Entry<String, String> entry2 : hashMap.entrySet()) {
                                uRLConnection.addRequestProperty(entry2.getKey(), entry2.getValue());
                            }
                        }
                    }
                }
                uRLConnection.connect();
                if (z) {
                    try {
                        inputStream2 = new GZIPInputStream(uRLConnection.getInputStream());
                    } catch (Exception unused) {
                        uRLConnection = url.openConnection();
                        uRLConnection.connect();
                        inputStream2 = uRLConnection.getInputStream();
                    }
                } else {
                    inputStream2 = uRLConnection.getInputStream();
                }
                inputStream = inputStream2;
                z2 = true;
            } catch (Throwable th3) {
                th2 = th3;
                if ((th2 instanceof SocketTimeoutException) ? !(th2 instanceof UnknownHostException) && (!(th2 instanceof SocketException) ? !(th2 instanceof FileNotFoundException) : th2.getMessage() == null || !th2.getMessage().contains("ECONNRESET")) : !ApplicationLoader.isNetworkOnline()) {
                    z4 = true;
                } else {
                    z4 = false;
                }
                FileLog.e(th2);
                z2 = z4;
                inputStream = null;
                if (z2) {
                }
                if (!z3) {
                }
            }
        } catch (Throwable th4) {
            th2 = th4;
            uRLConnection = null;
            if (th2 instanceof SocketTimeoutException) {
                z4 = true;
                FileLog.e(th2);
                z2 = z4;
                inputStream = null;
                if (z2) {
                }
                if (!z3) {
                }
            } else {
                z4 = true;
                FileLog.e(th2);
                z2 = z4;
                inputStream = null;
                if (z2) {
                }
                if (!z3) {
                }
            }
            z4 = false;
            FileLog.e(th2);
            z2 = z4;
            inputStream = null;
            if (z2) {
            }
            if (!z3) {
            }
        }
        if (z2) {
            try {
                if ((uRLConnection instanceof HttpURLConnection) && ((HttpURLConnection) uRLConnection).getResponseCode() != 200) {
                }
            } catch (Exception e2) {
                FileLog.e(e2);
            }
            if (inputStream != null) {
                try {
                    byte[] bArr = new byte[32768];
                    sb = null;
                    while (true) {
                        try {
                            if (asyncTask.isCancelled()) {
                                break;
                            }
                            try {
                                int read = inputStream.read(bArr);
                                if (read > 0) {
                                    if (sb == null) {
                                        sb = new StringBuilder();
                                    }
                                    try {
                                        sb.append(new String(bArr, 0, read, StandardCharsets.UTF_8));
                                    } catch (Exception e3) {
                                        e = e3;
                                    }
                                }
                            } catch (Exception e4) {
                                e = e4;
                                try {
                                    FileLog.e(e);
                                    z5 = false;
                                    z3 = z5;
                                } catch (Throwable th5) {
                                    th = th5;
                                }
                                if (inputStream != null) {
                                }
                                if (!z3) {
                                }
                            }
                        } catch (Throwable th6) {
                            th = th6;
                            FileLog.e(th);
                            z3 = false;
                            if (inputStream != null) {
                            }
                            if (!z3) {
                            }
                        }
                    }
                    z5 = false;
                    z3 = z5;
                } catch (Throwable th7) {
                    th = th7;
                    sb = null;
                    FileLog.e(th);
                    z3 = false;
                    if (inputStream != null) {
                    }
                    if (!z3) {
                    }
                }
            } else {
                sb = null;
                z3 = false;
            }
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (Throwable th8) {
                    FileLog.e(th8);
                }
            }
        } else {
            sb = null;
            z3 = false;
        }
        if (!z3) {
            return sb.toString();
        }
        return null;
    }

    /* access modifiers changed from: private */
    public class YoutubeVideoTask extends AsyncTask<Void, Void, String[]> {
        private boolean canRetry = true;
        private CountDownLatch countDownLatch = new CountDownLatch(1);
        private String[] result = new String[2];
        private String sig;
        private String videoId;

        public YoutubeVideoTask(String str) {
            this.videoId = str;
        }

        /* JADX DEBUG: Multi-variable search result rejected for r4v12, resolved type: java.lang.String */
        /* JADX DEBUG: Multi-variable search result rejected for r5v18, resolved type: java.lang.String[] */
        /* JADX DEBUG: Multi-variable search result rejected for r4v15, resolved type: java.lang.String */
        /* JADX DEBUG: Multi-variable search result rejected for r4v16, resolved type: java.lang.String */
        /* JADX WARN: Multi-variable type inference failed */
        /* access modifiers changed from: protected */
        /* JADX WARNING: Removed duplicated region for block: B:124:0x02e3  */
        /* JADX WARNING: Removed duplicated region for block: B:162:0x03e2  */
        public String[] doInBackground(Void... voidArr) {
            boolean z;
            String[] strArr;
            String str;
            String str2;
            String str3;
            String str4;
            String str5;
            String str6;
            boolean z2;
            boolean z3;
            String str7;
            String str8;
            Exception e;
            String downloadUrlContent = PlayerUtils.this.downloadUrlContent(this, "https://www.youtube.com/embed/" + this.videoId);
            String[] strArr2 = null;
            if (isCancelled()) {
                return null;
            }
            String str9 = "video_id=" + this.videoId + "&ps=default&gl=US&hl=en";
            try {
                StringBuilder sb = new StringBuilder();
                sb.append(str9);
                sb.append("&eurl=");
                sb.append(URLEncoder.encode("https://youtube.googleapis.com/v/" + this.videoId, "UTF-8"));
                str9 = sb.toString();
            } catch (Exception e2) {
                FileLog.e(e2);
            }
            if (downloadUrlContent != null) {
                Matcher matcher = PlayerUtils.stsPattern.matcher(downloadUrlContent);
                if (matcher.find()) {
                    str9 = str9 + "&sts=" + downloadUrlContent.substring(matcher.start() + 6, matcher.end());
                } else {
                    str9 = str9 + "&sts=";
                }
            }
            char c = 1;
            this.result[1] = DownloadAction.TYPE_DASH;
            int i = 5;
            String[] strArr3 = {"", "&el=leanback", "&el=embedded", "&el=detailpage", "&el=vevo"};
            char c2 = 0;
            String str10 = null;
            boolean z4 = false;
            int i2 = 0;
            while (true) {
                int i3 = 2;
                if (i2 >= i) {
                    break;
                }
                String downloadUrlContent2 = PlayerUtils.this.downloadUrlContent(this, "https://www.youtube.com/get_video_info?" + str9 + strArr3[i2]);
                if (isCancelled()) {
                    return strArr2;
                }
                if (downloadUrlContent2 != null) {
                    String[] split = downloadUrlContent2.split("&");
                    Object obj = strArr2;
                    String str11 = str10;
                    int i4 = 0;
                    z3 = false;
                    z2 = false;
                    boolean z5 = z4;
                    while (i4 < split.length) {
                        if (split[i4].startsWith("dashmpd")) {
                            String[] split2 = split[i4].split("=");
                            if (split2.length == i3) {
                                try {
                                    this.result[c2] = URLDecoder.decode(split2[c], "UTF-8");
                                } catch (Exception e3) {
                                    FileLog.e(e3);
                                }
                            }
                            str8 = str9;
                            z2 = true;
                        } else if (split[i4].startsWith("url_encoded_fmt_stream_map")) {
                            String[] split3 = split[i4].split("=");
                            if (split3.length == i3) {
                                try {
                                    String[] split4 = URLDecoder.decode(split3[c], "UTF-8").split("[&,]");
                                    String str12 = null;
                                    int i5 = 0;
                                    boolean z6 = false;
                                    while (true) {
                                        if (i5 >= split4.length) {
                                            break;
                                        }
                                        String[] split5 = split4[i5].split("=");
                                        str8 = str9;
                                        try {
                                            if (split5[0].startsWith("type")) {
                                                if (URLDecoder.decode(split5[1], "UTF-8").contains(MimeTypes.VIDEO_MP4)) {
                                                    z6 = true;
                                                }
                                            } else if (split5[0].startsWith(ImagesContract.URL)) {
                                                str12 = URLDecoder.decode(split5[1], "UTF-8");
                                            } else if (split5[0].startsWith("itag")) {
                                                str12 = null;
                                                z6 = false;
                                            }
                                            if (z6 && str12 != null) {
                                                str11 = str12;
                                                break;
                                            }
                                            i5++;
                                            split4 = split4;
                                            str9 = str8;
                                        } catch (Exception e4) {
                                            e = e4;
                                            FileLog.e(e);
                                            i4++;
                                            str9 = str8;
                                            c = 1;
                                            c2 = 0;
                                            i3 = 2;
                                        }
                                    }
                                } catch (Exception e5) {
                                    e = e5;
                                    str8 = str9;
                                    FileLog.e(e);
                                    i4++;
                                    str9 = str8;
                                    c = 1;
                                    c2 = 0;
                                    i3 = 2;
                                }
                            }
                            str8 = str9;
                        } else {
                            str8 = str9;
                            if (split[i4].startsWith("use_cipher_signature")) {
                                String[] split6 = split[i4].split("=");
                                if (split6.length == 2 && split6[1].toLowerCase().equals("true")) {
                                    z5 = true;
                                }
                            } else if (split[i4].startsWith("hlsvp")) {
                                String[] split7 = split[i4].split("=");
                                if (split7.length == 2) {
                                    try {
                                        obj = URLDecoder.decode(split7[1], "UTF-8");
                                    } catch (Exception e6) {
                                        FileLog.e(e6);
                                    }
                                }
                            } else if (split[i4].startsWith("livestream")) {
                                String[] split8 = split[i4].split("=");
                                if (split8.length == 2 && split8[1].toLowerCase().equals("1")) {
                                    z3 = true;
                                }
                            }
                        }
                        i4++;
                        str9 = str8;
                        c = 1;
                        c2 = 0;
                        i3 = 2;
                    }
                    str6 = str9;
                    z4 = z5;
                    str10 = str11;
                    str7 = obj;
                } else {
                    str6 = str9;
                    str7 = 0;
                    z3 = false;
                    z2 = false;
                }
                if (z3) {
                    if (str7 == 0 || z4 || str7.contains("/s/")) {
                        return null;
                    }
                    String[] strArr4 = this.result;
                    strArr4[0] = str7;
                    strArr4[1] = DownloadAction.TYPE_HLS;
                }
                if (z2) {
                    break;
                }
                i2++;
                str9 = str6;
                strArr2 = null;
                i = 5;
                c = 1;
                c2 = 0;
            }
            String[] strArr5 = this.result;
            if (strArr5[0] == null && str10 != null) {
                strArr5[0] = str10;
                strArr5[1] = "other";
            }
            String[] strArr6 = this.result;
            if (strArr6[0] == null || ((!z4 && !strArr6[0].contains("/s/")) || downloadUrlContent == null)) {
                strArr = null;
                z = z4;
            } else {
                int indexOf = this.result[0].indexOf("/s/");
                int indexOf2 = this.result[0].indexOf(47, indexOf + 10);
                if (indexOf != -1) {
                    if (indexOf2 == -1) {
                        indexOf2 = this.result[0].length();
                    }
                    this.sig = this.result[0].substring(indexOf, indexOf2);
                    Matcher matcher2 = PlayerUtils.jsPattern.matcher(downloadUrlContent);
                    if (matcher2.find()) {
                        try {
                            Object nextValue = new JSONTokener(matcher2.group(1)).nextValue();
                            str = nextValue instanceof String ? (String) nextValue : null;
                        } catch (Exception e7) {
                            FileLog.e(e7);
                        }
                        if (str != null) {
                            Matcher matcher3 = PlayerUtils.playerIdPattern.matcher(str);
                            if (matcher3.find()) {
                                str2 = matcher3.group(1) + matcher3.group(2);
                            } else {
                                str2 = null;
                            }
                            SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("youtubecode", 0);
                            if (str2 != null) {
                                str4 = sharedPreferences.getString(str2, null);
                                str3 = sharedPreferences.getString(str2 + "n", null);
                            } else {
                                str4 = null;
                                str3 = null;
                            }
                            if (str4 == null) {
                                if (str.startsWith("//")) {
                                    str = "https:" + str;
                                } else if (str.startsWith("/")) {
                                    str = "https://www.youtube.com" + str;
                                }
                                String downloadUrlContent3 = PlayerUtils.this.downloadUrlContent(this, str);
                                if (isCancelled()) {
                                    return null;
                                }
                                strArr = null;
                                if (downloadUrlContent3 != null) {
                                    Matcher matcher4 = PlayerUtils.sigPattern.matcher(downloadUrlContent3);
                                    if (matcher4.find()) {
                                        str3 = matcher4.group(1);
                                    } else {
                                        Matcher matcher5 = PlayerUtils.sigPattern2.matcher(downloadUrlContent3);
                                        if (matcher5.find()) {
                                            str3 = matcher5.group(1);
                                        }
                                    }
                                    if (str3 != null) {
                                        try {
                                            str4 = new JSExtractor(downloadUrlContent3).extractFunction(str3);
                                            if (!TextUtils.isEmpty(str4) && str2 != null) {
                                                sharedPreferences.edit().putString(str2, str4).putString(str2 + "n", str3).commit();
                                            }
                                        } catch (Exception e8) {
                                            FileLog.e(e8);
                                        }
                                    }
                                    if (!TextUtils.isEmpty(str4)) {
                                        if (Build.VERSION.SDK_INT >= 21) {
                                            str5 = str4 + str3 + "('" + this.sig.substring(3) + "');";
                                        } else {
                                            str5 = str4 + "window." + PlayerUtils.this.interfaceName + ".returnResultToJava(" + str3 + "('" + this.sig.substring(3) + "'));";
                                        }
                                        try {
                                            AndroidUtilities.runOnUIThread(new Runnable(str5) {
                                                /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$YoutubeVideoTask$yxyzkQhJ5FGKYtaQ6fw4FtfDZNc */
                                                private final /* synthetic */ String f$1;

                                                {
                                                    this.f$1 = r2;
                                                }

                                                public final void run() {
                                                    PlayerUtils.YoutubeVideoTask.this.lambda$doInBackground$1$PlayerUtils$YoutubeVideoTask(this.f$1);
                                                }
                                            });
                                            this.countDownLatch.await();
                                            z = false;
                                        } catch (Exception e9) {
                                            FileLog.e(e9);
                                        }
                                    }
                                    z = true;
                                }
                            } else {
                                strArr = null;
                            }
                            if (!TextUtils.isEmpty(str4)) {
                            }
                            z = true;
                        }
                    }
                    str = null;
                    if (str != null) {
                    }
                }
                strArr = null;
                z = true;
            }
            return (isCancelled() || z) ? strArr : this.result;
        }

        public /* synthetic */ void lambda$doInBackground$1$PlayerUtils$YoutubeVideoTask(String str) {
            if (Build.VERSION.SDK_INT >= 21) {
                PlayerUtils.this.webView.evaluateJavascript(str, new ValueCallback() {
                    /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$YoutubeVideoTask$ItpttbDmuBVYjKmdJ7z2C8Kn3Mk */

                    @Override // android.webkit.ValueCallback
                    public final void onReceiveValue(Object obj) {
                        PlayerUtils.YoutubeVideoTask.this.lambda$null$0$PlayerUtils$YoutubeVideoTask((String) obj);
                    }
                });
                return;
            }
            try {
                String encodeToString = Base64.encodeToString(("<script>" + str + "</script>").getBytes(StandardCharsets.UTF_8), 0);
                WebView webView = PlayerUtils.this.webView;
                webView.loadUrl("data:text/html;charset=utf-8;base64," + encodeToString);
            } catch (Exception e) {
                FileLog.e(e);
            }
        }

        public /* synthetic */ void lambda$null$0$PlayerUtils$YoutubeVideoTask(String str) {
            String[] strArr = this.result;
            String str2 = strArr[0];
            String str3 = this.sig;
            strArr[0] = str2.replace(str3, "/signature/" + str.substring(1, str.length() - 1));
            this.countDownLatch.countDown();
        }

        /* access modifiers changed from: private */
        /* access modifiers changed from: public */
        private void onInterfaceResult(String str) {
            String[] strArr = this.result;
            String str2 = strArr[0];
            String str3 = this.sig;
            strArr[0] = str2.replace(str3, "/signature/" + str);
            this.countDownLatch.countDown();
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(String[] strArr) {
            if (strArr[0] != null) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("start play youtube video " + strArr[1] + " " + strArr[0]);
                }
                PlayerUtils.this.initied = true;
                PlayerUtils.this.playVideoUrl = strArr[0];
                PlayerUtils.this.playVideoType = strArr[1];
                if (PlayerUtils.this.playVideoType.equals(DownloadAction.TYPE_HLS)) {
                    PlayerUtils.this.isStream = true;
                }
                if (PlayerUtils.this.isAutoplay) {
                    PlayerUtils.this.preparePlayer();
                }
                PlayerUtils.this.showProgress(false, true);
                PlayerUtils.this.controlsView.show(true, true);
            } else if (!isCancelled()) {
                PlayerUtils.this.onInitFailed();
            }
        }
    }

    private class VimeoVideoTask extends AsyncTask<Void, Void, String> {
        private boolean canRetry = true;
        private String[] results = new String[2];
        private String videoId;

        public VimeoVideoTask(String str) {
            this.videoId = str;
        }

        /* access modifiers changed from: protected */
        public String doInBackground(Void... voidArr) {
            String downloadUrlContent = PlayerUtils.this.downloadUrlContent(this, String.format(Locale.US, "https://player.vimeo.com/video/%s/config", this.videoId));
            if (isCancelled()) {
                return null;
            }
            try {
                JSONObject jSONObject = new JSONObject(downloadUrlContent).getJSONObject("request").getJSONObject("files");
                if (jSONObject.has(DownloadAction.TYPE_HLS)) {
                    JSONObject jSONObject2 = jSONObject.getJSONObject(DownloadAction.TYPE_HLS);
                    try {
                        this.results[0] = jSONObject2.getString(ImagesContract.URL);
                    } catch (Exception unused) {
                        this.results[0] = jSONObject2.getJSONObject("cdns").getJSONObject(jSONObject2.getString("default_cdn")).getString(ImagesContract.URL);
                    }
                    this.results[1] = DownloadAction.TYPE_HLS;
                } else if (jSONObject.has(DownloadAction.TYPE_PROGRESSIVE)) {
                    this.results[1] = "other";
                    this.results[0] = jSONObject.getJSONArray(DownloadAction.TYPE_PROGRESSIVE).getJSONObject(0).getString(ImagesContract.URL);
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            if (isCancelled()) {
                return null;
            }
            return this.results[0];
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(String str) {
            if (str != null) {
                PlayerUtils.this.initied = true;
                PlayerUtils.this.playVideoUrl = str;
                PlayerUtils.this.playVideoType = this.results[1];
                if (PlayerUtils.this.isAutoplay) {
                    PlayerUtils.this.preparePlayer();
                }
                PlayerUtils.this.showProgress(false, true);
                PlayerUtils.this.controlsView.show(true, true);
            } else if (!isCancelled()) {
                PlayerUtils.this.onInitFailed();
            }
        }
    }

    private class AparatVideoTask extends AsyncTask<Void, Void, String> {
        private boolean canRetry = true;
        private String[] results = new String[2];
        private String videoId;

        public AparatVideoTask(String str) {
            this.videoId = str;
        }

        /* access modifiers changed from: protected */
        public String doInBackground(Void... voidArr) {
            String downloadUrlContent = PlayerUtils.this.downloadUrlContent(this, String.format(Locale.US, "http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/%s", this.videoId));
            if (isCancelled()) {
                return null;
            }
            try {
                Matcher matcher = PlayerUtils.aparatFileListPattern.matcher(downloadUrlContent);
                if (matcher.find()) {
                    JSONArray jSONArray = new JSONArray(matcher.group(1));
                    for (int i = 0; i < jSONArray.length(); i++) {
                        JSONArray jSONArray2 = jSONArray.getJSONArray(i);
                        if (jSONArray2.length() != 0) {
                            JSONObject jSONObject = jSONArray2.getJSONObject(0);
                            if (jSONObject.has("file")) {
                                this.results[0] = jSONObject.getString("file");
                                this.results[1] = "other";
                            }
                        }
                    }
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            if (isCancelled()) {
                return null;
            }
            return this.results[0];
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(String str) {
            if (str != null) {
                PlayerUtils.this.initied = true;
                PlayerUtils.this.playVideoUrl = str;
                PlayerUtils.this.playVideoType = this.results[1];
                if (PlayerUtils.this.isAutoplay) {
                    PlayerUtils.this.preparePlayer();
                }
                PlayerUtils.this.showProgress(false, true);
                PlayerUtils.this.controlsView.show(true, true);
            } else if (!isCancelled()) {
                PlayerUtils.this.onInitFailed();
            }
        }
    }

    private class TwitchClipVideoTask extends AsyncTask<Void, Void, String> {
        private boolean canRetry = true;
        private String currentUrl;
        private String[] results = new String[2];
        private String videoId;

        public TwitchClipVideoTask(String str, String str2) {
            this.videoId = str2;
            this.currentUrl = str;
        }

        /* access modifiers changed from: protected */
        public String doInBackground(Void... voidArr) {
            String downloadUrlContent = PlayerUtils.this.downloadUrlContent(this, this.currentUrl, null, false);
            if (isCancelled()) {
                return null;
            }
            try {
                Matcher matcher = PlayerUtils.twitchClipFilePattern.matcher(downloadUrlContent);
                if (matcher.find()) {
                    this.results[0] = new JSONObject(matcher.group(1)).getJSONArray("quality_options").getJSONObject(0).getString("source");
                    this.results[1] = "other";
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            if (isCancelled()) {
                return null;
            }
            return this.results[0];
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(String str) {
            if (str != null) {
                PlayerUtils.this.initied = true;
                PlayerUtils.this.playVideoUrl = str;
                PlayerUtils.this.playVideoType = this.results[1];
                if (PlayerUtils.this.isAutoplay) {
                    PlayerUtils.this.preparePlayer();
                }
                PlayerUtils.this.showProgress(false, true);
                PlayerUtils.this.controlsView.show(true, true);
            } else if (!isCancelled()) {
                PlayerUtils.this.onInitFailed();
            }
        }
    }

    private class TwitchStreamVideoTask extends AsyncTask<Void, Void, String> {
        private boolean canRetry = true;
        private String currentUrl;
        private String[] results = new String[2];
        private String videoId;

        public TwitchStreamVideoTask(String str, String str2) {
            this.videoId = str2;
            this.currentUrl = str;
        }

        /* access modifiers changed from: protected */
        public String doInBackground(Void... voidArr) {
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put("Client-ID", "jzkbprff40iqj646a697cyrvl0zt2m6");
            int indexOf = this.videoId.indexOf(38);
            if (indexOf > 0) {
                this.videoId = this.videoId.substring(0, indexOf);
            }
            String downloadUrlContent = PlayerUtils.this.downloadUrlContent(this, String.format(Locale.US, "https://api.twitch.tv/kraken/streams/%s?stream_type=all", this.videoId), hashMap, false);
            if (isCancelled()) {
                return null;
            }
            try {
                new JSONObject(downloadUrlContent).getJSONObject("stream");
                JSONObject jSONObject = new JSONObject(PlayerUtils.this.downloadUrlContent(this, String.format(Locale.US, "https://api.twitch.tv/api/channels/%s/access_token", this.videoId), hashMap, false));
                String encode = URLEncoder.encode(jSONObject.getString("sig"), "UTF-8");
                String encode2 = URLEncoder.encode(jSONObject.getString("token"), "UTF-8");
                URLEncoder.encode("https://youtube.googleapis.com/v/" + this.videoId, "UTF-8");
                this.results[0] = String.format(Locale.US, "https://usher.ttvnw.net/api/channel/hls/%s.m3u8?%s", this.videoId, "allow_source=true&allow_audio_only=true&allow_spectre=true&player=twitchweb&segment_preference=4&p=" + ((int) (Math.random() * 1.0E7d)) + "&sig=" + encode + "&token=" + encode2);
                this.results[1] = DownloadAction.TYPE_HLS;
            } catch (Exception e) {
                FileLog.e(e);
            }
            if (isCancelled()) {
                return null;
            }
            return this.results[0];
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(String str) {
            if (str != null) {
                PlayerUtils.this.initied = true;
                PlayerUtils.this.playVideoUrl = str;
                PlayerUtils.this.playVideoType = this.results[1];
                if (PlayerUtils.this.isAutoplay) {
                    PlayerUtils.this.preparePlayer();
                }
                PlayerUtils.this.showProgress(false, true);
                PlayerUtils.this.controlsView.show(true, true);
            } else if (!isCancelled()) {
                PlayerUtils.this.onInitFailed();
            }
        }
    }

    private class CoubVideoTask extends AsyncTask<Void, Void, String> {
        private boolean canRetry = true;
        private String[] results = new String[4];
        private String videoId;

        public CoubVideoTask(String str) {
            this.videoId = str;
        }

        private String decodeUrl(String str) {
            StringBuilder sb = new StringBuilder(str);
            for (int i = 0; i < sb.length(); i++) {
                char charAt = sb.charAt(i);
                char lowerCase = Character.toLowerCase(charAt);
                if (charAt == lowerCase) {
                    lowerCase = Character.toUpperCase(charAt);
                }
                sb.setCharAt(i, lowerCase);
            }
            try {
                return new String(Base64.decode(sb.toString(), 0), StandardCharsets.UTF_8);
            } catch (Exception unused) {
                return null;
            }
        }

        /* access modifiers changed from: protected */
        public String doInBackground(Void... voidArr) {
            String downloadUrlContent = PlayerUtils.this.downloadUrlContent(this, String.format(Locale.US, "https://coub.com/api/v2/coubs/%s.json", this.videoId));
            if (isCancelled()) {
                return null;
            }
            try {
                JSONObject jSONObject = new JSONObject(downloadUrlContent).getJSONObject("file_versions").getJSONObject("mobile");
                String decodeUrl = decodeUrl(jSONObject.getString("gifv"));
                String string = jSONObject.getJSONArray(MimeTypes.BASE_TYPE_AUDIO).getString(0);
                if (!(decodeUrl == null || string == null)) {
                    this.results[0] = decodeUrl;
                    this.results[1] = "other";
                    this.results[2] = string;
                    this.results[3] = "other";
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            if (isCancelled()) {
                return null;
            }
            return this.results[0];
        }

        /* access modifiers changed from: protected */
        public void onPostExecute(String str) {
            if (str != null) {
                PlayerUtils.this.initied = true;
                PlayerUtils.this.playVideoUrl = str;
                PlayerUtils.this.playVideoType = this.results[1];
                PlayerUtils.this.playAudioUrl = this.results[2];
                PlayerUtils.this.playAudioType = this.results[3];
                if (PlayerUtils.this.isAutoplay) {
                    PlayerUtils.this.preparePlayer();
                }
                PlayerUtils.this.showProgress(false, true);
                PlayerUtils.this.controlsView.show(true, true);
            } else if (!isCancelled()) {
                PlayerUtils.this.onInitFailed();
            }
        }
    }

    /* access modifiers changed from: private */
    public class ControlsView extends FrameLayout {
        private int bufferedPosition;
        private AnimatorSet currentAnimation;
        private int currentProgressX;
        private int duration;
        private StaticLayout durationLayout;
        private int durationWidth;
        private Runnable hideRunnable = new Runnable() {
            /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$ControlsView$5lUCXj3UoM31zqGUn5euifgSGHs */

            public final void run() {
                PlayerUtils.ControlsView.this.lambda$new$0$PlayerUtils$ControlsView();
            }
        };
        private ImageReceiver imageReceiver;
        private boolean isVisible = true;
        private int lastProgressX;
        private int progress;
        private Paint progressBufferedPaint;
        private Paint progressInnerPaint;
        private StaticLayout progressLayout;
        private Paint progressPaint;
        private boolean progressPressed;
        private TextPaint textPaint;

        public /* synthetic */ void lambda$new$0$PlayerUtils$ControlsView() {
            show(false, true);
        }

        public ControlsView(Context context) {
            super(context);
            setWillNotDraw(false);
            TextPaint textPaint2 = new TextPaint(1);
            this.textPaint = textPaint2;
            textPaint2.setColor(-1);
            this.textPaint.setTextSize((float) AndroidUtilities.dp(12.0f));
            Paint paint = new Paint(1);
            this.progressPaint = paint;
            paint.setColor(-15095832);
            Paint paint2 = new Paint();
            this.progressInnerPaint = paint2;
            paint2.setColor(-6975081);
            Paint paint3 = new Paint(1);
            this.progressBufferedPaint = paint3;
            paint3.setColor(-1);
            this.imageReceiver = new ImageReceiver(this);
        }

        public void setDuration(int i) {
            if (this.duration != i && i >= 0 && !PlayerUtils.this.isStream) {
                this.duration = i;
                StaticLayout staticLayout = new StaticLayout(String.format(Locale.US, "%d:%02d", Integer.valueOf(this.duration / 60), Integer.valueOf(this.duration % 60)), this.textPaint, AndroidUtilities.dp(1000.0f), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                this.durationLayout = staticLayout;
                if (staticLayout.getLineCount() > 0) {
                    this.durationWidth = (int) Math.ceil((double) this.durationLayout.getLineWidth(0));
                }
                invalidate();
            }
        }

        public void setBufferedProgress(int i) {
            this.bufferedPosition = i;
            invalidate();
        }

        public void setProgress(int i) {
            if (!this.progressPressed && i >= 0 && !PlayerUtils.this.isStream) {
                this.progress = i;
                this.progressLayout = new StaticLayout(String.format(Locale.US, "%d:%02d", Integer.valueOf(this.progress / 60), Integer.valueOf(this.progress % 60)), this.textPaint, AndroidUtilities.dp(1000.0f), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                invalidate();
            }
        }

        public void show(boolean z, boolean z2) {
            if (this.isVisible != z) {
                this.isVisible = z;
                AnimatorSet animatorSet = this.currentAnimation;
                if (animatorSet != null) {
                    animatorSet.cancel();
                }
                if (this.isVisible) {
                    if (z2) {
                        AnimatorSet animatorSet2 = new AnimatorSet();
                        this.currentAnimation = animatorSet2;
                        animatorSet2.playTogether(ObjectAnimator.ofFloat(this, "alpha", 1.0f));
                        this.currentAnimation.setDuration(150L);
                        this.currentAnimation.addListener(new AnimatorListenerAdapter() {
                            /* class im.guobwnxjuc.messenger.utils.PlayerUtils.ControlsView.AnonymousClass1 */

                            public void onAnimationEnd(Animator animator) {
                                ControlsView.this.currentAnimation = null;
                            }
                        });
                        this.currentAnimation.start();
                    } else {
                        setAlpha(1.0f);
                    }
                } else if (z2) {
                    AnimatorSet animatorSet3 = new AnimatorSet();
                    this.currentAnimation = animatorSet3;
                    animatorSet3.playTogether(ObjectAnimator.ofFloat(this, "alpha", 0.0f));
                    this.currentAnimation.setDuration(150L);
                    this.currentAnimation.addListener(new AnimatorListenerAdapter() {
                        /* class im.guobwnxjuc.messenger.utils.PlayerUtils.ControlsView.AnonymousClass2 */

                        public void onAnimationEnd(Animator animator) {
                            ControlsView.this.currentAnimation = null;
                        }
                    });
                    this.currentAnimation.start();
                } else {
                    setAlpha(0.0f);
                }
                checkNeedHide();
            }
        }

        /* access modifiers changed from: private */
        /* access modifiers changed from: public */
        private void checkNeedHide() {
            AndroidUtilities.cancelRunOnUIThread(this.hideRunnable);
            if (this.isVisible && PlayerUtils.this.videoPlayer.isPlaying()) {
                AndroidUtilities.runOnUIThread(this.hideRunnable, 3000);
            }
        }

        public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
            if (motionEvent.getAction() != 0) {
                return super.onInterceptTouchEvent(motionEvent);
            }
            if (!this.isVisible) {
                show(true, true);
                return true;
            }
            onTouchEvent(motionEvent);
            return this.progressPressed;
        }

        public void requestDisallowInterceptTouchEvent(boolean z) {
            super.requestDisallowInterceptTouchEvent(z);
            checkNeedHide();
        }

        public boolean onTouchEvent(MotionEvent motionEvent) {
            int i;
            int i2;
            int i3;
            if (PlayerUtils.this.inFullscreen) {
                i3 = AndroidUtilities.dp(36.0f) + this.durationWidth;
                i2 = (getMeasuredWidth() - AndroidUtilities.dp(76.0f)) - this.durationWidth;
                i = getMeasuredHeight() - AndroidUtilities.dp(28.0f);
            } else {
                i2 = getMeasuredWidth();
                i = getMeasuredHeight() - AndroidUtilities.dp(12.0f);
                i3 = 0;
            }
            int i4 = this.duration;
            int i5 = (i4 != 0 ? (int) (((float) (i2 - i3)) * (((float) this.progress) / ((float) i4))) : 0) + i3;
            if (motionEvent.getAction() == 0) {
                if (!this.isVisible || PlayerUtils.this.isInline || PlayerUtils.this.isStream) {
                    show(true, true);
                } else if (this.duration != 0) {
                    int x = (int) motionEvent.getX();
                    int y = (int) motionEvent.getY();
                    if (x >= i5 - AndroidUtilities.dp(10.0f) && x <= AndroidUtilities.dp(10.0f) + i5 && y >= i - AndroidUtilities.dp(10.0f) && y <= i + AndroidUtilities.dp(10.0f)) {
                        this.progressPressed = true;
                        this.lastProgressX = x;
                        this.currentProgressX = i5;
                        getParent().requestDisallowInterceptTouchEvent(true);
                        invalidate();
                    }
                }
                AndroidUtilities.cancelRunOnUIThread(this.hideRunnable);
            } else if (motionEvent.getAction() == 1 || motionEvent.getAction() == 3) {
                if (PlayerUtils.this.initied && PlayerUtils.this.videoPlayer.isPlaying()) {
                    AndroidUtilities.runOnUIThread(this.hideRunnable, 3000);
                }
                if (this.progressPressed) {
                    this.progressPressed = false;
                    if (PlayerUtils.this.initied) {
                        this.progress = (int) (((float) this.duration) * (((float) (this.currentProgressX - i3)) / ((float) (i2 - i3))));
                        PlayerUtils.this.videoPlayer.seekTo(((long) this.progress) * 1000);
                    }
                }
            } else if (motionEvent.getAction() == 2 && this.progressPressed) {
                int x2 = (int) motionEvent.getX();
                int i6 = this.currentProgressX - (this.lastProgressX - x2);
                this.currentProgressX = i6;
                this.lastProgressX = x2;
                if (i6 < i3) {
                    this.currentProgressX = i3;
                } else if (i6 > i2) {
                    this.currentProgressX = i2;
                }
                setProgress((int) (((float) (this.duration * 1000)) * (((float) (this.currentProgressX - i3)) / ((float) (i2 - i3)))));
                invalidate();
            }
            super.onTouchEvent(motionEvent);
            return true;
        }

        /* access modifiers changed from: protected */
        /* JADX WARNING: Removed duplicated region for block: B:42:0x014f  */
        /* JADX WARNING: Removed duplicated region for block: B:45:0x0163  */
        /* JADX WARNING: Removed duplicated region for block: B:46:0x0166  */
        /* JADX WARNING: Removed duplicated region for block: B:53:0x0195  */
        /* JADX WARNING: Removed duplicated region for block: B:54:0x0198  */
        /* JADX WARNING: Removed duplicated region for block: B:58:0x01be  */
        /* JADX WARNING: Removed duplicated region for block: B:66:? A[RETURN, SYNTHETIC] */
        public void onDraw(Canvas canvas) {
            int i;
            int i2;
            int i3;
            int i4;
            int i5;
            int i6;
            int i7;
            int dp;
            int dp2;
            if (PlayerUtils.this.drawImage) {
                if (PlayerUtils.this.firstFrameRendered && PlayerUtils.this.currentAlpha != 0.0f) {
                    long currentTimeMillis = System.currentTimeMillis();
                    long j = currentTimeMillis - PlayerUtils.this.lastUpdateTime;
                    PlayerUtils.this.lastUpdateTime = currentTimeMillis;
                    PlayerUtils.this.currentAlpha -= ((float) j) / 150.0f;
                    if (PlayerUtils.this.currentAlpha < 0.0f) {
                        PlayerUtils.this.currentAlpha = 0.0f;
                    }
                    invalidate();
                }
                this.imageReceiver.setAlpha(PlayerUtils.this.currentAlpha);
                this.imageReceiver.draw(canvas);
            }
            if (PlayerUtils.this.videoPlayer.isPlayerPrepared() && !PlayerUtils.this.isStream) {
                int measuredWidth = getMeasuredWidth();
                int measuredHeight = getMeasuredHeight();
                if (!PlayerUtils.this.isInline) {
                    int i8 = 6;
                    if (this.durationLayout != null) {
                        canvas.save();
                        canvas.translate((float) ((measuredWidth - AndroidUtilities.dp(58.0f)) - this.durationWidth), (float) (measuredHeight - AndroidUtilities.dp((float) ((PlayerUtils.this.inFullscreen ? 6 : 10) + 29))));
                        this.durationLayout.draw(canvas);
                        canvas.restore();
                    }
                    if (this.progressLayout != null) {
                        canvas.save();
                        float dp3 = (float) AndroidUtilities.dp(18.0f);
                        if (!PlayerUtils.this.inFullscreen) {
                            i8 = 10;
                        }
                        canvas.translate(dp3, (float) (measuredHeight - AndroidUtilities.dp((float) (i8 + 29))));
                        this.progressLayout.draw(canvas);
                        canvas.restore();
                    }
                }
                if (this.duration != 0) {
                    float f = 7.0f;
                    if (PlayerUtils.this.isInline) {
                        dp = measuredHeight - AndroidUtilities.dp(3.0f);
                        dp2 = AndroidUtilities.dp(7.0f);
                    } else if (PlayerUtils.this.inFullscreen) {
                        int dp4 = measuredHeight - AndroidUtilities.dp(29.0f);
                        int dp5 = AndroidUtilities.dp(36.0f) + this.durationWidth;
                        i4 = (measuredWidth - AndroidUtilities.dp(76.0f)) - this.durationWidth;
                        i3 = measuredHeight - AndroidUtilities.dp(28.0f);
                        i2 = dp4;
                        i = dp5;
                        if (PlayerUtils.this.inFullscreen) {
                            canvas.drawRect((float) i, (float) i2, (float) i4, (float) (AndroidUtilities.dp(3.0f) + i2), this.progressInnerPaint);
                        }
                        if (!this.progressPressed) {
                            i5 = this.currentProgressX;
                        } else {
                            i5 = ((int) (((float) (i4 - i)) * (((float) this.progress) / ((float) this.duration)))) + i;
                        }
                        i6 = this.bufferedPosition;
                        if (!(i6 == 0 || (i7 = this.duration) == 0)) {
                            float f2 = (float) i;
                            canvas.drawRect(f2, (float) i2, (((float) (i4 - i)) * (((float) i6) / ((float) i7))) + f2, (float) (AndroidUtilities.dp(3.0f) + i2), !PlayerUtils.this.inFullscreen ? this.progressBufferedPaint : this.progressInnerPaint);
                        }
                        float f3 = (float) i5;
                        canvas.drawRect((float) i, (float) i2, f3, (float) (i2 + AndroidUtilities.dp(3.0f)), this.progressPaint);
                        if (PlayerUtils.this.isInline) {
                            float f4 = (float) i3;
                            if (!this.progressPressed) {
                                f = 5.0f;
                            }
                            canvas.drawCircle(f3, f4, (float) AndroidUtilities.dp(f), this.progressPaint);
                            return;
                        }
                        return;
                    } else {
                        dp = measuredHeight - AndroidUtilities.dp(13.0f);
                        dp2 = AndroidUtilities.dp(12.0f);
                    }
                    i4 = measuredWidth;
                    i3 = measuredHeight - dp2;
                    i2 = dp;
                    i = 0;
                    if (PlayerUtils.this.inFullscreen) {
                    }
                    if (!this.progressPressed) {
                    }
                    i6 = this.bufferedPosition;
                    float f22 = (float) i;
                    canvas.drawRect(f22, (float) i2, (((float) (i4 - i)) * (((float) i6) / ((float) i7))) + f22, (float) (AndroidUtilities.dp(3.0f) + i2), !PlayerUtils.this.inFullscreen ? this.progressBufferedPaint : this.progressInnerPaint);
                    float f32 = (float) i5;
                    canvas.drawRect((float) i, (float) i2, f32, (float) (i2 + AndroidUtilities.dp(3.0f)), this.progressPaint);
                    if (PlayerUtils.this.isInline) {
                    }
                }
            }
        }
    }

    public PlayerUtils(Context context, boolean z, boolean z2, WebPlayerViewDelegate webPlayerViewDelegate) {
        super(context);
        int i = lastContainerId;
        lastContainerId = i + 1;
        this.fragment_container_id = i;
        this.allowInlineAnimation = Build.VERSION.SDK_INT >= 21;
        this.backgroundPaint = new Paint();
        this.progressRunnable = new Runnable() {
            /* class im.guobwnxjuc.messenger.utils.PlayerUtils.AnonymousClass1 */

            public void run() {
                if (PlayerUtils.this.videoPlayer != null && PlayerUtils.this.videoPlayer.isPlaying()) {
                    PlayerUtils.this.controlsView.setProgress((int) (PlayerUtils.this.videoPlayer.getCurrentPosition() / 1000));
                    PlayerUtils.this.controlsView.setBufferedProgress((int) (PlayerUtils.this.videoPlayer.getBufferedPosition() / 1000));
                    AndroidUtilities.runOnUIThread(PlayerUtils.this.progressRunnable, 1000);
                }
            }
        };
        this.surfaceTextureListener = new TextureView.SurfaceTextureListener() {
            /* class im.guobwnxjuc.messenger.utils.PlayerUtils.AnonymousClass2 */

            public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
            }

            public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
            }

            public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
                if (!PlayerUtils.this.changingTextureView) {
                    return true;
                }
                if (PlayerUtils.this.switchingInlineMode) {
                    PlayerUtils.this.waitingForFirstTextureUpload = 2;
                }
                PlayerUtils.this.textureView.setSurfaceTexture(surfaceTexture);
                PlayerUtils.this.textureView.setVisibility(0);
                PlayerUtils.this.changingTextureView = false;
                return false;
            }

            public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
                if (PlayerUtils.this.waitingForFirstTextureUpload == 1) {
                    PlayerUtils.this.changedTextureView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                        /* class im.guobwnxjuc.messenger.utils.PlayerUtils.AnonymousClass2.AnonymousClass1 */

                        public boolean onPreDraw() {
                            PlayerUtils.this.changedTextureView.getViewTreeObserver().removeOnPreDrawListener(this);
                            if (PlayerUtils.this.textureImageView != null) {
                                PlayerUtils.this.textureImageView.setVisibility(4);
                                PlayerUtils.this.textureImageView.setImageDrawable(null);
                                if (PlayerUtils.this.currentBitmap != null) {
                                    PlayerUtils.this.currentBitmap.recycle();
                                    PlayerUtils.this.currentBitmap = null;
                                }
                            }
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$2$1$rDinkfzY6LHJxlv6S7Hg0MEdlXc */

                                public final void run() {
                                    PlayerUtils.AnonymousClass2.AnonymousClass1.this.lambda$onPreDraw$0$PlayerUtils$2$1();
                                }
                            });
                            PlayerUtils.this.waitingForFirstTextureUpload = 0;
                            return true;
                        }

                        public /* synthetic */ void lambda$onPreDraw$0$PlayerUtils$2$1() {
                            PlayerUtils.this.delegate.onInlineSurfaceTextureReady();
                        }
                    });
                    PlayerUtils.this.changedTextureView.invalidate();
                }
            }
        };
        this.switchToInlineRunnable = new Runnable() {
            /* class im.guobwnxjuc.messenger.utils.PlayerUtils.AnonymousClass3 */

            public void run() {
                PlayerUtils.this.switchingInlineMode = false;
                if (PlayerUtils.this.currentBitmap != null) {
                    PlayerUtils.this.currentBitmap.recycle();
                    PlayerUtils.this.currentBitmap = null;
                }
                PlayerUtils.this.changingTextureView = true;
                if (PlayerUtils.this.textureImageView != null) {
                    try {
                        PlayerUtils.this.currentBitmap = Bitmaps.createBitmap(PlayerUtils.this.textureView.getWidth(), PlayerUtils.this.textureView.getHeight(), Bitmap.Config.ARGB_8888);
                        PlayerUtils.this.textureView.getBitmap(PlayerUtils.this.currentBitmap);
                    } catch (Throwable th) {
                        if (PlayerUtils.this.currentBitmap != null) {
                            PlayerUtils.this.currentBitmap.recycle();
                            PlayerUtils.this.currentBitmap = null;
                        }
                        FileLog.e(th);
                    }
                    if (PlayerUtils.this.currentBitmap != null) {
                        PlayerUtils.this.textureImageView.setVisibility(0);
                        PlayerUtils.this.textureImageView.setImageBitmap(PlayerUtils.this.currentBitmap);
                    } else {
                        PlayerUtils.this.textureImageView.setImageDrawable(null);
                    }
                }
                PlayerUtils.this.isInline = true;
                PlayerUtils.this.updatePlayButton();
                PlayerUtils.this.updateShareButton();
                PlayerUtils.this.updateFullscreenButton();
                PlayerUtils.this.updateInlineButton();
                ViewGroup viewGroup = (ViewGroup) PlayerUtils.this.controlsView.getParent();
                if (viewGroup != null) {
                    viewGroup.removeView(PlayerUtils.this.controlsView);
                }
                PlayerUtils playerUtils = PlayerUtils.this;
                playerUtils.changedTextureView = playerUtils.delegate.onSwitchInlineMode(PlayerUtils.this.controlsView, PlayerUtils.this.isInline, PlayerUtils.this.aspectRatioFrameLayout.getAspectRatio(), PlayerUtils.this.aspectRatioFrameLayout.getVideoRotation(), PlayerUtils.this.allowInlineAnimation);
                PlayerUtils.this.changedTextureView.setVisibility(4);
                ViewGroup viewGroup2 = (ViewGroup) PlayerUtils.this.textureView.getParent();
                if (viewGroup2 != null) {
                    viewGroup2.removeView(PlayerUtils.this.textureView);
                }
                PlayerUtils.this.controlsView.show(false, false);
            }
        };
        setWillNotDraw(false);
        this.delegate = webPlayerViewDelegate;
        this.backgroundPaint.setColor(-16777216);
        AnonymousClass4 r14 = new AspectRatioFrameLayout(context) {
            /* class im.guobwnxjuc.messenger.utils.PlayerUtils.AnonymousClass4 */

            /* access modifiers changed from: protected */
            @Override // com.google.android.exoplayer2.ui.AspectRatioFrameLayout
            public void onMeasure(int i, int i2) {
                super.onMeasure(i, i2);
                if (PlayerUtils.this.textureViewContainer != null) {
                    ViewGroup.LayoutParams layoutParams = PlayerUtils.this.textureView.getLayoutParams();
                    layoutParams.width = getMeasuredWidth();
                    layoutParams.height = getMeasuredHeight();
                    if (PlayerUtils.this.textureImageView != null) {
                        ViewGroup.LayoutParams layoutParams2 = PlayerUtils.this.textureImageView.getLayoutParams();
                        layoutParams2.width = getMeasuredWidth();
                        layoutParams2.height = getMeasuredHeight();
                    }
                }
            }
        };
        this.aspectRatioFrameLayout = r14;
        addView(r14, LayoutHelper.createFrame(-1, -1, 17));
        this.interfaceName = "JavaScriptInterface";
        WebView webView2 = new WebView(context);
        this.webView = webView2;
        webView2.addJavascriptInterface(new JavaScriptInterface(new CallJavaResultInterface() {
            /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$j8uTKLmjFXipxVg7VlZn4hpyFW8 */

            @Override // im.guobwnxjuc.messenger.utils.PlayerUtils.CallJavaResultInterface
            public final void jsCallFinished(String str) {
                PlayerUtils.this.lambda$new$0$PlayerUtils(str);
            }
        }), this.interfaceName);
        WebSettings settings = this.webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDefaultTextEncodingName("utf-8");
        this.textureViewContainer = this.delegate.getTextureViewContainer();
        ScaleTextureView scaleTextureView = new ScaleTextureView(context);
        this.textureView = scaleTextureView;
        scaleTextureView.setPivotX(0.0f);
        this.textureView.setPivotY(0.0f);
        ViewGroup viewGroup = this.textureViewContainer;
        if (viewGroup != null) {
            viewGroup.addView(this.textureView);
        } else {
            this.aspectRatioFrameLayout.addView(this.textureView, LayoutHelper.createFrame(-1, -1, 17));
        }
        if (this.allowInlineAnimation && this.textureViewContainer != null) {
            ImageView imageView = new ImageView(context);
            this.textureImageView = imageView;
            imageView.setBackgroundColor(SupportMenu.CATEGORY_MASK);
            this.textureImageView.setPivotX(0.0f);
            this.textureImageView.setPivotY(0.0f);
            this.textureImageView.setVisibility(4);
            this.textureViewContainer.addView(this.textureImageView);
        }
        VideoPlayer videoPlayer2 = new VideoPlayer();
        this.videoPlayer = videoPlayer2;
        videoPlayer2.setDelegate(this);
        this.videoPlayer.setTextureView(this.textureView);
        ControlsView controlsView2 = new ControlsView(context);
        this.controlsView = controlsView2;
        ViewGroup viewGroup2 = this.textureViewContainer;
        if (viewGroup2 != null) {
            viewGroup2.addView(controlsView2);
        } else {
            addView(controlsView2, LayoutHelper.createFrame(-1, -1.0f));
        }
        RadialProgressView radialProgressView = new RadialProgressView(context);
        this.progressView = radialProgressView;
        radialProgressView.setProgressColor(-1);
        addView(this.progressView, LayoutHelper.createFrame(48, 48, 17));
        ImageView imageView2 = new ImageView(context);
        this.fullscreenButton = imageView2;
        imageView2.setScaleType(ImageView.ScaleType.CENTER);
        this.controlsView.addView(this.fullscreenButton, LayoutHelper.createFrame(56.0f, 56.0f, 85, 0.0f, 0.0f, 0.0f, 5.0f));
        this.fullscreenButton.setOnClickListener(new View.OnClickListener() {
            /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$3VXP8qBj0I7VJeJ72k2PTrSoUsE */

            public final void onClick(View view) {
                PlayerUtils.this.lambda$new$1$PlayerUtils(view);
            }
        });
        ImageView imageView3 = new ImageView(context);
        this.playButton = imageView3;
        imageView3.setScaleType(ImageView.ScaleType.CENTER);
        this.controlsView.addView(this.playButton, LayoutHelper.createFrame(48, 48, 17));
        this.playButton.setOnClickListener(new View.OnClickListener() {
            /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$gblKX_h2panwSwY6MnUDlw6caA */

            public final void onClick(View view) {
                PlayerUtils.this.lambda$new$2$PlayerUtils(view);
            }
        });
        if (z) {
            ImageView imageView4 = new ImageView(context);
            this.inlineButton = imageView4;
            imageView4.setScaleType(ImageView.ScaleType.CENTER);
            this.controlsView.addView(this.inlineButton, LayoutHelper.createFrame(56, 48, 53));
            this.inlineButton.setOnClickListener(new View.OnClickListener() {
                /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$B5A0cSqB0tFx22BDzptgpy1lKw4 */

                public final void onClick(View view) {
                    PlayerUtils.this.lambda$new$3$PlayerUtils(view);
                }
            });
        }
        if (z2) {
            ImageView imageView5 = new ImageView(context);
            this.shareButton = imageView5;
            imageView5.setScaleType(ImageView.ScaleType.CENTER);
            this.shareButton.setImageResource(R.drawable.ic_share_video);
            this.controlsView.addView(this.shareButton, LayoutHelper.createFrame(56, 48, 53));
            this.shareButton.setOnClickListener(new View.OnClickListener() {
                /* class im.guobwnxjuc.messenger.utils.$$Lambda$PlayerUtils$pkorj1QpcJWhnS3JyF5WcvzWVE */

                public final void onClick(View view) {
                    PlayerUtils.this.lambda$new$4$PlayerUtils(view);
                }
            });
        }
        updatePlayButton();
        updateFullscreenButton();
        updateInlineButton();
        updateShareButton();
    }

    public /* synthetic */ void lambda$new$0$PlayerUtils(String str) {
        AsyncTask asyncTask = this.currentTask;
        if (asyncTask != null && !asyncTask.isCancelled()) {
            AsyncTask asyncTask2 = this.currentTask;
            if (asyncTask2 instanceof YoutubeVideoTask) {
                ((YoutubeVideoTask) asyncTask2).onInterfaceResult(str);
            }
        }
    }

    public /* synthetic */ void lambda$new$1$PlayerUtils(View view) {
        if (this.initied && !this.changingTextureView && !this.switchingInlineMode && this.firstFrameRendered) {
            this.inFullscreen = !this.inFullscreen;
            updateFullscreenState(true);
        }
    }

    public /* synthetic */ void lambda$new$2$PlayerUtils(View view) {
        if (this.initied && this.playVideoUrl != null) {
            if (!this.videoPlayer.isPlayerPrepared()) {
                preparePlayer();
            }
            if (this.videoPlayer.isPlaying()) {
                this.videoPlayer.pause();
            } else {
                this.isCompleted = false;
                this.videoPlayer.play();
            }
            updatePlayButton();
        }
    }

    public /* synthetic */ void lambda$new$3$PlayerUtils(View view) {
        if (this.textureView != null && this.delegate.checkInlinePermissions() && !this.changingTextureView && !this.switchingInlineMode && this.firstFrameRendered) {
            this.switchingInlineMode = true;
            if (!this.isInline) {
                this.inFullscreen = false;
                this.delegate.prepareToSwitchInlineMode(true, this.switchToInlineRunnable, this.aspectRatioFrameLayout.getAspectRatio(), this.allowInlineAnimation);
                return;
            }
            ViewGroup viewGroup = (ViewGroup) this.aspectRatioFrameLayout.getParent();
            if (viewGroup != this) {
                if (viewGroup != null) {
                    viewGroup.removeView(this.aspectRatioFrameLayout);
                }
                addView(this.aspectRatioFrameLayout, 0, LayoutHelper.createFrame(-1, -1, 17));
                this.aspectRatioFrameLayout.measure(View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), 1073741824), View.MeasureSpec.makeMeasureSpec(getMeasuredHeight() - AndroidUtilities.dp(10.0f), 1073741824));
            }
            Bitmap bitmap = this.currentBitmap;
            if (bitmap != null) {
                bitmap.recycle();
                this.currentBitmap = null;
            }
            this.changingTextureView = true;
            this.isInline = false;
            updatePlayButton();
            updateShareButton();
            updateFullscreenButton();
            updateInlineButton();
            this.textureView.setVisibility(4);
            ViewGroup viewGroup2 = this.textureViewContainer;
            if (viewGroup2 != null) {
                viewGroup2.addView(this.textureView);
            } else {
                this.aspectRatioFrameLayout.addView(this.textureView);
            }
            ViewGroup viewGroup3 = (ViewGroup) this.controlsView.getParent();
            if (viewGroup3 != this) {
                if (viewGroup3 != null) {
                    viewGroup3.removeView(this.controlsView);
                }
                ViewGroup viewGroup4 = this.textureViewContainer;
                if (viewGroup4 != null) {
                    viewGroup4.addView(this.controlsView);
                } else {
                    addView(this.controlsView, 1);
                }
            }
            this.controlsView.show(false, false);
            this.delegate.prepareToSwitchInlineMode(false, null, this.aspectRatioFrameLayout.getAspectRatio(), this.allowInlineAnimation);
        }
    }

    public /* synthetic */ void lambda$new$4$PlayerUtils(View view) {
        WebPlayerViewDelegate webPlayerViewDelegate = this.delegate;
        if (webPlayerViewDelegate != null) {
            webPlayerViewDelegate.onSharePressed();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void onInitFailed() {
        if (this.controlsView.getParent() != this) {
            this.controlsView.setVisibility(8);
        }
        this.delegate.onInitFailed();
    }

    public void updateTextureImageView() {
        if (this.textureImageView != null) {
            try {
                Bitmap createBitmap = Bitmaps.createBitmap(this.textureView.getWidth(), this.textureView.getHeight(), Bitmap.Config.ARGB_8888);
                this.currentBitmap = createBitmap;
                this.changedTextureView.getBitmap(createBitmap);
            } catch (Throwable th) {
                Bitmap bitmap = this.currentBitmap;
                if (bitmap != null) {
                    bitmap.recycle();
                    this.currentBitmap = null;
                }
                FileLog.e(th);
            }
            if (this.currentBitmap != null) {
                this.textureImageView.setVisibility(0);
                this.textureImageView.setImageBitmap(this.currentBitmap);
                return;
            }
            this.textureImageView.setImageDrawable(null);
        }
    }

    public String getYoutubeId() {
        return this.currentYoutubeId;
    }

    @Override // im.guobwnxjuc.ui.components.VideoPlayer.VideoPlayerDelegate
    public void onStateChanged(boolean z, int i) {
        if (i != 2) {
            if (this.videoPlayer.getDuration() != C.TIME_UNSET) {
                this.controlsView.setDuration((int) (this.videoPlayer.getDuration() / 1000));
            } else {
                this.controlsView.setDuration(0);
            }
        }
        if (i == 2 || i == 1) {
            showProgress(true, true);
        }
        if (i == 3) {
            showProgress(false, true);
            if (isInFullscreen()) {
                this.videoPlayer.setMute(false);
            } else {
                this.videoPlayer.setMute(true);
            }
        }
        if (i == 4 || i == 1 || !this.videoPlayer.isPlaying()) {
            this.delegate.onPlayStateChanged(this, false, i);
        } else {
            this.delegate.onPlayStateChanged(this, true, i);
        }
        if (this.videoPlayer.isPlaying() && i != 4) {
            updatePlayButton();
        } else if (i == 4) {
            this.isCompleted = true;
            this.videoPlayer.pause();
            this.videoPlayer.seekTo(0);
            updatePlayButton();
            this.controlsView.show(true, true);
            if (this.initied && this.playVideoUrl != null) {
                if (!this.videoPlayer.isPlayerPrepared()) {
                    preparePlayer();
                }
                if (this.videoPlayer.isPlaying()) {
                    this.videoPlayer.pause();
                } else {
                    this.isCompleted = false;
                    this.videoPlayer.play();
                }
                updatePlayButton();
            }
        }
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        canvas.drawRect(0.0f, 0.0f, (float) getMeasuredWidth(), (float) (getMeasuredHeight() - AndroidUtilities.dp(10.0f)), this.backgroundPaint);
    }

    @Override // im.guobwnxjuc.ui.components.VideoPlayer.VideoPlayerDelegate
    public void onError(Exception exc) {
        FileLog.e(exc);
        onInitFailed();
    }

    @Override // im.guobwnxjuc.ui.components.VideoPlayer.VideoPlayerDelegate
    public void onVideoSizeChanged(int i, int i2, int i3, float f) {
        ScaleTextureView scaleTextureView = this.textureView;
        if (scaleTextureView != null) {
            scaleTextureView.setmVideoHeight(i2);
            this.textureView.setmVideoWidth(i);
            this.textureView.requestLayout();
        }
        if (this.aspectRatioFrameLayout != null) {
            if (!(i3 == 90 || i3 == 270)) {
                i2 = i;
                i = i2;
            }
            float f2 = i == 0 ? 1.0f : (((float) i2) * f) / ((float) i);
            this.aspectRatioFrameLayout.setAspectRatio(f2, i3);
            if (this.inFullscreen) {
                this.delegate.onVideoSizeChanged(f2, i3);
            }
        }
    }

    @Override // im.guobwnxjuc.ui.components.VideoPlayer.VideoPlayerDelegate
    public void onRenderedFirstFrame() {
        this.firstFrameRendered = true;
        this.lastUpdateTime = System.currentTimeMillis();
        this.controlsView.invalidate();
    }

    @Override // im.guobwnxjuc.ui.components.VideoPlayer.VideoPlayerDelegate
    public boolean onSurfaceDestroyed(SurfaceTexture surfaceTexture) {
        if (this.changingTextureView) {
            this.changingTextureView = false;
            if (this.inFullscreen || this.isInline) {
                if (this.isInline) {
                    this.waitingForFirstTextureUpload = 1;
                }
                this.changedTextureView.setSurfaceTexture(surfaceTexture);
                this.changedTextureView.setSurfaceTextureListener(this.surfaceTextureListener);
                this.changedTextureView.setVisibility(0);
                return true;
            }
        }
        return false;
    }

    @Override // im.guobwnxjuc.ui.components.VideoPlayer.VideoPlayerDelegate
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
        if (this.waitingForFirstTextureUpload == 2) {
            ImageView imageView = this.textureImageView;
            if (imageView != null) {
                imageView.setVisibility(4);
                this.textureImageView.setImageDrawable(null);
                Bitmap bitmap = this.currentBitmap;
                if (bitmap != null) {
                    bitmap.recycle();
                    this.currentBitmap = null;
                }
            }
            this.switchingInlineMode = false;
            this.delegate.onSwitchInlineMode(this.controlsView, false, this.aspectRatioFrameLayout.getAspectRatio(), this.aspectRatioFrameLayout.getVideoRotation(), this.allowInlineAnimation);
            this.waitingForFirstTextureUpload = 0;
        }
    }

    /* access modifiers changed from: protected */
    public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        int i5 = i3 - i;
        int measuredWidth = (i5 - this.aspectRatioFrameLayout.getMeasuredWidth()) / 2;
        int i6 = i4 - i2;
        int dp = ((i6 - AndroidUtilities.dp(10.0f)) - this.aspectRatioFrameLayout.getMeasuredHeight()) / 2;
        AspectRatioFrameLayout aspectRatioFrameLayout2 = this.aspectRatioFrameLayout;
        aspectRatioFrameLayout2.layout(measuredWidth, dp, aspectRatioFrameLayout2.getMeasuredWidth() + measuredWidth, this.aspectRatioFrameLayout.getMeasuredHeight() + dp);
        if (this.controlsView.getParent() == this) {
            ControlsView controlsView2 = this.controlsView;
            controlsView2.layout(0, 0, controlsView2.getMeasuredWidth(), this.controlsView.getMeasuredHeight());
        }
        int measuredWidth2 = (i5 - this.progressView.getMeasuredWidth()) / 2;
        int measuredHeight = (i6 - this.progressView.getMeasuredHeight()) / 2;
        RadialProgressView radialProgressView = this.progressView;
        radialProgressView.layout(measuredWidth2, measuredHeight, radialProgressView.getMeasuredWidth() + measuredWidth2, this.progressView.getMeasuredHeight() + measuredHeight);
        this.controlsView.imageReceiver.setImageCoords(0, 0, getMeasuredWidth(), getMeasuredHeight() - AndroidUtilities.dp(10.0f));
    }

    /* access modifiers changed from: protected */
    public void onMeasure(int i, int i2) {
        int size = View.MeasureSpec.getSize(i);
        int size2 = View.MeasureSpec.getSize(i2);
        this.aspectRatioFrameLayout.measure(View.MeasureSpec.makeMeasureSpec(size, 1073741824), View.MeasureSpec.makeMeasureSpec(size2 - AndroidUtilities.dp(10.0f), 1073741824));
        if (this.controlsView.getParent() == this) {
            this.controlsView.measure(View.MeasureSpec.makeMeasureSpec(size, 1073741824), View.MeasureSpec.makeMeasureSpec(size2, 1073741824));
        }
        this.progressView.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(44.0f), 1073741824), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(44.0f), 1073741824));
        setMeasuredDimension(size, size2);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void updatePlayButton() {
        this.controlsView.checkNeedHide();
        AndroidUtilities.cancelRunOnUIThread(this.progressRunnable);
        if (this.videoPlayer.isPlaying()) {
            this.playButton.setImageResource(this.isInline ? R.drawable.ic_pauseinline : R.drawable.ic_pause);
            AndroidUtilities.runOnUIThread(this.progressRunnable, 500);
            checkAudioFocus();
        } else if (this.isCompleted) {
            this.playButton.setImageResource(this.isInline ? R.drawable.ic_againinline : R.drawable.ic_again);
        } else {
            this.playButton.setImageResource(this.isInline ? R.drawable.ic_playinline : R.drawable.ic_play);
        }
    }

    private void checkAudioFocus() {
        if (!this.hasAudioFocus) {
            this.hasAudioFocus = true;
            if (((AudioManager) ApplicationLoader.applicationContext.getSystemService(MimeTypes.BASE_TYPE_AUDIO)).requestAudioFocus(this, 3, 1) == 1) {
                this.audioFocus = 2;
            }
        }
    }

    public void onAudioFocusChange(int i) {
        if (i == -1) {
            if (this.videoPlayer.isPlaying()) {
                this.videoPlayer.pause();
                updatePlayButton();
            }
            this.hasAudioFocus = false;
            this.audioFocus = 0;
        } else if (i == 1) {
            this.audioFocus = 2;
            if (this.resumeAudioOnFocusGain) {
                this.resumeAudioOnFocusGain = false;
                this.videoPlayer.play();
            }
        } else if (i == -3) {
            this.audioFocus = 1;
        } else if (i == -2) {
            this.audioFocus = 0;
            if (this.videoPlayer.isPlaying()) {
                this.resumeAudioOnFocusGain = true;
                this.videoPlayer.pause();
                updatePlayButton();
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void updateFullscreenButton() {
        if (!this.videoPlayer.isPlayerPrepared() || this.isInline) {
            this.fullscreenButton.setVisibility(8);
            return;
        }
        this.fullscreenButton.setVisibility(0);
        if (!this.inFullscreen) {
            this.fullscreenButton.setImageResource(R.drawable.ic_gofullscreen);
            this.fullscreenButton.setLayoutParams(LayoutHelper.createFrame(56.0f, 56.0f, 85, 0.0f, 0.0f, 0.0f, 5.0f));
            return;
        }
        this.fullscreenButton.setImageResource(R.drawable.ic_outfullscreen);
        this.fullscreenButton.setLayoutParams(LayoutHelper.createFrame(56.0f, 56.0f, 85, 0.0f, 0.0f, 0.0f, 1.0f));
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void updateShareButton() {
        ImageView imageView = this.shareButton;
        if (imageView != null) {
            imageView.setVisibility((this.isInline || !this.videoPlayer.isPlayerPrepared()) ? 8 : 0);
        }
    }

    private View getControlView() {
        return this.controlsView;
    }

    public View getProgressView() {
        return this.progressView;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void updateInlineButton() {
        ImageView imageView = this.inlineButton;
        if (imageView != null) {
            imageView.setImageResource(this.isInline ? R.drawable.ic_goinline : R.drawable.ic_outinline);
            this.inlineButton.setVisibility(this.videoPlayer.isPlayerPrepared() ? 0 : 8);
            if (this.isInline) {
                this.inlineButton.setLayoutParams(LayoutHelper.createFrame(40, 40, 53));
            } else {
                this.inlineButton.setLayoutParams(LayoutHelper.createFrame(56, 50, 53));
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void preparePlayer() {
        String str = this.playVideoUrl;
        if (str != null) {
            if (str == null || this.playAudioUrl == null) {
                this.videoPlayer.preparePlayer(Uri.parse(this.playVideoUrl), this.playVideoType);
            } else {
                this.videoPlayer.preparePlayerLoop(Uri.parse(str), this.playVideoType, Uri.parse(this.playAudioUrl), this.playAudioType);
            }
            this.videoPlayer.setPlayWhenReady(this.isAutoplay);
            this.isLoading = false;
            if (this.videoPlayer.getDuration() != C.TIME_UNSET) {
                this.controlsView.setDuration((int) (this.videoPlayer.getDuration() / 1000));
            } else {
                this.controlsView.setDuration(0);
            }
            updateFullscreenButton();
            updateShareButton();
            updateInlineButton();
            this.controlsView.invalidate();
            int i = this.seekToTime;
            if (i != -1) {
                this.videoPlayer.seekTo((long) (i * 1000));
            }
        }
    }

    public void pause() {
        this.videoPlayer.pause();
        updatePlayButton();
        this.controlsView.show(true, true);
    }

    private void updateFullscreenState(boolean z) {
        ViewGroup viewGroup;
        if (this.textureView != null) {
            updateFullscreenButton();
            ViewGroup viewGroup2 = this.textureViewContainer;
            if (viewGroup2 == null) {
                this.changingTextureView = true;
                if (!this.inFullscreen) {
                    if (viewGroup2 != null) {
                        viewGroup2.addView(this.textureView);
                    } else {
                        this.aspectRatioFrameLayout.addView(this.textureView);
                    }
                }
                if (this.inFullscreen) {
                    ViewGroup viewGroup3 = (ViewGroup) this.controlsView.getParent();
                    if (viewGroup3 != null) {
                        viewGroup3.removeView(this.controlsView);
                    }
                } else {
                    ViewGroup viewGroup4 = (ViewGroup) this.controlsView.getParent();
                    if (viewGroup4 != this) {
                        if (viewGroup4 != null) {
                            viewGroup4.removeView(this.controlsView);
                        }
                        ViewGroup viewGroup5 = this.textureViewContainer;
                        if (viewGroup5 != null) {
                            viewGroup5.addView(this.controlsView);
                        } else {
                            addView(this.controlsView, 1);
                        }
                    }
                }
                TextureView onSwitchToFullscreen = this.delegate.onSwitchToFullscreen(this.controlsView, this.inFullscreen, this.aspectRatioFrameLayout.getAspectRatio(), this.aspectRatioFrameLayout.getVideoRotation(), z);
                this.changedTextureView = onSwitchToFullscreen;
                onSwitchToFullscreen.setVisibility(4);
                if (!(!this.inFullscreen || this.changedTextureView == null || (viewGroup = (ViewGroup) this.textureView.getParent()) == null)) {
                    viewGroup.removeView(this.textureView);
                }
                this.controlsView.checkNeedHide();
                return;
            }
            if (this.inFullscreen) {
                this.videoPlayer.setMute(false);
                ViewGroup viewGroup6 = (ViewGroup) this.textureView.getParent();
                if (viewGroup6 != null) {
                    viewGroup6.removeView(this.textureView);
                }
                ViewGroup viewGroup7 = (ViewGroup) this.progressView.getParent();
                if (viewGroup7 != null) {
                    viewGroup7.removeView(this.progressView);
                }
            } else {
                this.videoPlayer.setMute(true);
                ViewGroup viewGroup8 = (ViewGroup) this.textureView.getParent();
                if (viewGroup8 != this) {
                    if (viewGroup8 != null) {
                        viewGroup8.removeView(this.textureView);
                    }
                    this.textureViewContainer.addView(this.textureView);
                }
                ViewGroup viewGroup9 = (ViewGroup) this.progressView.getParent();
                if (viewGroup9 != this) {
                    if (viewGroup9 != null) {
                        viewGroup9.removeView(this.progressView);
                    }
                    this.textureViewContainer.addView(this.progressView, LayoutHelper.createFrame(48, 48, 17));
                }
            }
            this.delegate.onSwitchToFullscreen(this.controlsView, this.inFullscreen, this.aspectRatioFrameLayout.getAspectRatio(), this.aspectRatioFrameLayout.getVideoRotation(), z);
        }
    }

    public void exitFullscreen() {
        if (this.inFullscreen) {
            this.inFullscreen = false;
            updateInlineButton();
            updateFullscreenState(false);
        }
    }

    public boolean isInitied() {
        return this.initied;
    }

    public boolean isInline() {
        return this.isInline || this.switchingInlineMode;
    }

    public void enterFullscreen() {
        if (!this.inFullscreen) {
            this.inFullscreen = true;
            updateInlineButton();
            updateFullscreenState(false);
        }
    }

    public boolean isInFullscreen() {
        return this.inFullscreen;
    }

    public boolean isPlaying() {
        return this.progressView.getAlpha() == 0.0f;
    }

    public String getYouTubeVideoId(String str) {
        Matcher matcher = youtubeIdRegex.matcher(str);
        if (matcher.find()) {
            return matcher.group(1);
        }
        return null;
    }

    public void setTextureViewContainer(ViewGroup viewGroup) {
        if (viewGroup != null) {
            ViewGroup viewGroup2 = (ViewGroup) this.textureView.getParent();
            if (!(viewGroup2 == null || viewGroup2 == viewGroup)) {
                viewGroup2.removeView(this.textureView);
                this.textureViewContainer = viewGroup;
                viewGroup.addView(this.textureView);
            }
            ViewGroup viewGroup3 = (ViewGroup) this.progressView.getParent();
            if (viewGroup3 != null && viewGroup3 != viewGroup) {
                viewGroup3.removeView(this.progressView);
                this.textureViewContainer = viewGroup;
                viewGroup.addView(this.progressView, LayoutHelper.createFrame(48, 48, 17));
                showProgress(true, true);
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:40:0x00a9 A[SYNTHETIC, Splitter:B:40:0x00a9] */
    /* JADX WARNING: Removed duplicated region for block: B:52:0x00c8 A[SYNTHETIC, Splitter:B:52:0x00c8] */
    /* JADX WARNING: Removed duplicated region for block: B:64:0x00e7 A[SYNTHETIC, Splitter:B:64:0x00e7] */
    /* JADX WARNING: Removed duplicated region for block: B:76:0x0106 A[SYNTHETIC, Splitter:B:76:0x0106] */
    public boolean loadVideo(String str, TLRPC.Photo photo, Object obj, String str2, boolean z) {
        String str3;
        String str4;
        String str5;
        String str6;
        String str7;
        String str8;
        String str9;
        this.seekToTime = -1;
        if (str == null) {
            str9 = null;
            str8 = null;
            str7 = null;
            str6 = null;
            str5 = null;
            str4 = null;
            str3 = null;
        } else if (str.endsWith(".mp4")) {
            str3 = str;
            str9 = null;
            str8 = null;
            str7 = null;
            str6 = null;
            str5 = null;
            str4 = null;
        } else {
            if (str2 != null) {
                try {
                    Uri parse = Uri.parse(str2);
                    String queryParameter = parse.getQueryParameter("t");
                    if (queryParameter == null) {
                        queryParameter = parse.getQueryParameter("time_continue");
                    }
                    if (queryParameter != null) {
                        if (queryParameter.contains("m")) {
                            String[] split = queryParameter.split("m");
                            this.seekToTime = (Utilities.parseInt(split[0]).intValue() * 60) + Utilities.parseInt(split[1]).intValue();
                        } else {
                            this.seekToTime = Utilities.parseInt(queryParameter).intValue();
                        }
                    }
                } catch (Exception e) {
                    try {
                        FileLog.e(e);
                    } catch (Exception e2) {
                        FileLog.e(e2);
                        str8 = null;
                    }
                }
            }
            Matcher matcher = youtubeIdRegex.matcher(str);
            String group = matcher.find() ? matcher.group(1) : null;
            if (group == null) {
                group = null;
            }
            str8 = group;
            if (str8 == null) {
                try {
                    Matcher matcher2 = vimeoIdRegex.matcher(str);
                    String group2 = matcher2.find() ? matcher2.group(3) : null;
                    if (group2 == null) {
                        group2 = null;
                    }
                    str7 = group2;
                } catch (Exception e3) {
                    FileLog.e(e3);
                }
                if (str7 == null) {
                    try {
                        Matcher matcher3 = aparatIdRegex.matcher(str);
                        String group3 = matcher3.find() ? matcher3.group(1) : null;
                        if (group3 == null) {
                            group3 = null;
                        }
                        str6 = group3;
                    } catch (Exception e4) {
                        FileLog.e(e4);
                    }
                    if (str6 == null) {
                        try {
                            Matcher matcher4 = twitchClipIdRegex.matcher(str);
                            String group4 = matcher4.find() ? matcher4.group(1) : null;
                            if (group4 == null) {
                                group4 = null;
                            }
                            str5 = group4;
                        } catch (Exception e5) {
                            FileLog.e(e5);
                        }
                        if (str5 == null) {
                            try {
                                Matcher matcher5 = twitchStreamIdRegex.matcher(str);
                                String group5 = matcher5.find() ? matcher5.group(1) : null;
                                if (group5 == null) {
                                    group5 = null;
                                }
                                str4 = group5;
                            } catch (Exception e6) {
                                FileLog.e(e6);
                            }
                            if (str4 == null) {
                                try {
                                    Matcher matcher6 = coubIdRegex.matcher(str);
                                    str9 = matcher6.find() ? matcher6.group(1) : null;
                                    if (str9 == null) {
                                        str9 = null;
                                    }
                                    str3 = null;
                                } catch (Exception e7) {
                                    FileLog.e(e7);
                                }
                            }
                            str9 = null;
                            str3 = null;
                        }
                        str4 = null;
                        if (str4 == null) {
                        }
                        str9 = null;
                        str3 = null;
                    }
                    str5 = null;
                    if (str5 == null) {
                    }
                    str4 = null;
                    if (str4 == null) {
                    }
                    str9 = null;
                    str3 = null;
                }
                str6 = null;
                if (str6 == null) {
                }
                str5 = null;
                if (str5 == null) {
                }
                str4 = null;
                if (str4 == null) {
                }
                str9 = null;
                str3 = null;
            }
            str7 = null;
            if (str7 == null) {
            }
            str6 = null;
            if (str6 == null) {
            }
            str5 = null;
            if (str5 == null) {
            }
            str4 = null;
            if (str4 == null) {
            }
            str9 = null;
            str3 = null;
        }
        this.initied = false;
        this.isCompleted = false;
        this.isAutoplay = z;
        this.playVideoUrl = null;
        this.playAudioUrl = null;
        destroy();
        this.firstFrameRendered = false;
        this.currentAlpha = 1.0f;
        AsyncTask asyncTask = this.currentTask;
        if (asyncTask != null) {
            asyncTask.cancel(true);
            this.currentTask = null;
        }
        updateFullscreenButton();
        updateShareButton();
        updateInlineButton();
        updatePlayButton();
        if (photo != null) {
            TLRPC.PhotoSize closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 80, true);
            if (closestPhotoSizeWithSize != null) {
                this.controlsView.imageReceiver.setImage(null, null, ImageLocation.getForPhoto(closestPhotoSizeWithSize, photo), "80_80_b", 0, null, obj, 1);
                this.drawImage = true;
            }
        } else {
            this.drawImage = false;
        }
        AnimatorSet animatorSet = this.progressAnimation;
        if (animatorSet != null) {
            animatorSet.cancel();
            this.progressAnimation = null;
        }
        this.isLoading = true;
        this.controlsView.setProgress(0);
        if (str8 != null) {
            this.currentYoutubeId = str8;
            str8 = null;
        }
        if (str3 != null) {
            this.initied = true;
            this.playVideoUrl = str3;
            this.playVideoType = "other";
            if (this.isAutoplay) {
                preparePlayer();
                this.videoPlayer.setMute(true);
            }
            showProgress(false, false);
            this.controlsView.show(true, true);
        } else {
            if (str8 != null) {
                YoutubeVideoTask youtubeVideoTask = new YoutubeVideoTask(str8);
                youtubeVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
                this.currentTask = youtubeVideoTask;
            } else if (str7 != null) {
                VimeoVideoTask vimeoVideoTask = new VimeoVideoTask(str7);
                vimeoVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
                this.currentTask = vimeoVideoTask;
            } else if (str9 != null) {
                CoubVideoTask coubVideoTask = new CoubVideoTask(str9);
                coubVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
                this.currentTask = coubVideoTask;
                this.isStream = true;
            } else if (str6 != null) {
                AparatVideoTask aparatVideoTask = new AparatVideoTask(str6);
                aparatVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
                this.currentTask = aparatVideoTask;
            } else if (str5 != null) {
                TwitchClipVideoTask twitchClipVideoTask = new TwitchClipVideoTask(str, str5);
                twitchClipVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
                this.currentTask = twitchClipVideoTask;
            } else if (str4 != null) {
                TwitchStreamVideoTask twitchStreamVideoTask = new TwitchStreamVideoTask(str, str4);
                twitchStreamVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
                this.currentTask = twitchStreamVideoTask;
                this.isStream = true;
            }
            this.controlsView.show(false, false);
            showProgress(true, false);
        }
        if (str8 == null && str7 == null && str9 == null && str6 == null && str3 == null && str5 == null && str4 == null) {
            this.controlsView.setVisibility(8);
            return false;
        }
        this.controlsView.setVisibility(0);
        return true;
    }

    public View getAspectRatioView() {
        return this.aspectRatioFrameLayout;
    }

    public TextureView getTextureView() {
        return this.textureView;
    }

    public ImageView getTextureImageView() {
        return this.textureImageView;
    }

    public View getControlsView() {
        return this.controlsView;
    }

    public void destroy() {
        this.videoPlayer.releasePlayer(false);
        AsyncTask asyncTask = this.currentTask;
        if (asyncTask != null) {
            asyncTask.cancel(true);
            this.currentTask = null;
        }
        this.webView.stopLoading();
        mPlayer = null;
    }

    public void showProgress(boolean z, boolean z2) {
        float f = 1.0f;
        if (z2) {
            AnimatorSet animatorSet = this.progressAnimation;
            if (animatorSet != null) {
                animatorSet.cancel();
            }
            AnimatorSet animatorSet2 = new AnimatorSet();
            this.progressAnimation = animatorSet2;
            Animator[] animatorArr = new Animator[1];
            RadialProgressView radialProgressView = this.progressView;
            float[] fArr = new float[1];
            if (!z) {
                f = 0.0f;
            }
            fArr[0] = f;
            animatorArr[0] = ObjectAnimator.ofFloat(radialProgressView, "alpha", fArr);
            animatorSet2.playTogether(animatorArr);
            this.progressAnimation.setDuration(150L);
            this.progressAnimation.addListener(new AnimatorListenerAdapter() {
                /* class im.guobwnxjuc.messenger.utils.PlayerUtils.AnonymousClass5 */

                public void onAnimationEnd(Animator animator) {
                    PlayerUtils.this.progressAnimation = null;
                }
            });
            this.progressAnimation.start();
            return;
        }
        RadialProgressView radialProgressView2 = this.progressView;
        if (!z) {
            f = 0.0f;
        }
        radialProgressView2.setAlpha(f);
    }

    public static PlayerUtils getPlayer(Context context, WebPlayerViewDelegate webPlayerViewDelegate) {
        PlayerUtils playerUtils = mPlayer;
        if (playerUtils == null) {
            mPlayer = new PlayerUtils(context, true, false, webPlayerViewDelegate);
        } else {
            playerUtils.delegate = webPlayerViewDelegate;
        }
        return mPlayer;
    }

    public static PlayerUtils getPlayer() {
        return mPlayer;
    }
}