package com.mbridge.msdk.playercommon; import android.content.Context; import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import com.iab.omid.library.mmadbridge.adsession.media.MediaEvents; import com.mbridge.msdk.foundation.controller.c; import com.mbridge.msdk.foundation.d.b; import com.mbridge.msdk.foundation.same.a; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.foundation.tools.ah; import com.mbridge.msdk.foundation.tools.ak; import com.mbridge.msdk.foundation.tools.x; import com.mbridge.msdk.playercommon.exoplayer2.text.ttml.TtmlNode; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes4.dex */ public class PlayerView extends LinearLayout { public static final String TAG = "PlayerView"; private boolean hadOMPause; private boolean isBTVideo; private boolean isBTVideoPlaying; private boolean mHasReportedData; private boolean mInitState; private boolean mIsCovered; private boolean mIsFirstCreateHolder; private boolean mIsNeedToRepeatPrepare; private boolean mIsSurfaceHolderDestoryed; private LinearLayout mLlSurContainer; private LinearLayout mLoadingView; private String mPlayUrl; private SurfaceHolder mSurfaceHolder; private VideoFeedsPlayer mVideoFeedsPlayer; private OnPlayerViewVisibleListener onPlayerViewVisibleListener; protected int orientation; private MediaEvents videoEvents; protected float xInScreen; protected float yInScreen; public interface OnPlayerViewVisibleListener { void playerViewVisibleCallback(); } public MediaEvents getVideoEvents() { return this.videoEvents; } public void setIsBTVideo(boolean z) { this.isBTVideo = z; } public void setIsBTVideoPlaying(boolean z) { this.isBTVideoPlaying = z; } public void setNotifyListener(OnPlayerViewVisibleListener onPlayerViewVisibleListener) { this.onPlayerViewVisibleListener = onPlayerViewVisibleListener; } public void setVideoEvents(MediaEvents mediaEvents) { this.videoEvents = mediaEvents; } public PlayerView(Context context) { super(context); this.mInitState = false; this.mIsFirstCreateHolder = true; this.mIsSurfaceHolderDestoryed = false; this.mIsCovered = false; this.mIsNeedToRepeatPrepare = false; this.isBTVideo = false; this.isBTVideoPlaying = false; this.orientation = 1; this.mHasReportedData = false; this.hadOMPause = false; init(); } public PlayerView(Context context, AttributeSet attributeSet) { super(context, attributeSet); this.mInitState = false; this.mIsFirstCreateHolder = true; this.mIsSurfaceHolderDestoryed = false; this.mIsCovered = false; this.mIsNeedToRepeatPrepare = false; this.isBTVideo = false; this.isBTVideoPlaying = false; this.orientation = 1; this.mHasReportedData = false; this.hadOMPause = false; init(); } private void init() { try { initView(); initPlayer(); } catch (Exception e) { af.b(TAG, e.getMessage()); } } private void initPlayer() { this.mVideoFeedsPlayer = new VideoFeedsPlayer(); } public void addSurfaceView() { try { af.c(TAG, "addSurfaceView"); SurfaceView surfaceView = new SurfaceView(getContext().getApplicationContext()); SurfaceHolder holder = surfaceView.getHolder(); this.mSurfaceHolder = holder; holder.setType(3); this.mSurfaceHolder.setKeepScreenOn(true); this.mSurfaceHolder.addCallback(new MySurfaceHoldeCallback()); this.mLlSurContainer.addView(surfaceView, -1, -1); } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void removeSurface() { try { af.c(TAG, "removeSurface"); this.mLlSurContainer.removeAllViews(); } catch (Exception e) { af.b(TAG, e.getMessage()); } } private void initView() { View inflate = LayoutInflater.from(getContext()).inflate(x.a(getContext(), "mbridge_playercommon_player_view", TtmlNode.TAG_LAYOUT), (ViewGroup) null); if (inflate != null) { this.mLlSurContainer = (LinearLayout) inflate.findViewById(x.a(getContext(), "mbridge_playercommon_ll_sur_container", "id")); this.mLoadingView = (LinearLayout) inflate.findViewById(x.a(getContext(), "mbridge_playercommon_ll_loading", "id")); addSurfaceView(); addView(inflate, -1, -1); } } public boolean initVFPData(String str, String str2, VideoPlayerStatusListener videoPlayerStatusListener) { if (TextUtils.isEmpty(str)) { af.c(TAG, "playUrl==null"); return false; } this.mPlayUrl = str; this.mVideoFeedsPlayer.initPlayer(getContext(), this.mLoadingView, str, videoPlayerStatusListener); this.mInitState = true; return true; } public boolean playVideo(int i) { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer == null) { af.c(TAG, "player init error 播放失败"); return false; } if (!this.mInitState) { af.c(TAG, "vfp init failed 播放失败"); return false; } videoFeedsPlayer.play(this.mPlayUrl, i); this.mIsNeedToRepeatPrepare = false; return true; } catch (Throwable th) { af.b(TAG, th.getMessage(), th); return false; } } public boolean playVideo() { return playVideo(0); } public float getVolume() { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { return videoFeedsPlayer.getVolume(); } return 0.0f; } public void onPause() { try { pause(); VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.setIsFrontDesk(false); } } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void pause() { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.pause(); } pauseOmsdk(); } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void pauseOmsdk() { try { if (this.videoEvents == null || this.hadOMPause) { return; } af.a("omsdk", "play view: pause"); this.hadOMPause = true; this.videoEvents.pause(); } catch (Exception e) { throw new RuntimeException(e); } } public void resumeOMSDK() { try { MediaEvents mediaEvents = this.videoEvents; if (mediaEvents != null) { this.hadOMPause = false; mediaEvents.resume(); af.a("omsdk", "play view: resume"); } } catch (Exception e) { throw new RuntimeException(e); } } public void resumeStart() { try { start(true); resumeOMSDK(); } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void setDataSource() { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.showLoading(); this.mVideoFeedsPlayer.setDataSource(); this.mIsNeedToRepeatPrepare = false; } } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void start(boolean z) { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer == null || this.mIsCovered) { return; } videoFeedsPlayer.start(z); } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void prepare() { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.prepare(); } } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void start(int i) { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.start(i); } } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void justSeekTo(int i) { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.justSeekTo(i); } } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void seekTo(int i) { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.seekTo(i); } } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void stop() { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.stop(); } if (this.videoEvents != null) { this.videoEvents = null; } } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void openSound() { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.openSound(); } } public void closeSound() { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.closeSound(); } } public void setDesk(boolean z) { this.mVideoFeedsPlayer.setIsFrontDesk(z); } public void onResume() { try { this.mVideoFeedsPlayer.setIsFrontDesk(true); if (this.mVideoFeedsPlayer != null && !this.mIsSurfaceHolderDestoryed && !isComplete() && !this.mIsCovered) { af.c(TAG, "onresume========"); if (this.mVideoFeedsPlayer.hasPrepare()) { resumeStart(); } else { playVideo(0); } } } catch (Exception e) { af.b(TAG, e.getMessage()); } } public void coverUnlockResume() { try { this.mVideoFeedsPlayer.setIsFrontDesk(true); if (this.mVideoFeedsPlayer != null) { af.c(TAG, "coverUnlockResume========"); if (this.mVideoFeedsPlayer.hasPrepare() && !this.mIsNeedToRepeatPrepare) { start(true); } playVideo(0); } } catch (Throwable th) { af.b(TAG, th.getMessage()); } } public void release() { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.releasePlayer(); } if (this.mSurfaceHolder != null) { af.b(TAG, "mSurfaceHolder release"); this.mSurfaceHolder.getSurface().release(); } } catch (Throwable th) { af.b(TAG, th.getMessage()); } } public int getCurPosition() { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { return videoFeedsPlayer.getCurPosition(); } return 0; } catch (Exception e) { af.b(TAG, e.getMessage()); return 0; } } public int getDuration() { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { return videoFeedsPlayer.getDuration(); } return 0; } public class MySurfaceHoldeCallback implements SurfaceHolder.Callback { private MySurfaceHoldeCallback() { } @Override // android.view.SurfaceHolder.Callback public void surfaceCreated(SurfaceHolder surfaceHolder) { try { af.c(PlayerView.TAG, "surfaceCreated"); if (PlayerView.this.mVideoFeedsPlayer == null || surfaceHolder == null) { return; } PlayerView.this.mSurfaceHolder = surfaceHolder; PlayerView.this.mVideoFeedsPlayer.setDisplay(surfaceHolder); } catch (Exception e) { af.b(PlayerView.TAG, e.getMessage()); } } @Override // android.view.SurfaceHolder.Callback public void surfaceDestroyed(SurfaceHolder surfaceHolder) { try { af.c(PlayerView.TAG, "surfaceDestroyed "); PlayerView.this.mIsSurfaceHolderDestoryed = true; PlayerView.this.mIsNeedToRepeatPrepare = true; PlayerView.this.mVideoFeedsPlayer.pause(); PlayerView.this.pauseOmsdk(); } catch (Exception e) { af.b(PlayerView.TAG, e.getMessage()); } } @Override // android.view.SurfaceHolder.Callback public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) { try { af.c(PlayerView.TAG, "surfaceChanged"); if (PlayerView.this.mIsSurfaceHolderDestoryed && !PlayerView.this.mIsCovered && !PlayerView.this.isComplete() && !PlayerView.this.isBTVideo && !b.c) { if (PlayerView.this.mVideoFeedsPlayer.hasPrepare()) { af.c(PlayerView.TAG, "surfaceChanged start===="); PlayerView.this.resumeStart(); } else { af.c(PlayerView.TAG, "surfaceChanged PLAY===="); PlayerView.this.playVideo(0); PlayerView.this.resumeOMSDK(); } if (PlayerView.this.isBTVideo) { if (PlayerView.this.isBTVideoPlaying) { if (!PlayerView.this.mVideoFeedsPlayer.hasPrepare()) { PlayerView.this.mVideoFeedsPlayer.prepare(); } PlayerView.this.mVideoFeedsPlayer.start(false); PlayerView.this.resumeOMSDK(); } else { PlayerView.this.pause(); } } } PlayerView.this.mIsSurfaceHolderDestoryed = false; } catch (Exception e) { af.b(PlayerView.TAG, e.getMessage()); } } } public boolean isComplete() { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { return videoFeedsPlayer.isComplete(); } return false; } catch (Throwable th) { af.b(TAG, th.getMessage(), th); return false; } } public void initBufferIngParam(int i) { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.initBufferIngParam(i); } } public boolean isPlayIng() { try { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { return videoFeedsPlayer.isPlayIng(); } return false; } catch (Throwable th) { af.b(TAG, th.getMessage()); return false; } } public void setIsCovered(boolean z) { try { this.mIsCovered = z; af.b(TAG, "mIsCovered:" + z); } catch (Exception e) { af.b(TAG, e.getMessage()); } } public boolean isSilent() { return this.mVideoFeedsPlayer.isSilent(); } public void setVolume(float f, float f2) { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.setVolume(f, f2); } } public void setPlaybackParams(float f) { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.setPlaybackParams(f); } } @Override // android.view.ViewGroup public boolean onInterceptTouchEvent(MotionEvent motionEvent) { this.xInScreen = motionEvent.getRawX(); this.yInScreen = motionEvent.getRawY(); return super.onInterceptTouchEvent(motionEvent); } public JSONObject buildH5JsonObject(int i) { JSONObject jSONObject; JSONObject jSONObject2 = new JSONObject(); try { jSONObject = new JSONObject(); } catch (JSONException e) { e = e; } try { jSONObject.put(a.h, ak.b(c.m().c(), this.xInScreen)); jSONObject.put(a.i, ak.b(c.m().c(), this.yInScreen)); jSONObject.put(a.m, i); try { this.orientation = getContext().getResources().getConfiguration().orientation; } catch (Exception e2) { e2.printStackTrace(); } jSONObject.put(a.k, this.orientation); jSONObject.put(a.l, ak.d(getContext())); return jSONObject; } catch (JSONException e3) { e = e3; jSONObject2 = jSONObject; e.printStackTrace(); return jSONObject2; } } @Override // android.view.View public void onVisibilityChanged(View view, int i) { super.onVisibilityChanged(view, i); try { if (ah.a().a("i_l_s_t_r_i", false) && i == 0 && !this.mHasReportedData) { this.mHasReportedData = true; OnPlayerViewVisibleListener onPlayerViewVisibleListener = this.onPlayerViewVisibleListener; if (onPlayerViewVisibleListener != null) { onPlayerViewVisibleListener.playerViewVisibleCallback(); } } } catch (Exception e) { e.printStackTrace(); } } public void seekToEndFrame() { VideoFeedsPlayer videoFeedsPlayer = this.mVideoFeedsPlayer; if (videoFeedsPlayer != null) { videoFeedsPlayer.seekToEndFrame(); } } }