正在查看: 小柿子 v1.3.8 应用的 VideoPlayActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 小柿子 v1.3.8 应用的 VideoPlayActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package cn.hzjizhun.admin.h5;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.content.res.AppCompatResources;
import cn.hzjizhun.admin.custom_ad.http.CustomAdPosResult;
import cn.hzjizhun.admin.exception.AdError;
import cn.hzjizhun.admin.image.ImageLoaderImp;
import cn.hzjizhun.admin.util.ALog;
import com.sjm.sjmdaly.R;
public class VideoPlayActivity extends Activity {
private static final String TAG = "VideoPlayActivity11111111";
private CustomAdPosResult mAdObject;
private ImageView mCoverView;
private boolean mIsComplete;
private boolean mIsError;
private boolean mIsMute;
private boolean mIsPrepare;
private boolean mIsReward;
private FrameLayout mLayoutClick;
private LinearLayout mLayoutJump;
private ImageView mLogoView;
private MediaPlayer mMediaPlayer;
private SurfaceHolder mSurfaceHolder;
private SurfaceView mSurfaceView;
private TextView mTvCloseTime;
private TextView mTvSkip;
private ImageView mVoiceView;
private int currentPosition = 0;
private ImageLoaderImp imageLoaderImp = new ImageLoaderImp(this, TAG);
private Handler mTimeHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message message) {
super.handleMessage(message);
VideoPlayActivity.this.updataTime();
VideoPlayActivity.this.mTimeHandler.sendEmptyMessageDelayed(1, 1000L);
}
};
private boolean isPause = false;
private void changeMute() {
if (this.mIsMute) {
unmuteVideo();
} else {
h.a.g().c().playMuteReport();
muteVideo();
}
}
public void clickCloseView() {
if (this.mTvSkip.getVisibility() != 8 || this.mIsComplete) {
if (!this.mIsComplete) {
pauseVideo();
}
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.BwtDownloadAlertDialogStyle);
builder.setTitle("是否关闭广告");
builder.setCancelable(true);
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
try {
if (!VideoPlayActivity.this.mIsComplete && VideoPlayActivity.this.mTvSkip.getVisibility() == 0) {
h.a.g().c().playSkipReport();
}
dialogInterface.dismiss();
VideoPlayActivity.this.finish();
} catch (Throwable unused) {
}
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
if (!VideoPlayActivity.this.mIsComplete) {
VideoPlayActivity.this.videoResume();
}
dialogInterface.dismiss();
}
});
builder.show();
}
}
public void initMediaPlayer() {
try {
if (this.mMediaPlayer != null) {
return;
}
ALog.innerD(TAG, "initMediaPlayer.....");
MediaPlayer mediaPlayer = new MediaPlayer();
this.mMediaPlayer = mediaPlayer;
mediaPlayer.setDataSource(this.mAdObject.video.url);
this.mMediaPlayer.prepareAsync();
this.mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer2) {
ALog.innerD(VideoPlayActivity.TAG, "onPrepared.........." + VideoPlayActivity.this.currentPosition);
VideoPlayActivity.this.mCoverView.setVisibility(8);
VideoPlayActivity.this.mIsPrepare = true;
if (VideoPlayActivity.this.isPause) {
return;
}
VideoPlayActivity.this.videoPrepared();
VideoPlayActivity.this.mMediaPlayer.start();
}
});
this.mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer mediaPlayer2) {
if (VideoPlayActivity.this.mMediaPlayer.isPlaying()) {
return;
}
VideoPlayActivity.this.mMediaPlayer.start();
}
});
this.mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mediaPlayer2, int i2, int i3) {
ALog.d(VideoPlayActivity.TAG, "视频播放失败" + i2 + "===" + i3);
VideoPlayActivity.this.onAdError(new AdError(-1, "video player fail"));
VideoPlayActivity.this.mIsError = true;
VideoPlayActivity.this.finish();
return false;
}
});
this.mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer2) {
ALog.innerD(VideoPlayActivity.TAG, "onCompletion..........");
VideoPlayActivity.this.mIsComplete = true;
VideoPlayActivity.this.mCoverView.setVisibility(0);
VideoPlayActivity.this.mVoiceView.setVisibility(8);
VideoPlayActivity.this.mTimeHandler.removeCallbacksAndMessages(null);
VideoPlayActivity.this.mTvSkip.setVisibility(8);
VideoPlayActivity.this.mTvCloseTime.setText("关闭");
if (VideoPlayActivity.this.mAdObject.video.min_time == 0) {
VideoPlayActivity.this.onAdReward();
}
h.a.g().c().playEndReport();
}
});
} catch (Throwable th) {
th.printStackTrace();
}
}
private void initVideoView() {
SurfaceHolder holder = this.mSurfaceView.getHolder();
this.mSurfaceHolder = holder;
holder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i2, int i3, int i4) {
}
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
if (VideoPlayActivity.this.mIsComplete) {
return;
}
VideoPlayActivity.this.initMediaPlayer();
VideoPlayActivity.this.mMediaPlayer.setDisplay(surfaceHolder);
VideoPlayActivity.this.videoResume();
} catch (Throwable unused) {
}
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
});
}
private void initView() {
this.mSurfaceView = (SurfaceView) findViewById(R.id.videoView);
this.mCoverView = (ImageView) findViewById(R.id.ivCover);
this.mVoiceView = (ImageView) findViewById(R.id.iv_voice);
this.mLogoView = (ImageView) findViewById(R.id.ivLogo);
this.mTvCloseTime = (TextView) findViewById(R.id.tv_close_time);
this.mTvSkip = (TextView) findViewById(R.id.tvSkip);
this.mLayoutJump = (LinearLayout) findViewById(R.id.layoutJump);
this.mLayoutClick = (FrameLayout) findViewById(R.id.layoutClick);
this.mSurfaceView.setVisibility(0);
this.mVoiceView.setVisibility(0);
this.mLayoutJump.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
VideoPlayActivity.this.clickCloseView();
}
});
setCoverView();
initVideoView();
initVoiceView();
this.mLayoutClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
VideoPlayActivity.this.onAdClick();
}
});
}
private void initVoiceView() {
setMuteIcon();
this.mVoiceView.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
VideoPlayActivity.this.kdsksdda(view);
}
});
}
public void kdsksdda(View view) {
changeMute();
setMuteIcon();
}
public void onAdClick() {
try {
if (h.a.g().b() != null) {
h.a.g().b().onAdClick();
}
} catch (Throwable unused) {
}
}
private void onAdClose() {
try {
if (h.a.g().b() != null) {
h.a.g().b().onAdClose();
}
} catch (Throwable unused) {
}
}
public void onAdError(AdError adError) {
try {
if (h.a.g().b() != null) {
h.a.g().b().onAdError(adError);
}
} catch (Throwable unused) {
}
}
private void onAdExpose() {
try {
h.a.g().c().startPlayReport();
if (h.a.g().b() != null) {
h.a.g().b().onAdExpose();
}
} catch (Throwable unused) {
}
}
public void onAdReward() {
try {
if (this.mIsReward) {
return;
}
this.mIsReward = true;
if (h.a.g().b() != null) {
h.a.g().b().onAdReward();
}
} catch (Throwable unused) {
}
}
private void pauseVideo() {
MediaPlayer mediaPlayer;
try {
if (!this.mIsPrepare || this.mIsComplete || (mediaPlayer = this.mMediaPlayer) == null || !mediaPlayer.isPlaying()) {
return;
}
this.mTimeHandler.removeCallbacksAndMessages(null);
this.mMediaPlayer.pause();
this.currentPosition = this.mMediaPlayer.getCurrentPosition();
ALog.innerD(TAG, "pause position: " + this.currentPosition);
h.a.g().c().playPauseReport();
this.isPause = true;
} catch (Throwable th) {
ALog.innerE(TAG, th.getMessage());
}
}
private void releaseMediaPlayer() {
MediaPlayer mediaPlayer = this.mMediaPlayer;
if (mediaPlayer != null) {
if (mediaPlayer.isPlaying()) {
this.mMediaPlayer.stop();
}
this.mMediaPlayer.release();
this.mMediaPlayer = null;
}
}
private void setCoverView() {
try {
this.imageLoaderImp.loadImage(this.mAdObject.video.cover, this.mCoverView);
} catch (Throwable unused) {
}
}
private void setMuteIcon() {
ImageView imageView;
int i2;
if (this.mIsMute) {
imageView = this.mVoiceView;
i2 = R.mipmap.ad_sdk_volume_close;
} else {
imageView = this.mVoiceView;
i2 = R.mipmap.ad_sdk_volume_open;
}
imageView.setImageDrawable(AppCompatResources.getDrawable(this, i2));
}
private void setSkipView() {
TextView textView;
int i2;
try {
CustomAdPosResult.VideoBean videoBean = this.mAdObject.video;
int currentPosition = this.mMediaPlayer.getCurrentPosition() / 1000;
int i3 = videoBean.min_time;
if (i3 > 0 && currentPosition >= i3) {
onAdReward();
}
if (!videoBean.isCanSkip() || currentPosition <= videoBean.min_time) {
textView = this.mTvSkip;
i2 = 8;
} else {
textView = this.mTvSkip;
i2 = 0;
}
textView.setVisibility(i2);
} catch (Throwable unused) {
}
}
@SuppressLint({"DefaultLocale"})
public void updataTime() {
try {
if (this.mMediaPlayer == null) {
return;
}
setSkipView();
int duration = this.mMediaPlayer.getDuration();
int currentPosition = this.mMediaPlayer.getCurrentPosition();
int i2 = duration - currentPosition;
if (i2 < 0) {
i2 = 0;
}
this.mTvCloseTime.setText(String.format("%d 秒", Integer.valueOf(i2 / 1000)));
setSkipView();
float f2 = (currentPosition / duration) * 100.0f;
if (f2 >= 75.0f) {
h.a.g().c().play75Report();
} else if (f2 >= 50.0f) {
h.a.g().c().play50Report();
} else if (f2 >= 25.0f) {
h.a.g().c().play25Report();
}
} catch (Throwable unused) {
}
}
private void updateLogo() {
try {
this.imageLoaderImp.loadIcon(this.mAdObject.getIconUrl(), this.mLogoView);
} catch (Throwable unused) {
}
}
public void videoResume() {
try {
if (!this.mIsPrepare || this.mIsComplete || this.mMediaPlayer == null || !this.isPause) {
return;
}
ALog.innerD(TAG, "resume position: " + this.currentPosition);
this.mTimeHandler.sendEmptyMessage(1);
this.mMediaPlayer.start();
this.isPause = false;
h.a.g().c().playResumeReport();
} catch (Throwable unused) {
}
}
public void muteVideo() {
MediaPlayer mediaPlayer = this.mMediaPlayer;
if (mediaPlayer != null) {
this.mIsMute = true;
mediaPlayer.setVolume(0.0f, 0.0f);
}
}
@Override
public void onBackPressed() {
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_ad_rc_videoplay);
this.mAdObject = h.a.g().d();
initView();
updateLogo();
}
@Override
public void onDestroy() {
h.a.g().c().playCloseReport();
this.mTimeHandler.removeCallbacksAndMessages(null);
if (!this.mIsError) {
onAdClose();
}
releaseMediaPlayer();
this.mTimeHandler = null;
super.onDestroy();
}
@Override
public void onPause() {
super.onPause();
pauseVideo();
}
public void unmuteVideo() {
MediaPlayer mediaPlayer = this.mMediaPlayer;
if (mediaPlayer != null) {
this.mIsMute = false;
mediaPlayer.setVolume(1.0f, 1.0f);
}
}
public void videoPrepared() {
try {
this.mTimeHandler.sendEmptyMessage(1);
onAdExpose();
this.mCoverView.setVisibility(8);
} catch (Throwable unused) {
}
}
}