Ruiyuanjb v2.7.0版本的 MD5 值为:45f663f003665a0ca2d09dcbec30071a
以下内容为反编译后的 WebPlayerView.java 源代码,内容仅作参考
package im.mvtqiwsorf.ui.components;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
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.mvtqiwsorf.messenger.AndroidUtilities;
import im.mvtqiwsorf.messenger.ApplicationLoader;
import im.mvtqiwsorf.messenger.Bitmaps;
import im.mvtqiwsorf.messenger.BuildVars;
import im.mvtqiwsorf.messenger.FileLoader;
import im.mvtqiwsorf.messenger.FileLog;
import im.mvtqiwsorf.messenger.ImageLocation;
import im.mvtqiwsorf.messenger.ImageReceiver;
import im.mvtqiwsorf.messenger.R;
import im.mvtqiwsorf.messenger.Utilities;
import im.mvtqiwsorf.tgnet.TLRPC;
import im.mvtqiwsorf.ui.components.VideoPlayer;
import im.mvtqiwsorf.ui.components.WebPlayerView;
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.slf4j.Marker;
public class WebPlayerView 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 String exprName = "[a-zA-Z_$][a-zA-Z_$0-9]*";
private static int lastContainerId = 4001;
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 TextureView textureView;
private ViewGroup textureViewContainer;
private VideoPlayer videoPlayer;
private int waitingForFirstTextureUpload;
private WebView webView;
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 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 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 Pattern aparatIdRegex = Pattern.compile("^https?://(?:www\\.)?aparat\\.com/(?:v/|video/video/embed/videohash/)([a-zA-Z0-9]+)");
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 aparatFileListPattern = Pattern.compile("fileList\\s*=\\s*JSON\\.parse\\('([^']+)'\\)");
private static final Pattern twitchClipFilePattern = Pattern.compile("clipInfo\\s*=\\s*(\\{[^']+\\});");
private static final Pattern stsPattern = Pattern.compile("\"sts\"\\s*:\\s*(\\d+)");
private static final Pattern jsPattern = Pattern.compile("\"assets\":.+?\"js\":\\s*(\"[^\"]+\")");
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 stmtVarPattern = Pattern.compile("var\\s");
private static final Pattern stmtReturnPattern = Pattern.compile("return(?:\\s+|$)");
private static final Pattern exprParensPattern = Pattern.compile("[()]");
private static final Pattern playerIdPattern = Pattern.compile(".*?-([a-zA-Z0-9_-]+)(?:/watch_as3|/html5player(?:-new)?|(?:/[a-z]{2}_[A-Z]{2})?/base)?\\.([a-z]+)$");
public interface CallJavaResultInterface {
void jsCallFinished(String str);
}
public interface WebPlayerViewDelegate {
boolean checkInlinePermissions();
ViewGroup getTextureViewContainer();
void onInitFailed();
void onInlineSurfaceTextureReady();
void onPlayStateChanged(WebPlayerView webPlayerView, boolean z);
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() {
}
}
public class JSExtractor {
private String jsCode;
ArrayList<String> codeLines = new ArrayList<>();
private String[] operators = {LogUtils.VERTICAL, "^", "&", ">>", "<<", "-", Marker.ANY_NON_NULL_MARKER, "%", "/", "*"};
private String[] assign_operators = {"|=", "^=", "&=", ">>=", "<<=", "-=", "+=", "%=", "/=", "*=", "="};
public JSExtractor(String str) {
this.jsCode = str;
}
private void interpretExpression(String str, HashMap<String, String> hashMap, int i) throws Exception {
String trim = str.trim();
if (TextUtils.isEmpty(trim)) {
return;
}
if (trim.charAt(0) == '(') {
Matcher matcher = WebPlayerView.exprParensPattern.matcher(trim);
int i2 = 0;
while (true) {
if (!matcher.find()) {
break;
}
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(.*)$", WebPlayerView.exprName, Pattern.quote(strArr[i3]))).matcher(trim);
if (matcher2.find()) {
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;
}
}
i3++;
} else {
try {
Integer.parseInt(trim);
return;
} catch (Exception unused) {
if (Pattern.compile(String.format(Locale.US, "(?!if|return|true|false)(%s)$", WebPlayerView.exprName)).matcher(trim).find()) {
return;
}
if (trim.charAt(0) == '\"' && trim.charAt(trim.length() - 1) == '\"') {
return;
}
try {
new JSONObject(trim).toString();
return;
} catch (Exception unused2) {
Matcher matcher3 = Pattern.compile(String.format(Locale.US, "(%s)\\[(.+)\\]$", WebPlayerView.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*(?:\\(+([^()]*)\\))?$", WebPlayerView.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 ')'");
}
if (group5.length() != 0) {
for (String str2 : group5.split(",")) {
interpretExpression(str2, hashMap, i);
}
return;
}
return;
}
Matcher matcher5 = Pattern.compile(String.format(Locale.US, "(%s)\\[(.+)\\]$", WebPlayerView.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]) {
throw new Exception(String.format("Premature left-side return of %s in %s", str3, trim));
}
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));
}
}
i4++;
} else {
Matcher matcher7 = Pattern.compile(String.format(Locale.US, "^(%s)\\(([a-zA-Z0-9_$,]*)\\)$", WebPlayerView.exprName)).matcher(trim);
if (matcher7.find()) {
extractFunction(matcher7.group(1));
}
throw new Exception(String.format("Unsupported JS expression %s", trim));
}
}
}
}
}
}
}
private void interpretStatement(String str, HashMap<String, String> hashMap, boolean[] zArr, int i) throws Exception {
if (i < 0) {
throw new Exception("recursion limit reached");
}
zArr[0] = false;
String trim = str.trim();
Matcher matcher = WebPlayerView.stmtVarPattern.matcher(trim);
if (!matcher.find()) {
Matcher matcher2 = WebPlayerView.stmtReturnPattern.matcher(trim);
if (matcher2.find()) {
trim = trim.substring(matcher2.group(0).length());
zArr[0] = true;
}
} else {
trim = trim.substring(matcher.group(0).length());
}
interpretExpression(trim, hashMap, i);
}
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;
}
}
}
public 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)) {
this.codeLines.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 callJavaResultInterface) {
this.callJavaResultInterface = callJavaResultInterface;
}
@JavascriptInterface
public void returnResultToJava(String str) {
this.callJavaResultInterface.jsCallFinished(str);
}
}
protected String downloadUrlContent(AsyncTask asyncTask, String str) {
return downloadUrlContent(asyncTask, str, null, true);
}
protected String downloadUrlContent(AsyncTask asyncTask, String str, HashMap<String, String> hashMap, boolean z) {
URLConnection uRLConnection;
boolean z2;
InputStream inputStream;
StringBuilder sb;
boolean z3;
InputStream inputStream2;
boolean z4 = 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 th) {
th = th;
boolean z5 = !(th instanceof SocketTimeoutException) ? !(!(th instanceof UnknownHostException) && (!(th instanceof SocketException) ? (th instanceof FileNotFoundException) : !(th.getMessage() == null || !th.getMessage().contains("ECONNRESET")))) : ApplicationLoader.isNetworkOnline();
FileLog.e(th);
z2 = z5;
inputStream = null;
if (z2) {
}
if (z3) {
}
}
} catch (Throwable th2) {
th = th2;
uRLConnection = null;
}
if (z2) {
sb = null;
z3 = false;
} else {
try {
if (uRLConnection instanceof HttpURLConnection) {
if (((HttpURLConnection) uRLConnection).getResponseCode() != 200) {
}
}
} catch (Exception e) {
FileLog.e(e);
}
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 {
try {
sb.append(new String(bArr, 0, read, StandardCharsets.UTF_8));
} catch (Exception e2) {
e = e2;
FileLog.e(e);
z4 = false;
z3 = z4;
if (inputStream != null) {
}
if (z3) {
}
}
} catch (Throwable th3) {
th = th3;
FileLog.e(th);
z3 = false;
if (inputStream != null) {
}
if (z3) {
}
}
}
} catch (Exception e3) {
e = e3;
}
} catch (Throwable th4) {
th = th4;
}
}
z3 = z4;
} catch (Throwable th5) {
th = th5;
sb = null;
}
if (inputStream != null) {
try {
inputStream.close();
} catch (Throwable th6) {
FileLog.e(th6);
}
}
} else {
sb = null;
}
z3 = false;
if (inputStream != null) {
}
}
if (z3) {
return null;
}
return sb.toString();
}
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;
}
@Override
public String[] doInBackground(Void... voidArr) {
String str;
String str2;
boolean z;
boolean z2;
String str3;
String downloadUrlContent = WebPlayerView.this.downloadUrlContent(this, "https://www.youtube.com/embed/" + this.videoId);
String[] strArr = null;
if (!isCancelled()) {
String str4 = "video_id=" + this.videoId + "&ps=default&gl=US&hl=en";
try {
StringBuilder sb = new StringBuilder();
sb.append(str4);
sb.append("&eurl=");
sb.append(URLEncoder.encode("https://youtube.googleapis.com/v/" + this.videoId, "UTF-8"));
str4 = sb.toString();
} catch (Exception e) {
FileLog.e(e);
}
if (downloadUrlContent != null) {
Matcher matcher = WebPlayerView.stsPattern.matcher(downloadUrlContent);
if (matcher.find()) {
str4 = str4 + "&sts=" + downloadUrlContent.substring(matcher.start() + 6, matcher.end());
} else {
str4 = str4 + "&sts=";
}
}
char c = 1;
this.result[1] = DownloadAction.TYPE_DASH;
int i = 5;
String[] strArr2 = {"", "&el=leanback", "&el=embedded", "&el=detailpage", "&el=vevo"};
char c2 = 0;
String str5 = null;
boolean z3 = false;
int i2 = 0;
while (true) {
int i3 = 2;
if (i2 >= i) {
break;
}
String downloadUrlContent2 = WebPlayerView.this.downloadUrlContent(this, "https://www.youtube.com/get_video_info?" + str4 + strArr2[i2]);
if (isCancelled()) {
return strArr;
}
if (downloadUrlContent2 != null) {
String[] split = downloadUrlContent2.split("&");
Object obj = strArr;
String str6 = str5;
int i4 = 0;
z = false;
z2 = false;
boolean z4 = z3;
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 e2) {
FileLog.e(e2);
}
}
str3 = str4;
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 str7 = null;
int i5 = 0;
boolean z5 = false;
while (i5 < split4.length) {
String[] split5 = split4[i5].split("=");
String[] strArr3 = split4;
str3 = str4;
try {
if (split5[0].startsWith("type")) {
if (URLDecoder.decode(split5[1], "UTF-8").contains(MimeTypes.VIDEO_MP4)) {
z5 = true;
}
} else if (split5[0].startsWith(ImagesContract.URL)) {
str7 = URLDecoder.decode(split5[1], "UTF-8");
} else if (split5[0].startsWith("itag")) {
str7 = null;
z5 = false;
}
if (z5 && str7 != null) {
str6 = str7;
break;
}
i5++;
split4 = strArr3;
str4 = str3;
} catch (Exception e3) {
e = e3;
FileLog.e(e);
i4++;
str4 = str3;
c = 1;
c2 = 0;
i3 = 2;
}
}
} catch (Exception e4) {
e = e4;
str3 = str4;
}
}
str3 = str4;
} else {
str3 = str4;
if (split[i4].startsWith("use_cipher_signature")) {
String[] split6 = split[i4].split("=");
if (split6.length == 2 && split6[1].toLowerCase().equals("true")) {
z4 = 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 e5) {
FileLog.e(e5);
}
}
} else if (split[i4].startsWith("livestream")) {
String[] split8 = split[i4].split("=");
if (split8.length == 2 && split8[1].toLowerCase().equals("1")) {
z = true;
}
}
}
i4++;
str4 = str3;
c = 1;
c2 = 0;
i3 = 2;
}
str = str4;
z3 = z4;
str5 = str6;
str2 = obj;
} else {
str = str4;
str2 = 0;
z = false;
z2 = false;
}
if (z) {
if (str2 == 0 || z3 || str2.contains("/s/")) {
return null;
}
String[] strArr4 = this.result;
strArr4[0] = str2;
strArr4[1] = DownloadAction.TYPE_HLS;
}
if (z2) {
break;
}
i2++;
str4 = str;
strArr = null;
i = 5;
c = 1;
c2 = 0;
}
} else {
return null;
}
}
public void lambda$doInBackground$1$WebPlayerView$YoutubeVideoTask(String str) {
if (Build.VERSION.SDK_INT >= 21) {
WebPlayerView.this.webView.evaluateJavascript(str, new ValueCallback() {
@Override
public final void onReceiveValue(Object obj) {
WebPlayerView.YoutubeVideoTask.this.lambda$null$0$WebPlayerView$YoutubeVideoTask((String) obj);
}
});
return;
}
try {
String encodeToString = Base64.encodeToString(("<script>" + str + "</script>").getBytes(StandardCharsets.UTF_8), 0);
WebPlayerView.this.webView.loadUrl("data:text/html;charset=utf-8;base64," + encodeToString);
} catch (Exception e) {
FileLog.e(e);
}
}
public void lambda$null$0$WebPlayerView$YoutubeVideoTask(String str) {
String[] strArr = this.result;
strArr[0] = strArr[0].replace(this.sig, "/signature/" + str.substring(1, str.length() - 1));
this.countDownLatch.countDown();
}
public void onInterfaceResult(String str) {
String[] strArr = this.result;
strArr[0] = strArr[0].replace(this.sig, "/signature/" + str);
this.countDownLatch.countDown();
}
@Override
public void onPostExecute(String[] strArr) {
if (strArr[0] != null) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("start play youtube video " + strArr[1] + " " + strArr[0]);
}
WebPlayerView.this.initied = true;
WebPlayerView.this.playVideoUrl = strArr[0];
WebPlayerView.this.playVideoType = strArr[1];
if (WebPlayerView.this.playVideoType.equals(DownloadAction.TYPE_HLS)) {
WebPlayerView.this.isStream = true;
}
if (WebPlayerView.this.isAutoplay) {
WebPlayerView.this.preparePlayer();
}
WebPlayerView.this.showProgress(false, true);
WebPlayerView.this.controlsView.show(true, true);
return;
}
if (isCancelled()) {
return;
}
WebPlayerView.this.onInitFailed();
}
}
public 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;
}
@Override
public String doInBackground(Void... voidArr) {
String downloadUrlContent = WebPlayerView.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];
}
@Override
public void onPostExecute(String str) {
if (str != null) {
WebPlayerView.this.initied = true;
WebPlayerView.this.playVideoUrl = str;
WebPlayerView.this.playVideoType = this.results[1];
if (WebPlayerView.this.isAutoplay) {
WebPlayerView.this.preparePlayer();
}
WebPlayerView.this.showProgress(false, true);
WebPlayerView.this.controlsView.show(true, true);
return;
}
if (isCancelled()) {
return;
}
WebPlayerView.this.onInitFailed();
}
}
public 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;
}
@Override
public String doInBackground(Void... voidArr) {
String downloadUrlContent = WebPlayerView.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 = WebPlayerView.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];
}
@Override
public void onPostExecute(String str) {
if (str != null) {
WebPlayerView.this.initied = true;
WebPlayerView.this.playVideoUrl = str;
WebPlayerView.this.playVideoType = this.results[1];
if (WebPlayerView.this.isAutoplay) {
WebPlayerView.this.preparePlayer();
}
WebPlayerView.this.showProgress(false, true);
WebPlayerView.this.controlsView.show(true, true);
return;
}
if (isCancelled()) {
return;
}
WebPlayerView.this.onInitFailed();
}
}
public class TwitchClipVideoTask extends AsyncTask<Void, Void, String> {
private String currentUrl;
private String videoId;
private boolean canRetry = true;
private String[] results = new String[2];
public TwitchClipVideoTask(String str, String str2) {
this.videoId = str2;
this.currentUrl = str;
}
@Override
public String doInBackground(Void... voidArr) {
String downloadUrlContent = WebPlayerView.this.downloadUrlContent(this, this.currentUrl, null, false);
if (isCancelled()) {
return null;
}
try {
Matcher matcher = WebPlayerView.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];
}
@Override
public void onPostExecute(String str) {
if (str != null) {
WebPlayerView.this.initied = true;
WebPlayerView.this.playVideoUrl = str;
WebPlayerView.this.playVideoType = this.results[1];
if (WebPlayerView.this.isAutoplay) {
WebPlayerView.this.preparePlayer();
}
WebPlayerView.this.showProgress(false, true);
WebPlayerView.this.controlsView.show(true, true);
return;
}
if (isCancelled()) {
return;
}
WebPlayerView.this.onInitFailed();
}
}
public class TwitchStreamVideoTask extends AsyncTask<Void, Void, String> {
private String currentUrl;
private String videoId;
private boolean canRetry = true;
private String[] results = new String[2];
public TwitchStreamVideoTask(String str, String str2) {
this.videoId = str2;
this.currentUrl = str;
}
@Override
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 = WebPlayerView.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(WebPlayerView.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];
}
@Override
public void onPostExecute(String str) {
if (str != null) {
WebPlayerView.this.initied = true;
WebPlayerView.this.playVideoUrl = str;
WebPlayerView.this.playVideoType = this.results[1];
if (WebPlayerView.this.isAutoplay) {
WebPlayerView.this.preparePlayer();
}
WebPlayerView.this.showProgress(false, true);
WebPlayerView.this.controlsView.show(true, true);
return;
}
if (isCancelled()) {
return;
}
WebPlayerView.this.onInitFailed();
}
}
public 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;
}
}
@Override
public String doInBackground(Void... voidArr) {
String downloadUrlContent = WebPlayerView.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];
}
@Override
public void onPostExecute(String str) {
if (str != null) {
WebPlayerView.this.initied = true;
WebPlayerView.this.playVideoUrl = str;
WebPlayerView.this.playVideoType = this.results[1];
WebPlayerView.this.playAudioUrl = this.results[2];
WebPlayerView.this.playAudioType = this.results[3];
if (WebPlayerView.this.isAutoplay) {
WebPlayerView.this.preparePlayer();
}
WebPlayerView.this.showProgress(false, true);
WebPlayerView.this.controlsView.show(true, true);
return;
}
if (isCancelled()) {
return;
}
WebPlayerView.this.onInitFailed();
}
}
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;
private ImageReceiver imageReceiver;
private boolean isVisible;
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 void lambda$new$0$WebPlayerView$ControlsView() {
show(false, true);
}
public ControlsView(Context context) {
super(context);
this.isVisible = true;
this.hideRunnable = new Runnable() {
@Override
public final void run() {
WebPlayerView.ControlsView.this.lambda$new$0$WebPlayerView$ControlsView();
}
};
setWillNotDraw(false);
TextPaint textPaint = new TextPaint(1);
this.textPaint = textPaint;
textPaint.setColor(-1);
this.textPaint.setTextSize(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 || WebPlayerView.this.isStream) {
return;
}
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(this.durationLayout.getLineWidth(0));
}
invalidate();
}
public void setBufferedProgress(int i) {
this.bufferedPosition = i;
invalidate();
}
public void setProgress(int i) {
if (this.progressPressed || i < 0 || WebPlayerView.this.isStream) {
return;
}
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) {
return;
}
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() {
@Override
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() {
@Override
public void onAnimationEnd(Animator animator) {
ControlsView.this.currentAnimation = null;
}
});
this.currentAnimation.start();
} else {
setAlpha(0.0f);
}
checkNeedHide();
}
public void checkNeedHide() {
AndroidUtilities.cancelRunOnUIThread(this.hideRunnable);
if (this.isVisible && WebPlayerView.this.videoPlayer.isPlaying()) {
AndroidUtilities.runOnUIThread(this.hideRunnable, 3000L);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
if (motionEvent.getAction() == 0) {
if (!this.isVisible) {
show(true, true);
return true;
}
onTouchEvent(motionEvent);
return this.progressPressed;
}
return super.onInterceptTouchEvent(motionEvent);
}
@Override
public void requestDisallowInterceptTouchEvent(boolean z) {
super.requestDisallowInterceptTouchEvent(z);
checkNeedHide();
}
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
int measuredWidth;
int measuredHeight;
int i;
if (WebPlayerView.this.inFullscreen) {
i = AndroidUtilities.dp(36.0f) + this.durationWidth;
measuredWidth = (getMeasuredWidth() - AndroidUtilities.dp(76.0f)) - this.durationWidth;
measuredHeight = getMeasuredHeight() - AndroidUtilities.dp(28.0f);
} else {
measuredWidth = getMeasuredWidth();
measuredHeight = getMeasuredHeight() - AndroidUtilities.dp(12.0f);
i = 0;
}
int i2 = this.duration;
int i3 = (i2 != 0 ? (int) ((measuredWidth - i) * (this.progress / i2)) : 0) + i;
if (motionEvent.getAction() == 0) {
if (this.isVisible && !WebPlayerView.this.isInline && !WebPlayerView.this.isStream) {
if (this.duration != 0) {
int x = (int) motionEvent.getX();
int y = (int) motionEvent.getY();
if (x >= i3 - AndroidUtilities.dp(10.0f) && x <= AndroidUtilities.dp(10.0f) + i3 && y >= measuredHeight - AndroidUtilities.dp(10.0f) && y <= measuredHeight + AndroidUtilities.dp(10.0f)) {
this.progressPressed = true;
this.lastProgressX = x;
this.currentProgressX = i3;
getParent().requestDisallowInterceptTouchEvent(true);
invalidate();
}
}
} else {
show(true, true);
}
AndroidUtilities.cancelRunOnUIThread(this.hideRunnable);
} else if (motionEvent.getAction() == 1 || motionEvent.getAction() == 3) {
if (WebPlayerView.this.initied && WebPlayerView.this.videoPlayer.isPlaying()) {
AndroidUtilities.runOnUIThread(this.hideRunnable, 3000L);
}
if (this.progressPressed) {
this.progressPressed = false;
if (WebPlayerView.this.initied) {
this.progress = (int) (this.duration * ((this.currentProgressX - i) / (measuredWidth - i)));
WebPlayerView.this.videoPlayer.seekTo(this.progress * 1000);
}
}
} else if (motionEvent.getAction() == 2 && this.progressPressed) {
int x2 = (int) motionEvent.getX();
int i4 = this.currentProgressX - (this.lastProgressX - x2);
this.currentProgressX = i4;
this.lastProgressX = x2;
if (i4 < i) {
this.currentProgressX = i;
} else if (i4 > measuredWidth) {
this.currentProgressX = measuredWidth;
}
setProgress((int) (this.duration * 1000 * ((this.currentProgressX - i) / (measuredWidth - i))));
invalidate();
}
super.onTouchEvent(motionEvent);
return true;
}
@Override
protected void onDraw(Canvas canvas) {
int dp;
int dp2;
int dp3;
int dp4;
int i;
int i2;
int i3;
int i4;
int i5;
if (WebPlayerView.this.drawImage) {
if (WebPlayerView.this.firstFrameRendered && WebPlayerView.this.currentAlpha != 0.0f) {
long currentTimeMillis = System.currentTimeMillis();
long j = currentTimeMillis - WebPlayerView.this.lastUpdateTime;
WebPlayerView.this.lastUpdateTime = currentTimeMillis;
WebPlayerView.this.currentAlpha -= ((float) j) / 150.0f;
if (WebPlayerView.this.currentAlpha < 0.0f) {
WebPlayerView.this.currentAlpha = 0.0f;
}
invalidate();
}
this.imageReceiver.setAlpha(WebPlayerView.this.currentAlpha);
this.imageReceiver.draw(canvas);
}
if (!WebPlayerView.this.videoPlayer.isPlayerPrepared() || WebPlayerView.this.isStream) {
return;
}
int measuredWidth = getMeasuredWidth();
int measuredHeight = getMeasuredHeight();
if (!WebPlayerView.this.isInline) {
if (this.durationLayout != null) {
canvas.save();
canvas.translate((measuredWidth - AndroidUtilities.dp(58.0f)) - this.durationWidth, measuredHeight - AndroidUtilities.dp((WebPlayerView.this.inFullscreen ? 6 : 10) + 29));
this.durationLayout.draw(canvas);
canvas.restore();
}
if (this.progressLayout != null) {
canvas.save();
canvas.translate(AndroidUtilities.dp(18.0f), measuredHeight - AndroidUtilities.dp((WebPlayerView.this.inFullscreen ? 6 : 10) + 29));
this.progressLayout.draw(canvas);
canvas.restore();
}
}
if (this.duration == 0) {
return;
}
if (!WebPlayerView.this.isInline) {
if (WebPlayerView.this.inFullscreen) {
int dp5 = measuredHeight - AndroidUtilities.dp(29.0f);
int dp6 = AndroidUtilities.dp(36.0f) + this.durationWidth;
dp3 = (measuredWidth - AndroidUtilities.dp(76.0f)) - this.durationWidth;
dp4 = measuredHeight - AndroidUtilities.dp(28.0f);
i = dp5;
i2 = dp6;
if (WebPlayerView.this.inFullscreen) {
canvas.drawRect(i2, i, dp3, AndroidUtilities.dp(3.0f) + i, this.progressInnerPaint);
}
if (!this.progressPressed) {
i3 = this.currentProgressX;
} else {
i3 = ((int) ((dp3 - i2) * (this.progress / this.duration))) + i2;
}
int i6 = i3;
i4 = this.bufferedPosition;
if (i4 != 0 && (i5 = this.duration) != 0) {
float f = i2;
canvas.drawRect(f, i, ((dp3 - i2) * (i4 / i5)) + f, AndroidUtilities.dp(3.0f) + i, !WebPlayerView.this.inFullscreen ? this.progressBufferedPaint : this.progressInnerPaint);
}
float f2 = i6;
canvas.drawRect(i2, i, f2, i + AndroidUtilities.dp(3.0f), this.progressPaint);
if (WebPlayerView.this.isInline) {
canvas.drawCircle(f2, dp4, AndroidUtilities.dp(this.progressPressed ? 7.0f : 5.0f), this.progressPaint);
return;
}
return;
}
dp = measuredHeight - AndroidUtilities.dp(13.0f);
dp2 = AndroidUtilities.dp(12.0f);
} else {
dp = measuredHeight - AndroidUtilities.dp(3.0f);
dp2 = AndroidUtilities.dp(7.0f);
}
dp3 = measuredWidth;
dp4 = measuredHeight - dp2;
i = dp;
i2 = 0;
if (WebPlayerView.this.inFullscreen) {
}
if (!this.progressPressed) {
}
int i62 = i3;
i4 = this.bufferedPosition;
if (i4 != 0) {
float f3 = i2;
canvas.drawRect(f3, i, ((dp3 - i2) * (i4 / i5)) + f3, AndroidUtilities.dp(3.0f) + i, !WebPlayerView.this.inFullscreen ? this.progressBufferedPaint : this.progressInnerPaint);
}
float f22 = i62;
canvas.drawRect(i2, i, f22, i + AndroidUtilities.dp(3.0f), this.progressPaint);
if (WebPlayerView.this.isInline) {
}
}
}
public WebPlayerView(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() {
@Override
public void run() {
if (WebPlayerView.this.videoPlayer == null || !WebPlayerView.this.videoPlayer.isPlaying()) {
return;
}
WebPlayerView.this.controlsView.setProgress((int) (WebPlayerView.this.videoPlayer.getCurrentPosition() / 1000));
WebPlayerView.this.controlsView.setBufferedProgress((int) (WebPlayerView.this.videoPlayer.getBufferedPosition() / 1000));
AndroidUtilities.runOnUIThread(WebPlayerView.this.progressRunnable, 1000L);
}
};
this.surfaceTextureListener = new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i2, int i3) {
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i2, int i3) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
if (!WebPlayerView.this.changingTextureView) {
return true;
}
if (WebPlayerView.this.switchingInlineMode) {
WebPlayerView.this.waitingForFirstTextureUpload = 2;
}
WebPlayerView.this.textureView.setSurfaceTexture(surfaceTexture);
WebPlayerView.this.textureView.setVisibility(0);
WebPlayerView.this.changingTextureView = false;
return false;
}
public class AnonymousClass1 implements ViewTreeObserver.OnPreDrawListener {
AnonymousClass1() {
}
@Override
public boolean onPreDraw() {
WebPlayerView.this.changedTextureView.getViewTreeObserver().removeOnPreDrawListener(this);
if (WebPlayerView.this.textureImageView != null) {
WebPlayerView.this.textureImageView.setVisibility(4);
WebPlayerView.this.textureImageView.setImageDrawable(null);
if (WebPlayerView.this.currentBitmap != null) {
WebPlayerView.this.currentBitmap.recycle();
WebPlayerView.this.currentBitmap = null;
}
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
WebPlayerView.AnonymousClass2.AnonymousClass1.this.lambda$onPreDraw$0$WebPlayerView$2$1();
}
});
WebPlayerView.this.waitingForFirstTextureUpload = 0;
return true;
}
public void lambda$onPreDraw$0$WebPlayerView$2$1() {
WebPlayerView.this.delegate.onInlineSurfaceTextureReady();
}
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
if (WebPlayerView.this.waitingForFirstTextureUpload == 1) {
WebPlayerView.this.changedTextureView.getViewTreeObserver().addOnPreDrawListener(new AnonymousClass1());
WebPlayerView.this.changedTextureView.invalidate();
}
}
};
this.switchToInlineRunnable = new Runnable() {
@Override
public void run() {
WebPlayerView.this.switchingInlineMode = false;
if (WebPlayerView.this.currentBitmap != null) {
WebPlayerView.this.currentBitmap.recycle();
WebPlayerView.this.currentBitmap = null;
}
WebPlayerView.this.changingTextureView = true;
if (WebPlayerView.this.textureImageView != null) {
try {
WebPlayerView.this.currentBitmap = Bitmaps.createBitmap(WebPlayerView.this.textureView.getWidth(), WebPlayerView.this.textureView.getHeight(), Bitmap.Config.ARGB_8888);
WebPlayerView.this.textureView.getBitmap(WebPlayerView.this.currentBitmap);
} catch (Throwable th) {
if (WebPlayerView.this.currentBitmap != null) {
WebPlayerView.this.currentBitmap.recycle();
WebPlayerView.this.currentBitmap = null;
}
FileLog.e(th);
}
if (WebPlayerView.this.currentBitmap != null) {
WebPlayerView.this.textureImageView.setVisibility(0);
WebPlayerView.this.textureImageView.setImageBitmap(WebPlayerView.this.currentBitmap);
} else {
WebPlayerView.this.textureImageView.setImageDrawable(null);
}
}
WebPlayerView.this.isInline = true;
WebPlayerView.this.updatePlayButton();
WebPlayerView.this.updateShareButton();
WebPlayerView.this.updateFullscreenButton();
WebPlayerView.this.updateInlineButton();
ViewGroup viewGroup = (ViewGroup) WebPlayerView.this.controlsView.getParent();
if (viewGroup != null) {
viewGroup.removeView(WebPlayerView.this.controlsView);
}
WebPlayerView webPlayerView = WebPlayerView.this;
webPlayerView.changedTextureView = webPlayerView.delegate.onSwitchInlineMode(WebPlayerView.this.controlsView, WebPlayerView.this.isInline, WebPlayerView.this.aspectRatioFrameLayout.getAspectRatio(), WebPlayerView.this.aspectRatioFrameLayout.getVideoRotation(), WebPlayerView.this.allowInlineAnimation);
WebPlayerView.this.changedTextureView.setVisibility(4);
ViewGroup viewGroup2 = (ViewGroup) WebPlayerView.this.textureView.getParent();
if (viewGroup2 != null) {
viewGroup2.removeView(WebPlayerView.this.textureView);
}
WebPlayerView.this.controlsView.show(false, false);
}
};
setWillNotDraw(false);
this.delegate = webPlayerViewDelegate;
this.backgroundPaint.setColor(-16777216);
AspectRatioFrameLayout aspectRatioFrameLayout = new AspectRatioFrameLayout(context) {
@Override
public void onMeasure(int i2, int i3) {
super.onMeasure(i2, i3);
if (WebPlayerView.this.textureViewContainer != null) {
ViewGroup.LayoutParams layoutParams = WebPlayerView.this.textureView.getLayoutParams();
layoutParams.width = getMeasuredWidth();
layoutParams.height = getMeasuredHeight();
if (WebPlayerView.this.textureImageView != null) {
ViewGroup.LayoutParams layoutParams2 = WebPlayerView.this.textureImageView.getLayoutParams();
layoutParams2.width = getMeasuredWidth();
layoutParams2.height = getMeasuredHeight();
}
}
}
};
this.aspectRatioFrameLayout = aspectRatioFrameLayout;
addView(aspectRatioFrameLayout, LayoutHelper.createFrame(-1, -1, 17));
this.interfaceName = "JavaScriptInterface";
WebView webView = new WebView(context);
this.webView = webView;
webView.addJavascriptInterface(new JavaScriptInterface(new CallJavaResultInterface() {
@Override
public final void jsCallFinished(String str) {
WebPlayerView.this.lambda$new$0$WebPlayerView(str);
}
}), this.interfaceName);
WebSettings settings = this.webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDefaultTextEncodingName("utf-8");
this.textureViewContainer = this.delegate.getTextureViewContainer();
TextureView textureView = new TextureView(context);
this.textureView = textureView;
textureView.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 videoPlayer = new VideoPlayer();
this.videoPlayer = videoPlayer;
videoPlayer.setDelegate(this);
this.videoPlayer.setTextureView(this.textureView);
ControlsView controlsView = new ControlsView(context);
this.controlsView = controlsView;
ViewGroup viewGroup2 = this.textureViewContainer;
if (viewGroup2 != null) {
viewGroup2.addView(controlsView);
} else {
addView(controlsView, 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() {
@Override
public final void onClick(View view) {
WebPlayerView.this.lambda$new$1$WebPlayerView(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() {
@Override
public final void onClick(View view) {
WebPlayerView.this.lambda$new$2$WebPlayerView(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() {
@Override
public final void onClick(View view) {
WebPlayerView.this.lambda$new$3$WebPlayerView(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() {
@Override
public final void onClick(View view) {
WebPlayerView.this.lambda$new$4$WebPlayerView(view);
}
});
}
updatePlayButton();
updateFullscreenButton();
updateInlineButton();
updateShareButton();
}
public void lambda$new$0$WebPlayerView(String str) {
AsyncTask asyncTask = this.currentTask;
if (asyncTask == null || asyncTask.isCancelled()) {
return;
}
AsyncTask asyncTask2 = this.currentTask;
if (asyncTask2 instanceof YoutubeVideoTask) {
((YoutubeVideoTask) asyncTask2).onInterfaceResult(str);
}
}
public void lambda$new$1$WebPlayerView(View view) {
if (!this.initied || this.changingTextureView || this.switchingInlineMode || !this.firstFrameRendered) {
return;
}
this.inFullscreen = !this.inFullscreen;
updateFullscreenState(true);
}
public void lambda$new$2$WebPlayerView(View view) {
if (!this.initied || this.playVideoUrl == null) {
return;
}
if (!this.videoPlayer.isPlayerPrepared()) {
preparePlayer();
}
if (this.videoPlayer.isPlaying()) {
this.videoPlayer.pause();
} else {
this.isCompleted = false;
this.videoPlayer.play();
}
updatePlayButton();
}
public void lambda$new$3$WebPlayerView(View view) {
if (this.textureView == null || !this.delegate.checkInlinePermissions() || this.changingTextureView || this.switchingInlineMode || !this.firstFrameRendered) {
return;
}
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 void lambda$new$4$WebPlayerView(View view) {
WebPlayerViewDelegate webPlayerViewDelegate = this.delegate;
if (webPlayerViewDelegate != null) {
webPlayerViewDelegate.onSharePressed();
}
}
public void onInitFailed() {
if (this.controlsView.getParent() != this) {
this.controlsView.setVisibility(8);
}
this.delegate.onInitFailed();
}
public void updateTextureImageView() {
if (this.textureImageView == null) {
return;
}
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);
} else {
this.textureImageView.setImageDrawable(null);
}
}
public String getYoutubeId() {
return this.currentYoutubeId;
}
@Override
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 != 4 && i != 1 && this.videoPlayer.isPlaying()) {
this.delegate.onPlayStateChanged(this, true);
} else {
this.delegate.onPlayStateChanged(this, false);
}
if (this.videoPlayer.isPlaying() && i != 4) {
updatePlayButton();
return;
}
if (i == 4) {
this.isCompleted = true;
this.videoPlayer.pause();
this.videoPlayer.seekTo(0L);
updatePlayButton();
this.controlsView.show(true, true);
}
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawRect(0.0f, 0.0f, getMeasuredWidth(), getMeasuredHeight() - AndroidUtilities.dp(10.0f), this.backgroundPaint);
}
@Override
public void onError(Exception exc) {
FileLog.e(exc);
onInitFailed();
}
@Override
public void onVideoSizeChanged(int i, int i2, int i3, float f) {
if (this.aspectRatioFrameLayout != null) {
if (i3 != 90 && i3 != 270) {
i2 = i;
i = i2;
}
float f2 = i == 0 ? 1.0f : (i2 * f) / i;
this.aspectRatioFrameLayout.setAspectRatio(f2, i3);
if (this.inFullscreen) {
this.delegate.onVideoSizeChanged(f2, i3);
}
}
}
@Override
public void onRenderedFirstFrame() {
this.firstFrameRendered = true;
this.lastUpdateTime = System.currentTimeMillis();
this.controlsView.invalidate();
}
@Override
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
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;
}
}
@Override
protected 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 aspectRatioFrameLayout = this.aspectRatioFrameLayout;
aspectRatioFrameLayout.layout(measuredWidth, dp, aspectRatioFrameLayout.getMeasuredWidth() + measuredWidth, this.aspectRatioFrameLayout.getMeasuredHeight() + dp);
if (this.controlsView.getParent() == this) {
ControlsView controlsView = this.controlsView;
controlsView.layout(0, 0, controlsView.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));
}
@Override
protected 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);
}
public void updatePlayButton() {
this.controlsView.checkNeedHide();
AndroidUtilities.cancelRunOnUIThread(this.progressRunnable);
if (!this.videoPlayer.isPlaying()) {
if (this.isCompleted) {
this.playButton.setImageResource(this.isInline ? R.drawable.ic_againinline : R.drawable.ic_again);
return;
} else {
this.playButton.setImageResource(this.isInline ? R.drawable.ic_playinline : R.drawable.ic_play);
return;
}
}
this.playButton.setImageResource(this.isInline ? R.drawable.ic_pauseinline : R.drawable.ic_pause);
AndroidUtilities.runOnUIThread(this.progressRunnable, 500L);
checkAudioFocus();
}
private void checkAudioFocus() {
if (this.hasAudioFocus) {
return;
}
AudioManager audioManager = (AudioManager) ApplicationLoader.applicationContext.getSystemService(MimeTypes.BASE_TYPE_AUDIO);
this.hasAudioFocus = true;
if (audioManager.requestAudioFocus(this, 3, 1) == 1) {
this.audioFocus = 2;
}
}
@Override
public void onAudioFocusChange(int i) {
if (i == -1) {
if (this.videoPlayer.isPlaying()) {
this.videoPlayer.pause();
updatePlayButton();
}
this.hasAudioFocus = false;
this.audioFocus = 0;
return;
}
if (i == 1) {
this.audioFocus = 2;
if (this.resumeAudioOnFocusGain) {
this.resumeAudioOnFocusGain = false;
this.videoPlayer.play();
return;
}
return;
}
if (i == -3) {
this.audioFocus = 1;
return;
}
if (i == -2) {
this.audioFocus = 0;
if (this.videoPlayer.isPlaying()) {
this.resumeAudioOnFocusGain = true;
this.videoPlayer.pause();
updatePlayButton();
}
}
}
public 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));
} else {
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));
}
}
public void updateShareButton() {
ImageView imageView = this.shareButton;
if (imageView == null) {
return;
}
imageView.setVisibility((this.isInline || !this.videoPlayer.isPlayerPrepared()) ? 8 : 0);
}
private View getControlView() {
return this.controlsView;
}
private View getProgressView() {
return this.progressView;
}
public void updateInlineButton() {
ImageView imageView = this.inlineButton;
if (imageView == null) {
return;
}
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));
}
}
public void preparePlayer() {
String str = this.playVideoUrl;
if (str == null) {
return;
}
if (str != null && this.playAudioUrl != null) {
this.videoPlayer.preparePlayerLoop(Uri.parse(str), this.playVideoType, Uri.parse(this.playAudioUrl), this.playAudioType);
} else {
this.videoPlayer.preparePlayer(Uri.parse(this.playVideoUrl), this.playVideoType);
}
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();
if (this.seekToTime != -1) {
this.videoPlayer.seekTo(r0 * 1000);
}
}
public void pause() {
this.videoPlayer.pause();
updatePlayButton();
this.controlsView.show(true, true);
}
private void updateFullscreenState(boolean z) {
ViewGroup viewGroup;
if (this.textureView == null) {
return;
}
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) {
ViewGroup viewGroup6 = (ViewGroup) this.aspectRatioFrameLayout.getParent();
if (viewGroup6 != null) {
viewGroup6.removeView(this.aspectRatioFrameLayout);
}
} else {
ViewGroup viewGroup7 = (ViewGroup) this.aspectRatioFrameLayout.getParent();
if (viewGroup7 != this) {
if (viewGroup7 != null) {
viewGroup7.removeView(this.aspectRatioFrameLayout);
}
addView(this.aspectRatioFrameLayout, 0);
}
}
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) {
return;
}
this.inFullscreen = true;
updateInlineButton();
updateFullscreenState(false);
}
public boolean isInFullscreen() {
return this.inFullscreen;
}
public String getYouTubeVideoId(String str) {
Matcher matcher = youtubeIdRegex.matcher(str);
if (matcher.find()) {
return matcher.group(1);
}
return null;
}
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) {
str3 = null;
str4 = null;
str5 = null;
str6 = null;
str7 = null;
str8 = null;
str9 = null;
} else if (str.endsWith(".mp4")) {
str9 = str;
str3 = null;
str4 = null;
str5 = null;
str6 = null;
str7 = null;
str8 = null;
} else {
try {
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) {
FileLog.e(e);
}
}
Matcher matcher = youtubeIdRegex.matcher(str);
String group = matcher.find() ? matcher.group(1) : null;
if (group == null) {
group = null;
}
str4 = group;
} catch (Exception e2) {
FileLog.e(e2);
str4 = null;
}
if (str4 == null) {
try {
Matcher matcher2 = vimeoIdRegex.matcher(str);
String group2 = matcher2.find() ? matcher2.group(3) : null;
if (group2 == null) {
group2 = null;
}
str5 = group2;
} catch (Exception e3) {
FileLog.e(e3);
}
if (str5 == 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;
}
str7 = group4;
} catch (Exception e5) {
FileLog.e(e5);
}
if (str7 == null) {
try {
Matcher matcher5 = twitchStreamIdRegex.matcher(str);
String group5 = matcher5.find() ? matcher5.group(1) : null;
if (group5 == null) {
group5 = null;
}
str8 = group5;
} catch (Exception e6) {
FileLog.e(e6);
}
if (str8 == null) {
try {
Matcher matcher6 = coubIdRegex.matcher(str);
str3 = matcher6.find() ? matcher6.group(1) : null;
if (str3 == null) {
str3 = null;
}
str9 = null;
} catch (Exception e7) {
FileLog.e(e7);
}
}
str3 = null;
str9 = null;
}
str8 = null;
if (str8 == null) {
}
str3 = null;
str9 = null;
}
str7 = null;
if (str7 == null) {
}
str8 = null;
if (str8 == null) {
}
str3 = null;
str9 = null;
}
str6 = null;
if (str6 == null) {
}
str7 = null;
if (str7 == null) {
}
str8 = null;
if (str8 == null) {
}
str3 = null;
str9 = null;
}
str5 = null;
if (str5 == null) {
}
str6 = null;
if (str6 == null) {
}
str7 = null;
if (str7 == null) {
}
str8 = null;
if (str8 == null) {
}
str3 = null;
str9 = 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 (str4 != null) {
this.currentYoutubeId = str4;
str4 = null;
}
if (str9 != null) {
this.initied = true;
this.playVideoUrl = str9;
this.playVideoType = "other";
if (this.isAutoplay) {
preparePlayer();
}
showProgress(false, false);
this.controlsView.show(true, true);
} else {
if (str4 != null) {
YoutubeVideoTask youtubeVideoTask = new YoutubeVideoTask(str4);
youtubeVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentTask = youtubeVideoTask;
} else if (str5 != null) {
VimeoVideoTask vimeoVideoTask = new VimeoVideoTask(str5);
vimeoVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentTask = vimeoVideoTask;
} else if (str3 != null) {
CoubVideoTask coubVideoTask = new CoubVideoTask(str3);
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 (str7 != null) {
TwitchClipVideoTask twitchClipVideoTask = new TwitchClipVideoTask(str, str7);
twitchClipVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentTask = twitchClipVideoTask;
} else if (str8 != null) {
TwitchStreamVideoTask twitchStreamVideoTask = new TwitchStreamVideoTask(str, str8);
twitchStreamVideoTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null, null, null);
this.currentTask = twitchStreamVideoTask;
this.isStream = true;
}
this.controlsView.show(false, false);
showProgress(true, false);
}
if (str4 != null || str5 != null || str3 != null || str6 != null || str9 != null || str7 != null || str8 != null) {
this.controlsView.setVisibility(0);
return true;
}
this.controlsView.setVisibility(8);
return false;
}
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();
}
public void showProgress(boolean z, boolean z2) {
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];
fArr[0] = z ? 1.0f : 0.0f;
animatorArr[0] = ObjectAnimator.ofFloat(radialProgressView, "alpha", fArr);
animatorSet2.playTogether(animatorArr);
this.progressAnimation.setDuration(150L);
this.progressAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
WebPlayerView.this.progressAnimation = null;
}
});
this.progressAnimation.start();
return;
}
this.progressView.setAlpha(z ? 1.0f : 0.0f);
}
}