- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
967 lines
35 KiB
Java
967 lines
35 KiB
Java
package com.mbridge.msdk.playercommon;
|
||
|
||
import android.content.Context;
|
||
import android.net.Uri;
|
||
import android.os.Handler;
|
||
import android.os.Looper;
|
||
import android.os.Message;
|
||
import android.text.TextUtils;
|
||
import android.view.SurfaceHolder;
|
||
import android.view.View;
|
||
import androidx.annotation.Nullable;
|
||
import com.mbridge.msdk.foundation.same.report.i;
|
||
import com.mbridge.msdk.foundation.tools.ab;
|
||
import com.mbridge.msdk.foundation.tools.af;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.DefaultLoadControl;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.DefaultRenderersFactory;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.ExoPlaybackException;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.ExoPlayerFactory;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.PlaybackParameters;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.Player;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.SimpleExoPlayer;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.Timeline;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.source.ExtractorMediaSource;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.source.MediaSource;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.source.TrackGroupArray;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.trackselection.DefaultTrackSelector;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.trackselection.TrackSelectionArray;
|
||
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DefaultDataSourceFactory;
|
||
import java.lang.ref.WeakReference;
|
||
import java.util.Timer;
|
||
import java.util.TimerTask;
|
||
|
||
/* loaded from: classes4.dex */
|
||
public class VideoFeedsPlayer implements Player.EventListener {
|
||
public static final int INTERVAL_TIME_PLAY_TIME_CD_THREAD = 1000;
|
||
public static final String TAG = "VideoFeedsPlayer";
|
||
private SimpleExoPlayer exoPlayer;
|
||
private Timer mBufferTimeoutTimer;
|
||
private long mCurrentPosition;
|
||
private View mFullScreenLoadingView;
|
||
private volatile VideoPlayerStatusListener mInnerVFPLisener;
|
||
private boolean mIsSilent;
|
||
private WeakReference<View> mLoadingView;
|
||
private volatile VideoPlayerStatusListener mOutterVFListener;
|
||
private String mPlayUrl;
|
||
private SurfaceHolder mSurfaceHolder;
|
||
private MediaSource mediaSource;
|
||
private boolean mIsComplete = false;
|
||
private boolean mIsPlaying = false;
|
||
private boolean mHasPrepare = false;
|
||
private boolean mIsBuffering = false;
|
||
private boolean mIsNeedBufferingTimeout = false;
|
||
private boolean mIsFrontDesk = true;
|
||
private int mBufferTime = 5;
|
||
private Object mLock = new Object();
|
||
private boolean isStart = false;
|
||
private final Handler mHandler = new Handler(Looper.getMainLooper()) { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.1
|
||
@Override // android.os.Handler
|
||
public void handleMessage(Message message) {
|
||
super.handleMessage(message);
|
||
}
|
||
};
|
||
private Runnable playProgressRunnable = new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.2
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
long j;
|
||
try {
|
||
if (VideoFeedsPlayer.this.exoPlayer == null || !VideoFeedsPlayer.this.exoPlayerIsPlaying()) {
|
||
return;
|
||
}
|
||
VideoFeedsPlayer videoFeedsPlayer = VideoFeedsPlayer.this;
|
||
videoFeedsPlayer.mCurrentPosition = videoFeedsPlayer.exoPlayer.getCurrentPosition();
|
||
float f = VideoFeedsPlayer.this.mCurrentPosition % 1000;
|
||
int round = Math.round(VideoFeedsPlayer.this.mCurrentPosition / 1000.0f);
|
||
af.c(VideoFeedsPlayer.TAG, "currentPosition:" + round + " mCurrentPosition:" + VideoFeedsPlayer.this.mCurrentPosition);
|
||
if (VideoFeedsPlayer.this.exoPlayer == null || VideoFeedsPlayer.this.exoPlayer.getDuration() <= 0) {
|
||
j = 0;
|
||
} else {
|
||
j = VideoFeedsPlayer.this.exoPlayer.getDuration() / 1000;
|
||
if (f > 0.0f && f < 500.0f) {
|
||
round++;
|
||
}
|
||
}
|
||
if (round >= 0 && j > 0 && round < 1 + j) {
|
||
VideoFeedsPlayer.this.postOnPlayProgressOnMainThread(round, (int) j);
|
||
}
|
||
VideoFeedsPlayer.this.mIsComplete = false;
|
||
if (!VideoFeedsPlayer.this.mIsBuffering) {
|
||
VideoFeedsPlayer.this.hideLoading();
|
||
}
|
||
VideoFeedsPlayer.this.mHandler.postDelayed(this, 1000L);
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
};
|
||
|
||
public int getCurPosition() {
|
||
return (int) this.mCurrentPosition;
|
||
}
|
||
|
||
public boolean hasPrepare() {
|
||
return this.mHasPrepare;
|
||
}
|
||
|
||
public boolean isComplete() {
|
||
return this.mIsComplete;
|
||
}
|
||
|
||
public boolean isSilent() {
|
||
return this.mIsSilent;
|
||
}
|
||
|
||
public void onBufferingUpdate(int i) {
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onLoadingChanged(boolean z) {
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onPositionDiscontinuity(int i) {
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onRepeatModeChanged(int i) {
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onSeekProcessed() {
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onShuffleModeEnabledChanged(boolean z) {
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onTimelineChanged(Timeline timeline, @Nullable Object obj, int i) {
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onTracksChanged(TrackGroupArray trackGroupArray, TrackSelectionArray trackSelectionArray) {
|
||
}
|
||
|
||
public void setIsComplete(boolean z) {
|
||
this.mIsComplete = z;
|
||
}
|
||
|
||
public void setSelfVideoFeedsPlayerListener(VideoPlayerStatusListener videoPlayerStatusListener) {
|
||
this.mInnerVFPLisener = videoPlayerStatusListener;
|
||
}
|
||
|
||
public void setVideoFeedsPlayerListener(VideoPlayerStatusListener videoPlayerStatusListener) {
|
||
this.mOutterVFListener = videoPlayerStatusListener;
|
||
}
|
||
|
||
public boolean initPlayer(Context context, View view, String str, VideoPlayerStatusListener videoPlayerStatusListener) {
|
||
try {
|
||
if (view == null) {
|
||
af.c(TAG, "loadingView is NULL");
|
||
postOnPlayErrorOnMainThread(PlayerErrorConstant.MEDIAPLAYER_INIT_FAILED);
|
||
return false;
|
||
}
|
||
this.mOutterVFListener = videoPlayerStatusListener;
|
||
this.mLoadingView = new WeakReference<>(view);
|
||
this.exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(context), new DefaultTrackSelector(), new DefaultLoadControl());
|
||
this.mediaSource = new ExtractorMediaSource.Factory(new DefaultDataSourceFactory(context, "MBridge_ExoPlayer")).createMediaSource(Uri.parse(str));
|
||
this.exoPlayer.setRepeatMode(0);
|
||
this.exoPlayer.prepare(this.mediaSource);
|
||
this.exoPlayer.addListener(this);
|
||
return true;
|
||
} catch (Throwable th) {
|
||
af.b(TAG, th.getMessage());
|
||
postOnPlayErrorOnMainThread(th.toString());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public void setDisplay(SurfaceHolder surfaceHolder) {
|
||
try {
|
||
this.exoPlayer.getVideoComponent().setVideoSurfaceHolder(surfaceHolder);
|
||
} catch (Throwable th) {
|
||
af.b(TAG, th.getMessage());
|
||
postOnPlayErrorOnMainThread(th.toString());
|
||
}
|
||
}
|
||
|
||
public void play(String str, int i) {
|
||
try {
|
||
synchronized (this.mLock) {
|
||
try {
|
||
af.b(TAG, "Start Play currentionPosition:" + this.mCurrentPosition);
|
||
if (i > 0) {
|
||
this.mCurrentPosition = i;
|
||
}
|
||
if (TextUtils.isEmpty(str)) {
|
||
postOnPlayErrorOnMainThread(PlayerErrorConstant.PLAY_URL_ILLEGAL);
|
||
return;
|
||
}
|
||
this.mPlayUrl = str;
|
||
this.mHasPrepare = false;
|
||
this.mIsFrontDesk = true;
|
||
showLoading();
|
||
setDataSource();
|
||
af.c(TAG, "mPlayUrl:" + this.mPlayUrl);
|
||
} catch (Throwable th) {
|
||
throw th;
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
releasePlayer();
|
||
hideLoading();
|
||
postOnPlayErrorOnMainThread(PlayerErrorConstant.PLAY_CANNOT_PALY);
|
||
}
|
||
}
|
||
|
||
public void play(String str, SurfaceHolder surfaceHolder) {
|
||
try {
|
||
synchronized (this.mLock) {
|
||
try {
|
||
if (TextUtils.isEmpty(str)) {
|
||
postOnPlayErrorOnMainThread(PlayerErrorConstant.PLAY_URL_ILLEGAL);
|
||
return;
|
||
}
|
||
this.mPlayUrl = str;
|
||
this.mHasPrepare = false;
|
||
this.mIsFrontDesk = true;
|
||
this.mSurfaceHolder = surfaceHolder;
|
||
showLoading();
|
||
setDataSource();
|
||
af.c(TAG, "mPlayUrl:" + this.mPlayUrl);
|
||
} catch (Throwable th) {
|
||
throw th;
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
releasePlayer();
|
||
hideLoading();
|
||
postOnPlayErrorOnMainThread(PlayerErrorConstant.PLAY_CANNOT_PALY);
|
||
}
|
||
}
|
||
|
||
private void startPlayProgressTimer() {
|
||
try {
|
||
cancelPlayProgressTimer();
|
||
this.mHandler.post(this.playProgressRunnable);
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
private void cancelPlayProgressTimer() {
|
||
try {
|
||
this.mHandler.removeCallbacks(this.playProgressRunnable);
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
private void cancelBufferTimeoutTimer() {
|
||
try {
|
||
Timer timer = this.mBufferTimeoutTimer;
|
||
if (timer != null) {
|
||
timer.cancel();
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
private void startBufferIngTimer(final String str) {
|
||
if (!this.mIsNeedBufferingTimeout) {
|
||
af.b(TAG, "不需要缓冲超时功能");
|
||
return;
|
||
}
|
||
cancelBufferTimeoutTimer();
|
||
Timer timer = new Timer();
|
||
this.mBufferTimeoutTimer = timer;
|
||
timer.schedule(new TimerTask() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.3
|
||
@Override // java.util.TimerTask, java.lang.Runnable
|
||
public void run() {
|
||
try {
|
||
if (VideoFeedsPlayer.this.mHasPrepare && !VideoFeedsPlayer.this.mIsBuffering) {
|
||
return;
|
||
}
|
||
af.b(VideoFeedsPlayer.TAG, "缓冲超时");
|
||
VideoFeedsPlayer.this.postOnBufferingStarOnMainThread(str);
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
}, this.mBufferTime * 1000);
|
||
}
|
||
|
||
public void initBufferIngParam(int i) {
|
||
if (i > 0) {
|
||
this.mBufferTime = i;
|
||
}
|
||
this.mIsNeedBufferingTimeout = true;
|
||
af.c(TAG, "mIsNeedBufferingTimeout:" + this.mIsNeedBufferingTimeout + " mMaxBufferTime:" + this.mBufferTime);
|
||
}
|
||
|
||
public void onCompletion() {
|
||
try {
|
||
this.mIsComplete = true;
|
||
this.mIsPlaying = false;
|
||
this.mCurrentPosition = 0L;
|
||
hideLoading();
|
||
postOnPlayCompletedOnMainThread();
|
||
af.c(TAG, "======onCompletion");
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void onPrepared() {
|
||
try {
|
||
af.c(TAG, "onPrepared:" + this.mHasPrepare);
|
||
this.mHasPrepare = true;
|
||
boolean z = this.mIsFrontDesk;
|
||
if (!z) {
|
||
af.b(TAG, "At background, Do not process");
|
||
if (this.exoPlayer != null) {
|
||
pause();
|
||
return;
|
||
}
|
||
return;
|
||
}
|
||
if (z) {
|
||
hideLoading();
|
||
SimpleExoPlayer simpleExoPlayer = this.exoPlayer;
|
||
if (simpleExoPlayer != null) {
|
||
this.mIsPlaying = true;
|
||
if (!this.isStart) {
|
||
postOnPlayStartOnMainThread(simpleExoPlayer.getDuration() / 1000);
|
||
af.c(TAG, "onPlayStarted(),getCurrentPosition:" + this.exoPlayer.getCurrentPosition());
|
||
this.isStart = true;
|
||
}
|
||
}
|
||
postOnBufferinEndOnMainThread();
|
||
startPlayProgressTimer();
|
||
af.c(TAG, "onPrepare mCurrentPosition:" + this.mCurrentPosition + " onPrepare mHasPrepare:" + this.mHasPrepare);
|
||
}
|
||
} catch (Throwable th) {
|
||
af.b(TAG, th.getMessage());
|
||
}
|
||
}
|
||
|
||
public void showLoading() {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler == null) {
|
||
return;
|
||
}
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.4
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (VideoFeedsPlayer.this.mFullScreenLoadingView != null) {
|
||
VideoFeedsPlayer.this.mFullScreenLoadingView.setVisibility(0);
|
||
}
|
||
}
|
||
});
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
/* JADX INFO: Access modifiers changed from: private */
|
||
public void hideLoading() {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler == null) {
|
||
return;
|
||
}
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.5
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (VideoFeedsPlayer.this.mLoadingView != null && VideoFeedsPlayer.this.mLoadingView.get() != null) {
|
||
((View) VideoFeedsPlayer.this.mLoadingView.get()).setVisibility(8);
|
||
}
|
||
if (VideoFeedsPlayer.this.mFullScreenLoadingView != null) {
|
||
VideoFeedsPlayer.this.mFullScreenLoadingView.setVisibility(8);
|
||
}
|
||
}
|
||
});
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
/* JADX INFO: Access modifiers changed from: private */
|
||
public void postOnPlayProgressOnMainThread(final int i, final int i2) {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler != null) {
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.6
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (VideoFeedsPlayer.this.mOutterVFListener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mOutterVFListener.onPlayProgress(i, i2);
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
if (VideoFeedsPlayer.this.mInnerVFPLisener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mInnerVFPLisener.onPlayProgress(i, i2);
|
||
} catch (Exception e2) {
|
||
af.b(VideoFeedsPlayer.TAG, e2.getMessage());
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
/* JADX INFO: Access modifiers changed from: private */
|
||
public void postOnBufferingStarOnMainThread(final String str) {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler != null) {
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.7
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (VideoFeedsPlayer.this.mOutterVFListener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mOutterVFListener.onBufferingStart(str);
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
if (VideoFeedsPlayer.this.mInnerVFPLisener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mInnerVFPLisener.onBufferingStart(str);
|
||
} catch (Exception e2) {
|
||
af.b(VideoFeedsPlayer.TAG, e2.getMessage());
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
private void postOnBufferinEndOnMainThread() {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler != null) {
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.8
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (VideoFeedsPlayer.this.mOutterVFListener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mOutterVFListener.onBufferingEnd();
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
if (VideoFeedsPlayer.this.mInnerVFPLisener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mInnerVFPLisener.onBufferingEnd();
|
||
} catch (Exception e2) {
|
||
af.b(VideoFeedsPlayer.TAG, e2.getMessage());
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
private void postOnPlayStartOnMainThread(final long j) {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler != null) {
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.9
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
int i = (int) j;
|
||
if (VideoFeedsPlayer.this.mOutterVFListener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mOutterVFListener.onPlayStarted(i);
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
if (VideoFeedsPlayer.this.mInnerVFPLisener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mInnerVFPLisener.onPlayStarted(i);
|
||
} catch (Exception e2) {
|
||
af.b(VideoFeedsPlayer.TAG, e2.getMessage());
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
private void postOnPlayErrorOnMainThread(final String str) {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler != null) {
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.10
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (VideoFeedsPlayer.this.mOutterVFListener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mOutterVFListener.onPlayError(str);
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
if (VideoFeedsPlayer.this.mInnerVFPLisener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mInnerVFPLisener.onPlayError(str);
|
||
} catch (Exception e2) {
|
||
af.b(VideoFeedsPlayer.TAG, e2.getMessage());
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
i.a(94, this.mPlayUrl, str);
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
private void postOnPlaySetDataSourceError2MainThread(final String str) {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler != null) {
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.11
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (VideoFeedsPlayer.this.mInnerVFPLisener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mInnerVFPLisener.onPlaySetDataSourceError(str);
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
if (VideoFeedsPlayer.this.mOutterVFListener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mOutterVFListener.onPlaySetDataSourceError(str);
|
||
} catch (Exception e2) {
|
||
af.b(VideoFeedsPlayer.TAG, e2.getMessage());
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
private void postOnPlayCompletedOnMainThread() {
|
||
try {
|
||
Handler handler = this.mHandler;
|
||
if (handler != null) {
|
||
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.VideoFeedsPlayer.12
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (VideoFeedsPlayer.this.mOutterVFListener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mOutterVFListener.onPlayCompleted();
|
||
} catch (Exception e) {
|
||
af.b(VideoFeedsPlayer.TAG, e.getMessage());
|
||
}
|
||
}
|
||
if (VideoFeedsPlayer.this.mInnerVFPLisener != null) {
|
||
try {
|
||
VideoFeedsPlayer.this.mInnerVFPLisener.onPlayCompleted();
|
||
} catch (Exception e2) {
|
||
af.b(VideoFeedsPlayer.TAG, e2.getMessage());
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void pause() {
|
||
try {
|
||
if (this.mHasPrepare && this.exoPlayer != null && exoPlayerIsPlaying()) {
|
||
af.c(TAG, "pause isPalying:" + exoPlayerIsPlaying() + " mIsPlaying:" + this.mIsPlaying);
|
||
hideLoading();
|
||
this.exoPlayer.setPlayWhenReady(false);
|
||
this.mIsPlaying = false;
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void prepare() {
|
||
SimpleExoPlayer simpleExoPlayer;
|
||
try {
|
||
if (this.mHasPrepare || (simpleExoPlayer = this.exoPlayer) == null) {
|
||
return;
|
||
}
|
||
simpleExoPlayer.prepare(this.mediaSource);
|
||
this.mHasPrepare = true;
|
||
this.mIsPlaying = false;
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void stop() {
|
||
try {
|
||
if (this.mHasPrepare && this.exoPlayer != null && exoPlayerIsPlaying()) {
|
||
hideLoading();
|
||
this.exoPlayer.stop();
|
||
this.mHasPrepare = false;
|
||
this.mIsPlaying = false;
|
||
this.mIsComplete = true;
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void start(boolean z) {
|
||
try {
|
||
if (!this.mHasPrepare) {
|
||
af.c(TAG, "!mHasPrepare");
|
||
return;
|
||
}
|
||
if (this.exoPlayer == null || exoPlayerIsPlaying()) {
|
||
return;
|
||
}
|
||
showLoading();
|
||
play();
|
||
this.mIsPlaying = true;
|
||
if (z) {
|
||
startPlayProgressTimer();
|
||
}
|
||
af.c(TAG, "start");
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void start(int i) {
|
||
try {
|
||
if (this.mHasPrepare) {
|
||
if (this.exoPlayer != null && !exoPlayerIsPlaying()) {
|
||
if (i > 0) {
|
||
this.exoPlayer.seekTo(i);
|
||
play();
|
||
} else {
|
||
play();
|
||
this.mIsPlaying = true;
|
||
af.c(TAG, "=========start 指定进度");
|
||
}
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void justSeekTo(int i) {
|
||
try {
|
||
this.mCurrentPosition = i;
|
||
if (this.mHasPrepare) {
|
||
return;
|
||
}
|
||
af.a(TAG, "seekTo return mHasPrepare false");
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void seekTo(int i) {
|
||
long j = i;
|
||
try {
|
||
this.mCurrentPosition = j;
|
||
if (!this.mHasPrepare) {
|
||
af.a(TAG, "seekTo return mHasPrepare false");
|
||
return;
|
||
}
|
||
SimpleExoPlayer simpleExoPlayer = this.exoPlayer;
|
||
if (simpleExoPlayer != null) {
|
||
simpleExoPlayer.seekTo(j);
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void setDataSource() {
|
||
try {
|
||
af.c(TAG, "setDataSource");
|
||
if (this.exoPlayer != null) {
|
||
SurfaceHolder surfaceHolder = this.mSurfaceHolder;
|
||
if (surfaceHolder != null) {
|
||
setDisplay(surfaceHolder);
|
||
}
|
||
this.mHasPrepare = false;
|
||
this.exoPlayer.prepare(this.mediaSource);
|
||
this.exoPlayer.setPlayWhenReady(true);
|
||
startBufferIngTimer(PlayerErrorConstant.PREPARE_TIMEOUT);
|
||
}
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
hideLoading();
|
||
postOnPlayErrorOnMainThread(PlayerErrorConstant.ILLEGAL_VIDEO_ADDRESS);
|
||
postOnPlaySetDataSourceError2MainThread(PlayerErrorConstant.ILLEGAL_VIDEO_ADDRESS);
|
||
}
|
||
}
|
||
|
||
public void releasePlayer() {
|
||
try {
|
||
af.c(TAG, "release");
|
||
cancelPlayProgressTimer();
|
||
cancelBufferTimeoutTimer();
|
||
if (this.exoPlayer != null) {
|
||
stop();
|
||
this.exoPlayer.removeListener(this);
|
||
this.exoPlayer.release();
|
||
this.mInnerVFPLisener = null;
|
||
this.mOutterVFListener = null;
|
||
}
|
||
hideLoading();
|
||
} catch (Throwable th) {
|
||
af.b(TAG, th.getMessage());
|
||
}
|
||
}
|
||
|
||
public void closeSound() {
|
||
try {
|
||
SimpleExoPlayer simpleExoPlayer = this.exoPlayer;
|
||
if (simpleExoPlayer == null) {
|
||
return;
|
||
}
|
||
simpleExoPlayer.setVolume(0.0f);
|
||
this.mIsSilent = true;
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void openSound() {
|
||
try {
|
||
SimpleExoPlayer simpleExoPlayer = this.exoPlayer;
|
||
if (simpleExoPlayer == null) {
|
||
return;
|
||
}
|
||
simpleExoPlayer.setVolume(1.0f);
|
||
this.mIsSilent = false;
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public float getVolume() {
|
||
SimpleExoPlayer simpleExoPlayer = this.exoPlayer;
|
||
if (simpleExoPlayer != null) {
|
||
return simpleExoPlayer.getVolume();
|
||
}
|
||
return 0.0f;
|
||
}
|
||
|
||
public boolean isPlayIng() {
|
||
try {
|
||
if (this.exoPlayer != null) {
|
||
return exoPlayerIsPlaying();
|
||
}
|
||
return false;
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public boolean onError(int i, String str) {
|
||
try {
|
||
af.b(TAG, "onError what: " + i + " extra: " + str);
|
||
hideLoading();
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
if (!this.mIsFrontDesk && "MIX 3".equalsIgnoreCase(ab.h()) && ab.x().equalsIgnoreCase("Xiaomi")) {
|
||
return true;
|
||
}
|
||
this.mHasPrepare = false;
|
||
postOnPlayErrorOnMainThread(str);
|
||
return true;
|
||
}
|
||
|
||
public void setIsFrontDesk(boolean z) {
|
||
try {
|
||
this.mIsFrontDesk = z;
|
||
StringBuilder sb = new StringBuilder();
|
||
sb.append("isFrontDesk: ");
|
||
sb.append(z ? "frontStage" : "backStage");
|
||
af.b(TAG, sb.toString());
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
|
||
public void setFullScreenLoadingView(View view) {
|
||
if (view != null) {
|
||
try {
|
||
this.mFullScreenLoadingView = view;
|
||
} catch (Exception e) {
|
||
af.b(TAG, e.getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
public boolean fullScreenLoadingViewisVisible() {
|
||
try {
|
||
View view = this.mFullScreenLoadingView;
|
||
if (view != null) {
|
||
return view.getVisibility() == 0;
|
||
}
|
||
return false;
|
||
} catch (Throwable th) {
|
||
af.b(TAG, th.getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public boolean halfLoadingViewisVisible() {
|
||
try {
|
||
WeakReference<View> weakReference = this.mLoadingView;
|
||
if (weakReference == null || weakReference.get() == null) {
|
||
return false;
|
||
}
|
||
return this.mLoadingView.get().getVisibility() == 0;
|
||
} catch (Throwable th) {
|
||
af.b(TAG, th.getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public int getDuration() {
|
||
SimpleExoPlayer simpleExoPlayer = this.exoPlayer;
|
||
if (simpleExoPlayer == null) {
|
||
return 0;
|
||
}
|
||
simpleExoPlayer.getDuration();
|
||
return 0;
|
||
}
|
||
|
||
public void setVolume(float f, float f2) {
|
||
try {
|
||
SimpleExoPlayer simpleExoPlayer = this.exoPlayer;
|
||
if (simpleExoPlayer != null) {
|
||
simpleExoPlayer.setVolume(f2);
|
||
}
|
||
} catch (Throwable th) {
|
||
af.b(TAG, th.getMessage());
|
||
}
|
||
}
|
||
|
||
public void setPlaybackParams(float f) {
|
||
try {
|
||
if (exoPlayerIsPlaying()) {
|
||
this.exoPlayer.setPlaybackParameters(new PlaybackParameters(f));
|
||
} else {
|
||
this.exoPlayer.setPlaybackParameters(new PlaybackParameters(f));
|
||
this.exoPlayer.stop();
|
||
}
|
||
} catch (Throwable th) {
|
||
af.b(TAG, th.getMessage());
|
||
}
|
||
}
|
||
|
||
public boolean exoPlayerIsPlaying() {
|
||
return this.exoPlayer.getPlaybackState() == 3 && this.exoPlayer.getPlayWhenReady();
|
||
}
|
||
|
||
public void play() {
|
||
this.exoPlayer.setPlayWhenReady(true);
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onPlayerStateChanged(boolean z, int i) {
|
||
af.b(TAG, "onPlaybackStateChanged : " + i);
|
||
if (i == 1) {
|
||
af.b(TAG, "onPlaybackStateChanged : IDLE");
|
||
return;
|
||
}
|
||
if (i == 2) {
|
||
af.b(TAG, "onPlaybackStateChanged : Buffering");
|
||
this.mIsBuffering = true;
|
||
showLoading();
|
||
startBufferIngTimer(PlayerErrorConstant.PLAYERING_TIMEOUT);
|
||
return;
|
||
}
|
||
if (i != 3) {
|
||
if (i != 4) {
|
||
return;
|
||
}
|
||
af.b(TAG, "onPlaybackStateChanged : Ended : PLAY ENDED");
|
||
cancelPlayProgressTimer();
|
||
onCompletion();
|
||
return;
|
||
}
|
||
af.b(TAG, "onPlaybackStateChanged : READY");
|
||
this.mIsBuffering = false;
|
||
hideLoading();
|
||
postOnBufferinEndOnMainThread();
|
||
onPrepared();
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onPlayerError(ExoPlaybackException exoPlaybackException) {
|
||
String str;
|
||
if (exoPlaybackException != null) {
|
||
int i = exoPlaybackException.type;
|
||
if (i == 0) {
|
||
str = "Play error, because have a SourceException.";
|
||
} else if (i == 1) {
|
||
str = "Play error, because have a RendererException.";
|
||
} else if (i == 2) {
|
||
str = "Play error, because have a UnexpectedException.";
|
||
}
|
||
if (exoPlaybackException.getCause() != null && !TextUtils.isEmpty(exoPlaybackException.getCause().getMessage())) {
|
||
str = exoPlaybackException.getCause().getMessage();
|
||
}
|
||
af.b(TAG, "onPlayerError : " + str);
|
||
onError(exoPlaybackException.type, str);
|
||
}
|
||
str = "Play error and ExoPlayer have not message.";
|
||
if (exoPlaybackException.getCause() != null) {
|
||
str = exoPlaybackException.getCause().getMessage();
|
||
}
|
||
af.b(TAG, "onPlayerError : " + str);
|
||
onError(exoPlaybackException.type, str);
|
||
}
|
||
|
||
@Override // com.mbridge.msdk.playercommon.exoplayer2.Player.EventListener
|
||
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
|
||
af.b(TAG, "onPlaybackParametersChanged : " + playbackParameters.speed);
|
||
}
|
||
|
||
public void seekToEndFrame() {
|
||
SimpleExoPlayer simpleExoPlayer = this.exoPlayer;
|
||
if (simpleExoPlayer != null) {
|
||
simpleExoPlayer.seekTo(simpleExoPlayer.getCurrentPosition() - 500);
|
||
}
|
||
}
|
||
}
|