package com.bottle.hp.album.capture; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import com.baidu.cloud.media.player.IMediaPlayer; import com.bottle.hp.album.R$id; import com.bottle.hp.album.R$layout; import com.bottle.hp.album.R$mipmap; import java.lang.ref.WeakReference; /* loaded from: classes.dex */ public class MediaPlayerActivity extends AppCompatActivity implements SurfaceHolder.Callback, MediaPlayer.OnCompletionListener, MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnInfoListener, View.OnClickListener { private ImageView b; private ImageView c; private SurfaceView d; private ImageView e; private TextView f; private ImageView g; private ProgressBar h; private View i; private TextView j; private MediaPlayer k; private SurfaceHolder l; private String m; private boolean n; private Handler x; private final String a = MediaPlayerActivity.class.getSimpleName(); private int o = 0; private int p = 0; private boolean q = false; private boolean r = false; private boolean s = false; private boolean t = false; private boolean u = false; private Runnable v = new Runnable() { // from class: com.bottle.hp.album.capture.MediaPlayerActivity.2 @Override // java.lang.Runnable public void run() { if (MediaPlayerActivity.this.r) { try { MediaPlayerActivity.this.p = MediaPlayerActivity.this.k.getCurrentPosition(); MediaPlayerActivity.this.a(1, null, MediaPlayerActivity.this.p, 0); MediaPlayerActivity.this.x.postDelayed(MediaPlayerActivity.this.v, 1000L); } catch (Exception e) { e.printStackTrace(); } } } }; private static class StaticHandler extends Handler { private WeakReference a; public StaticHandler(MediaPlayerActivity mediaPlayerActivity) { this.a = new WeakReference<>(mediaPlayerActivity); } public WeakReference a() { return this.a; } @Override // android.os.Handler public void handleMessage(Message message) { if (message.what == 1 && a().get() != null) { a().get().l(message.arg1); } } } private void D0() { this.k = new MediaPlayer(); this.k.setOnCompletionListener(this); this.k.setOnBufferingUpdateListener(this); this.k.setOnErrorListener(this); this.k.setOnPreparedListener(this); this.k.setOnInfoListener(this); this.k.setAudioStreamType(3); this.k.setDisplay(this.l); try { this.k.setDataSource(this.m); this.k.prepareAsync(); } catch (Exception e) { e.printStackTrace(); } } private void E0() { try { if (this.k != null) { this.k.pause(); this.r = false; this.c.setVisibility(0); this.e.setImageResource(R$mipmap.video_start); } } catch (IllegalStateException e) { e.printStackTrace(); } } private void F0() { this.r = false; if (this.k != null) { new Thread(new Runnable() { // from class: com.bottle.hp.album.capture.MediaPlayerActivity.1 @Override // java.lang.Runnable public void run() { MediaPlayerActivity.this.k.release(); } }).start(); } } private void G0() { try { if (this.t) { this.t = false; this.k.seekTo(this.p); this.g.setVisibility(8); } if (!this.s) { this.k.start(); } this.r = true; this.x.postDelayed(this.v, 200L); this.c.setVisibility(8); this.e.setImageResource(R$mipmap.video_stop); } catch (IllegalStateException e) { e.printStackTrace(); } } private void c(View view) { } private void initData() { try { Intent intent = getIntent(); this.m = intent.getStringExtra("uri"); this.n = intent.getBooleanExtra("auto_close", false); } catch (Exception e) { e.printStackTrace(); } } /* JADX INFO: Access modifiers changed from: private */ public void l(int i) { this.h.setProgress(i); int i2 = this.o - i; this.f.setText(String.format("%02d:%02d", Integer.valueOf(i2 / 1000000), Integer.valueOf(i2 / 1000))); } public void initView() { this.b = (ImageView) findViewById(R$id.activity_media_player_img_back); this.b.setOnClickListener(this); this.c = (ImageView) findViewById(R$id.activity_media_player_img_play); this.c.setOnClickListener(this); this.e = (ImageView) findViewById(R$id.activity_media_player_img_start); this.e.setOnClickListener(this); this.d = (SurfaceView) findViewById(R$id.activity_media_player_surface); this.f = (TextView) findViewById(R$id.activity_media_player_tv_reset); this.f.setOnClickListener(this); this.g = (ImageView) findViewById(R$id.activity_media_player_img_snagshot); this.h = (ProgressBar) findViewById(R$id.activity_media_player_pb); this.i = findViewById(R$id.rl_error); this.j = (TextView) findViewById(R$id.tv_retry); this.j.setOnClickListener(this); this.l = this.d.getHolder(); this.l.addCallback(this); this.l.setFixedSize(320, 220); } @Override // android.media.MediaPlayer.OnBufferingUpdateListener public void onBufferingUpdate(MediaPlayer mediaPlayer, int i) { } @Override // android.view.View.OnClickListener public void onClick(View view) { int id = view.getId(); if (id == R$id.activity_media_player_img_back) { a(view); return; } if (id == R$id.tv_retry) { d(view); return; } if (id == R$id.activity_media_player_img_start) { e(view); } else if (id == R$id.activity_media_player_img_play) { b(view); } else if (id == R$id.activity_media_player_tv_reset) { c(view); } } @Override // android.media.MediaPlayer.OnCompletionListener public void onCompletion(MediaPlayer mediaPlayer) { this.r = false; this.p = this.o; this.e.setImageResource(R$mipmap.video_start); a(1, null, this.o, 0); if (this.u) { this.u = false; } else { this.c.setVisibility(0); } try { if (this.n) { finish(); } } catch (Exception e) { e.printStackTrace(); } } @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.core.app.ComponentActivity, android.app.Activity protected void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R$layout.activity_media_player); this.x = new StaticHandler(this); initView(); initData(); if (bundle != null) { this.p = bundle.getInt("currentPosition"); this.s = bundle.getBoolean("isPause"); } } @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity protected void onDestroy() { this.x.removeCallbacksAndMessages(null); super.onDestroy(); } @Override // android.media.MediaPlayer.OnErrorListener public boolean onError(MediaPlayer mediaPlayer, int i, int i2) { Log.e(this.a, "onError:" + i + "-" + i2); this.i.setVisibility(0); this.u = true; this.k.reset(); return false; } @Override // android.media.MediaPlayer.OnInfoListener public boolean onInfo(MediaPlayer mediaPlayer, int i, int i2) { Log.e(this.a, "onInfo:" + i + "-" + i2); if (i == -1004) { Log.e(this.a, "media error io"); return false; } if (i == -110) { Log.e(this.a, "media error timeout"); return false; } if (i == 1) { Log.i(this.a, "media info unknown"); return false; } switch (i) { case IMediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING /* 700 */: Log.i(this.a, "media info video track lagging"); break; case IMediaPlayer.MEDIA_INFO_BUFFERING_START /* 701 */: Log.i(this.a, "media info video buffering start"); break; case IMediaPlayer.MEDIA_INFO_BUFFERING_END /* 702 */: Log.i(this.a, "media info buffering end"); break; default: switch (i) { case 800: Log.i(this.a, "media info bad interleaving"); break; case IMediaPlayer.MEDIA_INFO_NOT_SEEKABLE /* 801 */: Log.i(this.a, "media info not seekable"); break; case IMediaPlayer.MEDIA_INFO_METADATA_UPDATE /* 802 */: Log.i(this.a, "media info metadata update"); break; } } return false; } @Override // androidx.appcompat.app.AppCompatActivity, android.app.Activity, android.view.KeyEvent.Callback public boolean onKeyDown(int i, KeyEvent keyEvent) { if (i != 4) { return super.onKeyDown(i, keyEvent); } F0(); finish(); return true; } @Override // androidx.fragment.app.FragmentActivity, android.app.Activity protected void onPause() { E0(); super.onPause(); } @Override // android.media.MediaPlayer.OnPreparedListener public void onPrepared(MediaPlayer mediaPlayer) { try { this.o = this.k.getDuration(); this.h.setMax(this.o); this.q = true; this.r = true; G0(); } catch (Exception e) { e.printStackTrace(); } } @Override // androidx.fragment.app.FragmentActivity, android.app.Activity protected void onResume() { this.t = true; super.onResume(); } @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.core.app.ComponentActivity, android.app.Activity protected void onSaveInstanceState(Bundle bundle) { bundle.putInt("currentPosition", this.p); bundle.putBoolean("isPause", this.s); super.onSaveInstanceState(bundle); } @Override // android.view.SurfaceHolder.Callback public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) { } @Override // android.view.SurfaceHolder.Callback public void surfaceCreated(SurfaceHolder surfaceHolder) { D0(); } @Override // android.view.SurfaceHolder.Callback public void surfaceDestroyed(SurfaceHolder surfaceHolder) { } private void d(View view) { this.i.setVisibility(8); try { this.k.reset(); this.k.setDataSource(this.m); this.k.prepareAsync(); } catch (Exception e) { e.printStackTrace(); } } private void e(View view) { MediaPlayer mediaPlayer = this.k; if (mediaPlayer != null && this.q) { if (mediaPlayer.isPlaying()) { this.s = true; E0(); } else { this.s = false; G0(); } } } private void a(View view) { F0(); finish(); } private void b(View view) { e((View) null); } protected void a(int i, Object obj, int i2, int i3) { Handler handler = this.x; if (handler != null) { handler.sendMessage(handler.obtainMessage(i, i2, i3, obj)); } } }