package com.ubt.jimu.widgets.player; import android.content.Context; import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.Toast; import com.baidu.cloud.media.player.IMediaPlayer; import com.ubt.jimu.R; import com.ubt.jimu.utils.LogUtils; import com.ubt.jimu.widgets.player.bar.SimpleMediaController; import com.ubt.jimu.widgets.player.widget.BDCloudVideoView; /* loaded from: classes2.dex */ public class UbtPlayerView extends RelativeLayout implements IMediaPlayer.OnPreparedListener, IMediaPlayer.OnCompletionListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnInfoListener, IMediaPlayer.OnBufferingUpdateListener, BDCloudVideoView.OnPlayerStateListener, FullScreenSwitchoverListener, View.OnClickListener { private String a; private String b; private SimpleMediaController c; private RelativeLayout d; private Context e; private BDCloudVideoView f; private String g; private Toast h; private RelativeLayout i; private RelativeLayout j; private ImageView k; private ImageView l; private boolean m; private VideoErrorListener n; public interface VideoErrorListener { void j(int i); } public UbtPlayerView(Context context) { this(context, null); } private void h() { this.k.setOnClickListener(this); } private void i() { BDCloudVideoView.setAppId(this.b); BDCloudVideoView.setAK(this.a); this.f = new BDCloudVideoView(this.e); this.f.setOnPreparedListener(this); this.f.setOnCompletionListener(this); this.f.setOnErrorListener(this); this.f.setOnInfoListener(this); this.f.setOnBufferingUpdateListener(this); this.f.setOnPlayerStateListener(this); } private void j() { this.i = (RelativeLayout) ((LayoutInflater) getContext().getSystemService("layout_inflater")).inflate(R.layout.layout_ubt_player, this); this.d = (RelativeLayout) this.i.findViewById(R.id.rl_player_container); this.j = (RelativeLayout) this.i.findViewById(R.id.rl_normalscreen_controller); this.c = (SimpleMediaController) findViewById(R.id.media_controller_bar); this.k = (ImageView) findViewById(R.id.playButton); this.l = (ImageView) findViewById(R.id.im_cover); this.c.setFullScreenSwitchoverListener(this); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -1); layoutParams.addRule(13); this.d.addView(this.f, layoutParams); this.c.setMediaPlayerControl(this.f); this.f.setLogEnabled(true); this.f.setMaxProbeTime(2000); this.f.setTimeoutInUs(1000000); this.i.setEnabled(false); this.i.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.widgets.player.UbtPlayerView.1 @Override // android.view.View.OnClickListener public void onClick(View view) { UbtPlayerView.this.a(); } }); } @Override // com.ubt.jimu.widgets.player.widget.BDCloudVideoView.OnPlayerStateListener public void a(BDCloudVideoView.PlayerState playerState) { SimpleMediaController simpleMediaController = this.c; if (simpleMediaController != null) { simpleMediaController.a(); } BDCloudVideoView bDCloudVideoView = this.f; if (bDCloudVideoView == null) { return; } BDCloudVideoView.PlayerState currentPlayerState = bDCloudVideoView.getCurrentPlayerState(); if (currentPlayerState == BDCloudVideoView.PlayerState.STATE_PLAYING) { this.i.setEnabled(true); this.k.setVisibility(8); } if (this.m && currentPlayerState == BDCloudVideoView.PlayerState.STATE_PLAYING) { this.m = false; this.f.pause(); this.k.setVisibility(0); } } public void b() { BDCloudVideoView bDCloudVideoView = this.f; if (bDCloudVideoView != null) { bDCloudVideoView.pause(); } } public void c() { BDCloudVideoView bDCloudVideoView; if (this.k.getVisibility() != 8 || (bDCloudVideoView = this.f) == null) { return; } bDCloudVideoView.start(); } public void d() { RelativeLayout relativeLayout = this.d; if (relativeLayout == null) { return; } relativeLayout.removeAllViews(); this.j.removeAllViews(); BDCloudVideoView bDCloudVideoView = this.f; if (bDCloudVideoView != null) { this.d.addView(bDCloudVideoView); } this.j.addView(this.c); } public void e() { BDCloudVideoView bDCloudVideoView = this.f; if (bDCloudVideoView != null) { bDCloudVideoView.seekTo((int) this.c.getPreviousProgress()); this.f.start(); } } public void f() { if (TextUtils.isEmpty(this.g)) { this.h = Toast.makeText(this.e, "播放错误:视频播发源出错(001)", 0); this.h.show(); } else { this.m = false; this.f.setVideoPath(this.g); this.f.start(); } } public void g() { BDCloudVideoView bDCloudVideoView = this.f; if (bDCloudVideoView != null) { bDCloudVideoView.b(); } BDCloudVideoView bDCloudVideoView2 = this.f; if (bDCloudVideoView2 != null) { bDCloudVideoView2.e(); this.f.d(); } this.f = null; Toast toast = this.h; if (toast != null) { toast.cancel(); } } public long getCurrentPosition() { if (this.f != null) { return r0.getCurrentPosition(); } return -1L; } @Override // com.baidu.cloud.media.player.IMediaPlayer.OnBufferingUpdateListener public void onBufferingUpdate(IMediaPlayer iMediaPlayer, int i) { BDCloudVideoView bDCloudVideoView; SimpleMediaController simpleMediaController = this.c; if (simpleMediaController == null || (bDCloudVideoView = this.f) == null) { return; } simpleMediaController.a((i * bDCloudVideoView.getDuration()) / 100); } @Override // android.view.View.OnClickListener public void onClick(View view) { LogUtils.c("开始播放"); if (view.getId() != R.id.playButton) { return; } this.k.setVisibility(8); this.l.setVisibility(8); BDCloudVideoView bDCloudVideoView = this.f; if (bDCloudVideoView != null) { this.m = false; bDCloudVideoView.start(); } } @Override // com.baidu.cloud.media.player.IMediaPlayer.OnCompletionListener public void onCompletion(IMediaPlayer iMediaPlayer) { this.k.setVisibility(0); this.l.setVisibility(0); this.m = true; } @Override // com.baidu.cloud.media.player.IMediaPlayer.OnErrorListener public boolean onError(IMediaPlayer iMediaPlayer, int i, int i2) { VideoErrorListener videoErrorListener = this.n; if (videoErrorListener == null) { return true; } videoErrorListener.j(i); return true; } @Override // com.baidu.cloud.media.player.IMediaPlayer.OnInfoListener public boolean onInfo(IMediaPlayer iMediaPlayer, int i, int i2) { if (i == 701) { this.i.setEnabled(false); this.k.setVisibility(8); } else if (i == 702 && this.c != null) { this.i.setEnabled(true); this.k.setVisibility(8); BDCloudVideoView bDCloudVideoView = this.f; if (bDCloudVideoView != null) { bDCloudVideoView.start(); } } return false; } @Override // com.baidu.cloud.media.player.IMediaPlayer.OnPreparedListener public void onPrepared(IMediaPlayer iMediaPlayer) { if (this.f == null) { } } public void setTitle(String str) { this.c.setTitle(str); } public void setVideoErrorListener(VideoErrorListener videoErrorListener) { this.n = videoErrorListener; } public void setVideoPath(String str) { this.g = str; } public UbtPlayerView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); } public UbtPlayerView(Context context, AttributeSet attributeSet, int i) { this(context, attributeSet, i, 0); } public UbtPlayerView(Context context, AttributeSet attributeSet, int i, int i2) { super(context, attributeSet, i, i2); this.a = "637ccdcd7133452fab2cd63c0ad326e7"; this.b = "83120902010953728101p"; this.f = null; this.e = context; i(); j(); h(); } public void a() { BDCloudVideoView bDCloudVideoView = this.f; if (bDCloudVideoView == null) { return; } if (bDCloudVideoView.isPlaying()) { this.k.setVisibility(0); this.f.pause(); } else { this.k.setVisibility(8); this.l.setVisibility(8); this.f.start(); } } }