MBridgeBTVideoView.java 源代码
package com.mbridge.msdk.video.bt.module;
import android.content.Context;
import android.content.res.Configuration;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Base64;
import android.view.View;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.core.app.NotificationCompat;
import com.anythink.expressad.foundation.g.h;
import com.mbridge.msdk.foundation.b.b;
import com.mbridge.msdk.foundation.entity.CampaignEx;
import com.mbridge.msdk.foundation.tools.k;
import com.mbridge.msdk.foundation.tools.q;
import com.mbridge.msdk.foundation.tools.u;
import com.mbridge.msdk.foundation.tools.x;
import com.mbridge.msdk.mbsignalcommon.windvane.g;
import com.mbridge.msdk.playercommon.DefaultVideoPlayerStatusListener;
import com.mbridge.msdk.playercommon.PlayerView;
import com.mbridge.msdk.video.bt.a.c;
import com.mbridge.msdk.video.widget.SoundImageView;
import com.mbridge.msdk.widget.FeedBackButton;
import java.io.File;
import org.json.JSONObject;
public class MBridgeBTVideoView extends BTBaseView {
private static boolean G;
private int A;
private int B;
private boolean C;
private int D;
private int E;
private String F;
private boolean H;
private boolean I;
private boolean J;
private RelativeLayout K;
private ProgressBar L;
private PlayerView f18747p;
private SoundImageView f18748q;
private TextView f18749r;
private View f18750s;
private FeedBackButton f18751t;
private WebView f18752u;
private com.mbridge.msdk.videocommon.download.a f18753v;
private int f18754w;
private int f18755x;
private int f18756y;
private a f18757z;
public static final class a extends DefaultVideoPlayerStatusListener {
private MBridgeBTVideoView f18761a;
private WebView f18762b;
private String f18763c;
private String f18764d;
private int f18765e;
private int f18766f;
private boolean f18767g;
private int f18771k;
private int f18772l;
private boolean f18768h = false;
private boolean f18769i = false;
private boolean f18770j = false;
private boolean f18773m = false;
public a(MBridgeBTVideoView mBridgeBTVideoView, WebView webView) {
this.f18761a = mBridgeBTVideoView;
this.f18762b = webView;
if (mBridgeBTVideoView != null) {
this.f18763c = mBridgeBTVideoView.f18677d;
this.f18764d = mBridgeBTVideoView.f18676c;
}
}
public final void a(int i6, int i7) {
this.f18771k = i6;
this.f18772l = i7;
}
@Override
public final void onBufferingEnd() {
try {
super.onBufferingEnd();
} catch (Exception e6) {
e6.printStackTrace();
}
}
@Override
public final void onBufferingStart(String str) {
try {
super.onBufferingStart(str);
if ((str.equals("mediaplayer prepare timeout") || str.equals("play buffering tiemout")) && this.f18762b != null) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("code", BTBaseView.f18672n);
jSONObject.put("id", this.f18763c);
jSONObject.put("data", new JSONObject());
g.a().a(this.f18762b, "onPlayerTimeout", Base64.encodeToString(jSONObject.toString().getBytes(), 2));
} catch (Exception e6) {
c.a().a(this.f18762b, e6.getMessage());
}
}
} catch (Exception e7) {
e7.printStackTrace();
}
}
@Override
public final void onPlayCompleted() {
super.onPlayCompleted();
MBridgeBTVideoView mBridgeBTVideoView = this.f18761a;
CampaignEx campaignEx = mBridgeBTVideoView.f18675b;
if (campaignEx != null) {
if (campaignEx.getVideoCompleteTime() > 0) {
this.f18761a.f18749r.setText(k.a(com.mbridge.msdk.foundation.controller.a.e().g(), "mbridge_reward_video_view_reward_time_complete", "string"));
} else {
this.f18761a.f18749r.setText("0");
}
} else {
mBridgeBTVideoView.f18749r.setText("0");
}
this.f18761a.f18747p.setClickable(false);
WebView webView = this.f18762b;
if (webView != null) {
BTBaseView.a(webView, "onPlayerFinish", this.f18763c);
}
this.f18765e = this.f18766f;
boolean unused = MBridgeBTVideoView.G = true;
this.f18761a.stop();
}
@Override
public final void onPlayError(String str) {
super.onPlayError(str);
if (this.f18762b != null) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("code", BTBaseView.f18673o);
jSONObject.put("id", this.f18763c);
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("error", str);
jSONObject2.put("id", this.f18763c);
jSONObject.put("data", jSONObject2);
g.a().a(this.f18762b, "onPlayerFailed", Base64.encodeToString(jSONObject.toString().getBytes(), 2));
} catch (Exception e6) {
c.a().a(this.f18762b, e6.getMessage());
}
}
}
@Override
public final void onPlayProgress(int i6, int i7) {
int i8;
int i9;
String str;
com.mbridge.msdk.videocommon.download.a a7;
int i10;
int i11;
StringBuilder sb;
String str2;
String sb2;
super.onPlayProgress(i6, i7);
MBridgeBTVideoView mBridgeBTVideoView = this.f18761a;
if (mBridgeBTVideoView.f18681h) {
CampaignEx campaignEx = mBridgeBTVideoView.f18675b;
if (campaignEx != null) {
i10 = campaignEx.getVideoCompleteTime();
b.a().b(this.f18761a.f18675b.getCampaignUnitId() + "_1", i6);
} else {
i10 = 0;
}
if (i10 > i7) {
i10 = i7;
}
if (i10 <= 0) {
i11 = i7 - i6;
} else {
i11 = i10 - i6;
}
if (i11 <= 0) {
if (i10 <= 0) {
sb2 = "0";
} else {
sb2 = (String) this.f18761a.getContext().getResources().getText(k.a(com.mbridge.msdk.foundation.controller.a.e().g(), "mbridge_reward_video_view_reward_time_complete", "string"));
}
} else {
if (i10 <= 0) {
sb = new StringBuilder();
sb.append(i11);
str2 = "";
} else {
sb = new StringBuilder();
sb.append(i11);
str2 = (String) this.f18761a.getContext().getResources().getText(k.a(com.mbridge.msdk.foundation.controller.a.e().g(), "mbridge_reward_video_view_reward_time_left", "string"));
}
sb.append(str2);
sb2 = sb.toString();
}
this.f18761a.f18749r.setText(sb2);
}
this.f18766f = i7;
this.f18765e = i6;
this.f18761a.L.setProgress(this.f18765e);
if (this.f18762b != null) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("code", BTBaseView.f18672n);
jSONObject.put("id", this.f18763c);
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("id", this.f18763c);
jSONObject2.put(NotificationCompat.CATEGORY_PROGRESS, MBridgeBTVideoView.b(i6, i7));
jSONObject2.put("time", String.valueOf(i6));
jSONObject2.put("duration", String.valueOf(i7));
jSONObject.put("data", jSONObject2);
g.a().a(this.f18762b, "onPlayerProgressChanged", Base64.encodeToString(jSONObject.toString().getBytes(), 2));
} catch (Exception e6) {
c.a().a(this.f18762b, e6.getMessage());
}
}
try {
if (this.f18771k != 100 && !this.f18773m && (i8 = this.f18772l) != 0 && i8 >= 0 && i6 >= (i9 = (i7 * i8) / 100)) {
if (this.f18761a.f18675b.getAdType() != 94 && this.f18761a.f18675b.getAdType() != 287) {
str = this.f18761a.f18675b.getId() + this.f18761a.f18675b.getVideoUrlEncode() + this.f18761a.f18675b.getBidToken();
a7 = com.mbridge.msdk.videocommon.download.c.getInstance().a(this.f18764d, str);
if (a7 == null) {
a7.j();
this.f18773m = true;
q.d("DefaultVideoPlayerStatusListener", "CDRate is : " + i9 + " and start download !");
return;
}
return;
}
str = this.f18761a.f18675b.getRequestId() + this.f18761a.f18675b.getId() + this.f18761a.f18675b.getVideoUrlEncode();
a7 = com.mbridge.msdk.videocommon.download.c.getInstance().a(this.f18764d, str);
if (a7 == null) {
}
}
} catch (Exception e7) {
q.d("DefaultVideoPlayerStatusListener", e7.getMessage());
}
}
@Override
public final void onPlaySetDataSourceError(String str) {
super.onPlaySetDataSourceError(str);
}
@Override
public final void onPlayStarted(int i6) {
super.onPlayStarted(i6);
if (!this.f18767g) {
this.f18761a.L.setMax(i6);
WebView webView = this.f18762b;
if (webView != null) {
BTBaseView.a(webView, "onPlayerPlay", this.f18763c);
}
this.f18767g = true;
}
boolean unused = MBridgeBTVideoView.G = false;
}
}
public MBridgeBTVideoView(Context context) {
super(context);
this.f18754w = 0;
this.f18755x = 0;
this.f18756y = 0;
this.A = 2;
this.C = false;
this.D = 2;
this.E = 1;
this.H = false;
this.I = false;
this.J = false;
}
public int getMute() {
return this.A;
}
@Override
public void init(Context context) {
int findLayout = findLayout("mbridge_reward_videoview_item");
if (findLayout > 0) {
this.f18679f.inflate(findLayout, this);
boolean b6 = b();
this.f18681h = b6;
if (!b6) {
q.d("BTBaseView", "MBridgeVideoView init fail");
}
a();
}
G = false;
}
@Override
protected void onAttachedToWindow() {
int i6;
int i7;
super.onAttachedToWindow();
if (!this.J) {
this.D = c.a().d(this.f18676c);
}
View view = this.f18750s;
int i8 = 8;
if (view != null) {
if (this.f18755x == 0) {
i7 = 8;
} else {
i7 = 0;
}
view.setVisibility(i7);
}
SoundImageView soundImageView = this.f18748q;
if (soundImageView != null) {
if (this.f18756y == 0) {
i6 = 8;
} else {
i6 = 0;
}
soundImageView.setVisibility(i6);
}
TextView textView = this.f18749r;
if (textView != null) {
if (this.f18754w != 0) {
i8 = 0;
}
textView.setVisibility(i8);
if (this.f18749r.getVisibility() == 0 && b.a().b()) {
b.a().a(this.f18676c + "_1", this.f18675b);
b.a().a(this.f18676c + "_1", this.f18751t);
}
}
}
@Override
public void onConfigurationChanged(Configuration configuration) {
super.onConfigurationChanged(configuration);
}
@Override
public void onDestory() {
try {
PlayerView playerView = this.f18747p;
if (playerView != null) {
playerView.setOnClickListener(null);
this.f18747p.release();
this.f18747p = null;
}
SoundImageView soundImageView = this.f18748q;
if (soundImageView != null) {
soundImageView.setOnClickListener(null);
}
View view = this.f18750s;
if (view != null) {
view.setOnClickListener(null);
}
if (this.f18752u != null) {
this.f18752u = null;
}
setOnClickListener(null);
} catch (Throwable th) {
q.a("BTBaseView", th.getMessage());
}
}
public void onPause() {
PlayerView playerView = this.f18747p;
if (playerView != null) {
boolean isPlayIng = playerView.isPlayIng();
this.I = isPlayIng;
this.f18747p.setIsBTVideoPlaying(isPlayIng);
this.f18747p.onPause();
}
}
public void onResume() {
PlayerView playerView = this.f18747p;
if (playerView != null) {
playerView.setIsCovered(false);
this.f18747p.setDesk(true);
if (this.I) {
this.f18747p.start(true);
}
}
}
public void onStop() {
PlayerView playerView = this.f18747p;
if (playerView != null) {
playerView.setIsCovered(true);
}
}
public void pause() {
try {
PlayerView playerView = this.f18747p;
if (playerView != null) {
playerView.pause();
WebView webView = this.f18752u;
if (webView != null) {
BTBaseView.a(webView, "onPlayerPause", this.f18677d);
}
}
} catch (Exception e6) {
q.a("BTBaseView", e6.getMessage(), e6);
}
}
public void play() {
a aVar;
try {
if (!this.J) {
String c6 = c();
this.F = c6;
this.f18747p.initVFPData(c6, this.f18675b.getVideoUrlEncode(), this.f18757z);
if (this.D == 1) {
playMute();
} else {
playUnMute();
}
if (!this.f18747p.playVideo() && (aVar = this.f18757z) != null) {
aVar.onPlayError("play video failed");
}
this.J = true;
return;
}
if (this.C) {
this.f18747p.playVideo(0);
this.C = false;
} else {
this.f18747p.start(false);
}
} catch (Exception e6) {
q.a("BTBaseView", e6.getMessage(), e6);
}
}
public boolean playMute() {
try {
PlayerView playerView = this.f18747p;
if (playerView != null && this.f18752u != null) {
playerView.closeSound();
this.f18748q.setSoundStatus(false);
this.A = 1;
BTBaseView.a(this.f18752u, "onPlayerMute", this.f18677d);
return true;
}
} catch (Exception e6) {
q.d("BTBaseView", e6.getMessage());
}
return false;
}
public boolean playUnMute() {
try {
PlayerView playerView = this.f18747p;
if (playerView != null && this.f18752u != null) {
playerView.openSound();
this.f18748q.setSoundStatus(true);
this.A = 2;
BTBaseView.a(this.f18752u, "onUnmute", this.f18677d);
return true;
}
return false;
} catch (Exception e6) {
q.d("BTBaseView", e6.getMessage());
return false;
}
}
public void preLoadData() {
String str;
int p6;
if (this.f18675b.getAdType() != 94 && this.f18675b.getAdType() != 287) {
str = this.f18675b.getId() + this.f18675b.getVideoUrlEncode() + this.f18675b.getBidToken();
} else {
str = this.f18675b.getRequestId() + this.f18675b.getId() + this.f18675b.getVideoUrlEncode();
}
com.mbridge.msdk.videocommon.download.a a7 = com.mbridge.msdk.videocommon.download.c.getInstance().a(this.f18676c, str);
if (a7 != null) {
this.f18753v = a7;
}
this.B = d();
String c6 = c();
this.F = c6;
if (this.f18681h && !TextUtils.isEmpty(c6) && this.f18675b != null) {
a aVar = new a(this, this.f18752u);
this.f18757z = aVar;
CampaignEx campaignEx = this.f18675b;
if (campaignEx != null) {
if (campaignEx.getReady_rate() != -1) {
p6 = campaignEx.getReady_rate();
} else {
p6 = com.mbridge.msdk.videocommon.d.b.a().a(com.mbridge.msdk.foundation.controller.a.e().h(), this.f18676c, false).p();
}
} else {
p6 = com.mbridge.msdk.videocommon.d.b.a().a(com.mbridge.msdk.foundation.controller.a.e().h(), this.f18676c, false).p();
}
aVar.a(p6, com.mbridge.msdk.videocommon.d.b.a().a(com.mbridge.msdk.foundation.controller.a.e().h(), this.f18676c, false).q());
this.f18747p.setDesk(false);
this.f18747p.initBufferIngParam(this.B);
soundOperate(this.A, -1, null);
}
G = false;
}
public void resume() {
try {
PlayerView playerView = this.f18747p;
if (playerView != null) {
if (this.C) {
playerView.playVideo(0);
this.C = false;
} else {
playerView.onResume();
}
WebView webView = this.f18752u;
if (webView != null) {
BTBaseView.a(webView, "onPlayerResume", this.f18677d);
}
}
} catch (Exception e6) {
q.d("BTBaseView", e6.getMessage());
}
}
@Override
public void setCampaign(CampaignEx campaignEx) {
super.setCampaign(campaignEx);
if (campaignEx != null && campaignEx.getVideoCompleteTime() > 0) {
this.f18749r.setBackgroundResource(k.a(com.mbridge.msdk.foundation.controller.a.e().g(), "mbridge_reward_video_time_count_num_bg", h.f3993c));
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, u.b(com.mbridge.msdk.foundation.controller.a.e().g(), 30.0f));
int b6 = u.b(com.mbridge.msdk.foundation.controller.a.e().g(), 5.0f);
layoutParams.setMargins(b6, 0, 0, 0);
this.f18749r.setPadding(b6, 0, b6, 0);
this.f18749r.setLayoutParams(layoutParams);
return;
}
this.f18749r.setBackgroundResource(k.a(com.mbridge.msdk.foundation.controller.a.e().g(), "mbridge_reward_shape_progress", h.f3993c));
this.f18749r.setWidth(u.b(com.mbridge.msdk.foundation.controller.a.e().g(), 30.0f));
}
public void setCloseViewVisable(int i6) {
int i7;
View view = this.f18750s;
if (i6 == 0) {
i7 = 4;
} else {
i7 = 0;
}
view.setVisibility(i7);
}
public void setCountDownTextViewVisable(int i6) {
int i7;
TextView textView = this.f18749r;
if (i6 == 0) {
i7 = 4;
} else {
i7 = 0;
}
textView.setVisibility(i7);
}
public void setCreateWebView(WebView webView) {
this.f18752u = webView;
}
public void setNotchPadding(int i6, int i7, int i8, int i9) {
if (i6 <= 0) {
i6 = this.K.getPaddingLeft();
}
if (i7 <= 0) {
i7 = this.K.getPaddingRight();
}
if (i8 <= 0) {
i8 = this.K.getPaddingTop();
}
if (i9 <= 0) {
i9 = this.K.getPaddingBottom();
}
q.d("BTBaseView", "NOTCH BTVideoView " + String.format("%1s-%2s-%3s-%4s", Integer.valueOf(i6), Integer.valueOf(i7), Integer.valueOf(i8), Integer.valueOf(i9)));
this.K.setPadding(i6, i8, i7, i9);
}
public void setOrientation(int i6) {
this.E = i6;
}
public void setPlaybackParams(float f6) {
PlayerView playerView = this.f18747p;
if (playerView != null) {
playerView.setPlaybackParams(f6);
}
}
public void setProgressBarState(int i6) {
int i7;
ProgressBar progressBar = this.L;
if (progressBar != null) {
if (i6 == 0) {
i7 = 8;
} else {
i7 = 0;
}
progressBar.setVisibility(i7);
}
}
public void setShowClose(int i6) {
this.f18755x = i6;
}
public void setShowMute(int i6) {
this.f18756y = i6;
}
public void setShowTime(int i6) {
this.f18754w = i6;
}
public void setSoundImageViewVisble(int i6) {
int i7;
SoundImageView soundImageView = this.f18748q;
if (i6 == 0) {
i7 = 4;
} else {
i7 = 0;
}
soundImageView.setVisibility(i7);
}
public void setVolume(float f6, float f7) {
PlayerView playerView = this.f18747p;
if (playerView != null) {
playerView.setVolume(f6, f7);
}
}
public void soundOperate(int i6, int i7, String str) {
if (this.f18681h) {
this.A = i6;
if (i6 == 1) {
this.f18748q.setSoundStatus(false);
this.f18747p.closeSound();
} else if (i6 == 2) {
this.f18748q.setSoundStatus(true);
this.f18747p.openSound();
}
if (i7 == 1) {
this.f18748q.setVisibility(8);
} else if (i7 == 2) {
this.f18748q.setVisibility(0);
}
}
}
public void stop() {
try {
PlayerView playerView = this.f18747p;
if (playerView != null) {
playerView.pause();
this.f18747p.stop();
this.C = true;
WebView webView = this.f18752u;
if (webView != null) {
BTBaseView.a(webView, "onPlayerStop", this.f18677d);
}
}
} catch (Exception e6) {
q.a("BTBaseView", e6.getMessage(), e6);
}
}
private boolean b() {
try {
this.f18747p = (PlayerView) findViewById(findID("mbridge_vfpv"));
this.f18748q = (SoundImageView) findViewById(findID("mbridge_sound_switch"));
this.f18749r = (TextView) findViewById(findID("mbridge_tv_count"));
this.f18750s = findViewById(findID("mbridge_rl_playing_close"));
this.K = (RelativeLayout) findViewById(findID("mbridge_top_control"));
this.L = (ProgressBar) findViewById(findID("mbridge_video_progress_bar"));
this.f18751t = (FeedBackButton) findViewById(findID("mbridge_native_endcard_feed_btn"));
this.f18747p.setIsBTVideo(true);
return isNotNULL(this.f18747p, this.f18748q, this.f18749r, this.f18750s);
} catch (Throwable th) {
q.a("BTBaseView", th.getMessage(), th);
return false;
}
}
private String c() {
String str = "";
try {
str = this.f18675b.getVideoUrlEncode();
com.mbridge.msdk.videocommon.download.a aVar = this.f18753v;
if (aVar == null) {
return str;
}
String d6 = aVar.d();
return !x.a(d6) ? new File(d6).exists() ? d6 : str : str;
} catch (Throwable th) {
q.a("BTBaseView", th.getMessage(), th);
return str;
}
}
private int d() {
try {
com.mbridge.msdk.videocommon.d.a b6 = com.mbridge.msdk.videocommon.d.b.a().b();
if (b6 == null) {
com.mbridge.msdk.videocommon.d.b.a().c();
}
r0 = b6 != null ? (int) b6.f() : 5;
q.b("BTBaseView", "MBridgeBaseView buffetTimeout:" + r0);
} catch (Throwable th) {
th.printStackTrace();
}
return r0;
}
@Override
public final void a() {
super.a();
if (this.f18681h) {
this.f18748q.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
boolean isSilent = MBridgeBTVideoView.this.f18747p.isSilent();
if (MBridgeBTVideoView.this.f18752u != null) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("code", BTBaseView.f18672n);
jSONObject.put("id", MBridgeBTVideoView.this.f18677d);
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("mute", MBridgeBTVideoView.this.A);
jSONObject.put("data", jSONObject2);
g.a().a(MBridgeBTVideoView.this.f18752u, "onPlayerMuteBtnClicked", Base64.encodeToString(jSONObject.toString().getBytes(), 2));
q.a("OperateViews", "onPlayerMuteBtnClicked isMute = " + isSilent + " mute = " + MBridgeBTVideoView.this.A);
} catch (Exception e6) {
c.a().a(MBridgeBTVideoView.this.f18752u, e6.getMessage());
}
}
}
});
this.f18750s.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
if (MBridgeBTVideoView.this.f18752u != null) {
BTBaseView.a(MBridgeBTVideoView.this.f18752u, "onPlayerCloseBtnClicked", MBridgeBTVideoView.this.f18677d);
}
}
});
setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
if (MBridgeBTVideoView.this.f18752u != null) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("code", BTBaseView.f18672n);
jSONObject.put("id", MBridgeBTVideoView.this.f18677d);
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("x", String.valueOf(view.getX()));
jSONObject2.put("y", String.valueOf(view.getY()));
jSONObject.put("data", jSONObject2);
g.a().a(MBridgeBTVideoView.this.f18752u, "onClicked", Base64.encodeToString(jSONObject.toString().getBytes(), 2));
} catch (Exception unused) {
c.a().a(MBridgeBTVideoView.this.f18752u, "onClicked", MBridgeBTVideoView.this.f18677d);
}
}
}
});
}
}
public MBridgeBTVideoView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.f18754w = 0;
this.f18755x = 0;
this.f18756y = 0;
this.A = 2;
this.C = false;
this.D = 2;
this.E = 1;
this.H = false;
this.I = false;
this.J = false;
}
public static String b(int i6, int i7) {
if (i7 != 0) {
try {
return u.a(Double.valueOf(i6 / i7)) + "";
} catch (Throwable th) {
th.printStackTrace();
}
}
return i7 + "";
}
}