AdGuard v3.6.45版本的 MD5 值为:ce30a13dcef92cf942973fffcc6d20fb
以下内容为反编译后的 WebViewYouTubePlayer.java 源代码,内容仅作参考
package com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import ch.qos.logback.core.CoreConstants;
import com.pierfrancescosoffritti.androidyoutubeplayer.R;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.b;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.b.a;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import kotlin.b.b.j;
import kotlin.r;
public final class WebViewYouTubePlayer extends WebView implements com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a, b.InterfaceC0075b {
private boolean isBackgroundPlaybackEnabled;
private final Handler mainThreadHandler;
private kotlin.b.a.b<? super com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a, r> youTubePlayerInitListener;
private final HashSet<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a.d> youTubePlayerListeners;
static final class a implements Runnable {
final String b;
final float c;
a(String str, float f) {
this.b = str;
this.c = f;
}
@Override
public final void run() {
WebViewYouTubePlayer webViewYouTubePlayer = WebViewYouTubePlayer.this;
webViewYouTubePlayer.loadUrl("javascript:cueVideo('" + this.b + "', " + this.c + CoreConstants.RIGHT_PARENTHESIS_CHAR);
}
}
public static final class b extends WebChromeClient {
b() {
}
@Override
public final Bitmap getDefaultVideoPoster() {
Bitmap defaultVideoPoster = super.getDefaultVideoPoster();
return defaultVideoPoster == null ? Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565) : defaultVideoPoster;
}
}
static final class c implements Runnable {
final String b;
final float c;
c(String str, float f) {
this.b = str;
this.c = f;
}
@Override
public final void run() {
WebViewYouTubePlayer webViewYouTubePlayer = WebViewYouTubePlayer.this;
webViewYouTubePlayer.loadUrl("javascript:loadVideo('" + this.b + "', " + this.c + CoreConstants.RIGHT_PARENTHESIS_CHAR);
}
}
static final class d implements Runnable {
d() {
}
@Override
public final void run() {
WebViewYouTubePlayer.this.loadUrl("javascript:mute()");
}
}
static final class e implements Runnable {
e() {
}
@Override
public final void run() {
WebViewYouTubePlayer.this.loadUrl("javascript:pauseVideo()");
}
}
static final class f implements Runnable {
f() {
}
@Override
public final void run() {
WebViewYouTubePlayer.this.loadUrl("javascript:playVideo()");
}
}
static final class g implements Runnable {
final float b;
g(float f) {
this.b = f;
}
@Override
public final void run() {
WebViewYouTubePlayer webViewYouTubePlayer = WebViewYouTubePlayer.this;
webViewYouTubePlayer.loadUrl("javascript:seekTo(" + this.b + CoreConstants.RIGHT_PARENTHESIS_CHAR);
}
}
static final class h implements Runnable {
final int b;
h(int i) {
this.b = i;
}
@Override
public final void run() {
WebViewYouTubePlayer webViewYouTubePlayer = WebViewYouTubePlayer.this;
webViewYouTubePlayer.loadUrl("javascript:setVolume(" + this.b + CoreConstants.RIGHT_PARENTHESIS_CHAR);
}
}
static final class i implements Runnable {
i() {
}
@Override
public final void run() {
WebViewYouTubePlayer.this.loadUrl("javascript:unMute()");
}
}
public WebViewYouTubePlayer(Context context, AttributeSet attributeSet, int i2) {
super(context, attributeSet, i2);
j.b(context, CoreConstants.CONTEXT_SCOPE_VALUE);
this.youTubePlayerListeners = new HashSet<>();
this.mainThreadHandler = new Handler(Looper.getMainLooper());
}
public WebViewYouTubePlayer(Context context, AttributeSet attributeSet, int i2, int i3, kotlin.b.b.f fVar) {
this(context, (i3 & 2) != 0 ? null : attributeSet, (i3 & 4) != 0 ? 0 : i2);
}
private final void initWebView(com.pierfrancescosoffritti.androidyoutubeplayer.core.player.b.a aVar) {
WebSettings settings = getSettings();
j.a((Object) settings, "settings");
settings.setJavaScriptEnabled(true);
WebSettings settings2 = getSettings();
j.a((Object) settings2, "settings");
settings2.setMediaPlaybackRequiresUserGesture(false);
WebSettings settings3 = getSettings();
j.a((Object) settings3, "settings");
settings3.setCacheMode(2);
addJavascriptInterface(new com.pierfrancescosoffritti.androidyoutubeplayer.core.player.b(this), "YouTubePlayerBridge");
com.pierfrancescosoffritti.androidyoutubeplayer.core.player.utils.d dVar = com.pierfrancescosoffritti.androidyoutubeplayer.core.player.utils.d.f1063a;
InputStream openRawResource = getResources().openRawResource(R.e.ayp_youtube_player);
j.a((Object) openRawResource, "resources.openRawResourc…R.raw.ayp_youtube_player)");
String a2 = kotlin.text.h.a(com.pierfrancescosoffritti.androidyoutubeplayer.core.player.utils.d.a(openRawResource), "<<injectedPlayerVars>>", aVar.toString(), false);
String string = aVar.f1044a.getString("origin");
j.a((Object) string, "playerOptions.getString(Builder.ORIGIN)");
loadDataWithBaseURL(string, a2, "text/html", "utf-8", null);
setWebChromeClient(new b());
}
@Override
public final boolean addListener(com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a.d dVar) {
j.b(dVar, "listener");
return this.youTubePlayerListeners.add(dVar);
}
@Override
public final void cueVideo(String str, float f2) {
j.b(str, "videoId");
this.mainThreadHandler.post(new a(str, f2));
}
@Override
public final void destroy() {
this.youTubePlayerListeners.clear();
this.mainThreadHandler.removeCallbacksAndMessages(null);
super.destroy();
}
@Override
public final com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a getInstance() {
return this;
}
@Override
public final Collection<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a.d> getListeners() {
Collection<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a.d> unmodifiableCollection = Collections.unmodifiableCollection(new HashSet(this.youTubePlayerListeners));
j.a((Object) unmodifiableCollection, "Collections.unmodifiable…(youTubePlayerListeners))");
return unmodifiableCollection;
}
public final void initialize$core_release(kotlin.b.a.b<? super com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a, r> bVar, com.pierfrancescosoffritti.androidyoutubeplayer.core.player.b.a aVar) {
j.b(bVar, "initListener");
this.youTubePlayerInitListener = bVar;
if (aVar == null) {
a.b bVar2 = com.pierfrancescosoffritti.androidyoutubeplayer.core.player.b.a.b;
aVar = com.pierfrancescosoffritti.androidyoutubeplayer.core.player.b.a.c;
}
initWebView(aVar);
}
public final boolean isBackgroundPlaybackEnabled$core_release() {
return this.isBackgroundPlaybackEnabled;
}
@Override
public final void loadVideo(String str, float f2) {
j.b(str, "videoId");
this.mainThreadHandler.post(new c(str, f2));
}
public final void mute() {
this.mainThreadHandler.post(new d());
}
@Override
protected final void onWindowVisibilityChanged(int i2) {
if (this.isBackgroundPlaybackEnabled && (i2 == 8 || i2 == 4)) {
return;
}
super.onWindowVisibilityChanged(i2);
}
@Override
public final void onYouTubeIFrameAPIReady() {
kotlin.b.a.b<? super com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a, r> bVar = this.youTubePlayerInitListener;
if (bVar == null) {
j.a("youTubePlayerInitListener");
}
bVar.invoke(this);
}
@Override
public final void pause() {
this.mainThreadHandler.post(new e());
}
@Override
public final void play() {
this.mainThreadHandler.post(new f());
}
@Override
public final boolean removeListener(com.pierfrancescosoffritti.androidyoutubeplayer.core.player.a.d dVar) {
j.b(dVar, "listener");
return this.youTubePlayerListeners.remove(dVar);
}
@Override
public final void seekTo(float f2) {
this.mainThreadHandler.post(new g(f2));
}
public final void setBackgroundPlaybackEnabled$core_release(boolean z) {
this.isBackgroundPlaybackEnabled = z;
}
public final void setVolume(int i2) {
if (!(i2 >= 0 && i2 <= 100)) {
throw new IllegalArgumentException("Volume must be between 0 and 100".toString());
}
this.mainThreadHandler.post(new h(i2));
}
public final void unMute() {
this.mainThreadHandler.post(new i());
}
}