270 lines
9.6 KiB
Java
270 lines
9.6 KiB
Java
package com.ubt.jimu.widgets.player.bar;
|
|
|
|
import android.content.Context;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.SeekBar;
|
|
import android.widget.TextView;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.widgets.player.FullScreenSwitchoverListener;
|
|
import com.ubt.jimu.widgets.player.widget.BDCloudVideoView;
|
|
import com.ubtrobot.log.ALog;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class SimpleMediaController extends RelativeLayout {
|
|
private TextView a;
|
|
private SeekBar b;
|
|
private TextView c;
|
|
private Timer d;
|
|
private Handler e;
|
|
private long f;
|
|
private BDCloudVideoView g;
|
|
boolean h;
|
|
private TextView i;
|
|
private View j;
|
|
private boolean k;
|
|
private long l;
|
|
|
|
public SimpleMediaController(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.e = new Handler(Looper.getMainLooper());
|
|
this.g = null;
|
|
this.h = false;
|
|
this.k = false;
|
|
this.l = 0L;
|
|
c();
|
|
}
|
|
|
|
public boolean getIsDragging() {
|
|
return this.h;
|
|
}
|
|
|
|
public Handler getMainThreadHandler() {
|
|
return this.e;
|
|
}
|
|
|
|
public long getPreviousProgress() {
|
|
return this.f;
|
|
}
|
|
|
|
public void setCache(int i) {
|
|
SeekBar seekBar = this.b;
|
|
if (seekBar == null || i == seekBar.getSecondaryProgress()) {
|
|
return;
|
|
}
|
|
this.b.setSecondaryProgress(i);
|
|
}
|
|
|
|
public void setFullScreenSwitchoverListener(FullScreenSwitchoverListener fullScreenSwitchoverListener) {
|
|
}
|
|
|
|
public void setMax(int i) {
|
|
if (this.k) {
|
|
return;
|
|
}
|
|
SeekBar seekBar = this.b;
|
|
if (seekBar != null) {
|
|
seekBar.setMax(i);
|
|
}
|
|
b(i);
|
|
if (i > 0) {
|
|
this.k = true;
|
|
}
|
|
}
|
|
|
|
public void setMediaPlayerControl(BDCloudVideoView bDCloudVideoView) {
|
|
this.g = bDCloudVideoView;
|
|
}
|
|
|
|
public void setProgress(int i) {
|
|
if (this.b != null) {
|
|
this.f = this.g.getCurrentPosition();
|
|
this.b.setProgress(i);
|
|
}
|
|
}
|
|
|
|
public void setTitle(String str) {
|
|
this.j.setVisibility(0);
|
|
this.i.setVisibility(0);
|
|
this.i.setText(str);
|
|
}
|
|
|
|
private void c() {
|
|
View inflate = ((LayoutInflater) getContext().getSystemService("layout_inflater")).inflate(R.layout.layout_simple_controller, this);
|
|
this.i = (TextView) inflate.findViewById(R.id.tv_content);
|
|
this.j = inflate.findViewById(R.id.view_background);
|
|
this.a = (TextView) inflate.findViewById(R.id.tv_position);
|
|
this.b = (SeekBar) inflate.findViewById(R.id.seekbar);
|
|
this.b.setMax(0);
|
|
this.c = (TextView) inflate.findViewById(R.id.tv_duration);
|
|
this.b.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { // from class: com.ubt.jimu.widgets.player.bar.SimpleMediaController.1
|
|
@Override // android.widget.SeekBar.OnSeekBarChangeListener
|
|
public void onProgressChanged(SeekBar seekBar, int i, boolean z) {
|
|
SimpleMediaController.this.c(i);
|
|
}
|
|
|
|
@Override // android.widget.SeekBar.OnSeekBarChangeListener
|
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
SimpleMediaController.this.h = true;
|
|
}
|
|
|
|
@Override // android.widget.SeekBar.OnSeekBarChangeListener
|
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
if (SimpleMediaController.this.g.getDuration() > 0) {
|
|
SimpleMediaController.this.l = seekBar.getProgress();
|
|
if (SimpleMediaController.this.g != null) {
|
|
SimpleMediaController.this.g.seekTo(seekBar.getProgress());
|
|
}
|
|
}
|
|
SimpleMediaController.this.h = false;
|
|
}
|
|
});
|
|
a(false);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void d() {
|
|
Timer timer = this.d;
|
|
if (timer != null) {
|
|
timer.cancel();
|
|
this.d = null;
|
|
}
|
|
this.d = new Timer();
|
|
this.d.schedule(new TimerTask() { // from class: com.ubt.jimu.widgets.player.bar.SimpleMediaController.3
|
|
@Override // java.util.TimerTask, java.lang.Runnable
|
|
public void run() {
|
|
SimpleMediaController.this.e.post(new Runnable() { // from class: com.ubt.jimu.widgets.player.bar.SimpleMediaController.3.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
SimpleMediaController.this.b();
|
|
}
|
|
});
|
|
}
|
|
}, 0L, 500L);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void e() {
|
|
Timer timer = this.d;
|
|
if (timer != null) {
|
|
timer.cancel();
|
|
this.d = null;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void b(int i) {
|
|
TextView textView = this.c;
|
|
if (textView != null) {
|
|
textView.setText(a(i));
|
|
}
|
|
}
|
|
|
|
public void a() {
|
|
final BDCloudVideoView.PlayerState currentPlayerState = this.g.getCurrentPlayerState();
|
|
ALog.a("SimpleMediaController").d("mediaController: changeStatus=" + currentPlayerState.name());
|
|
this.k = false;
|
|
this.e.post(new Runnable() { // from class: com.ubt.jimu.widgets.player.bar.SimpleMediaController.2
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
BDCloudVideoView.PlayerState playerState = currentPlayerState;
|
|
if (playerState == BDCloudVideoView.PlayerState.STATE_IDLE || playerState == BDCloudVideoView.PlayerState.STATE_ERROR) {
|
|
SimpleMediaController.this.e();
|
|
SimpleMediaController.this.b.setEnabled(false);
|
|
SimpleMediaController simpleMediaController = SimpleMediaController.this;
|
|
simpleMediaController.c(simpleMediaController.g == null ? 0 : SimpleMediaController.this.g.getCurrentPosition());
|
|
SimpleMediaController simpleMediaController2 = SimpleMediaController.this;
|
|
simpleMediaController2.b(simpleMediaController2.g != null ? SimpleMediaController.this.g.getDuration() : 0);
|
|
return;
|
|
}
|
|
if (playerState == BDCloudVideoView.PlayerState.STATE_PREPARING) {
|
|
SimpleMediaController.this.b.setEnabled(false);
|
|
return;
|
|
}
|
|
if (playerState == BDCloudVideoView.PlayerState.STATE_PREPARED) {
|
|
SimpleMediaController.this.b.setEnabled(true);
|
|
SimpleMediaController simpleMediaController3 = SimpleMediaController.this;
|
|
simpleMediaController3.b(simpleMediaController3.g != null ? SimpleMediaController.this.g.getDuration() : 0);
|
|
SimpleMediaController.this.b.setMax(SimpleMediaController.this.g.getDuration());
|
|
return;
|
|
}
|
|
if (playerState == BDCloudVideoView.PlayerState.STATE_PLAYBACK_COMPLETED) {
|
|
SimpleMediaController.this.e();
|
|
SimpleMediaController.this.b.setProgress(SimpleMediaController.this.b.getMax());
|
|
SimpleMediaController.this.b.setEnabled(false);
|
|
} else if (playerState != BDCloudVideoView.PlayerState.STATE_PLAYING) {
|
|
BDCloudVideoView.PlayerState playerState2 = BDCloudVideoView.PlayerState.STATE_PAUSED;
|
|
} else {
|
|
SimpleMediaController.this.d();
|
|
SimpleMediaController.this.b.setEnabled(true);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public boolean b() {
|
|
int duration;
|
|
BDCloudVideoView bDCloudVideoView = this.g;
|
|
if (bDCloudVideoView == null) {
|
|
return false;
|
|
}
|
|
long currentPosition = bDCloudVideoView.getCurrentPosition();
|
|
long j = this.l;
|
|
if (currentPosition > 0 && !getIsDragging()) {
|
|
this.l = currentPosition;
|
|
}
|
|
if (getVisibility() == 0 && !getIsDragging() && (duration = this.g.getDuration()) > 0) {
|
|
setMax(duration);
|
|
if (j != currentPosition) {
|
|
setProgress((int) currentPosition);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public SimpleMediaController(Context context) {
|
|
super(context);
|
|
this.e = new Handler(Looper.getMainLooper());
|
|
this.g = null;
|
|
this.h = false;
|
|
this.k = false;
|
|
this.l = 0L;
|
|
c();
|
|
}
|
|
|
|
private String a(int i) {
|
|
int i2 = i / 1000;
|
|
int i3 = i2 / 3600;
|
|
int i4 = (i2 % 3600) / 60;
|
|
int i5 = i2 % 60;
|
|
return i3 != 0 ? String.format("%02d:%02d:%02d", Integer.valueOf(i3), Integer.valueOf(i4), Integer.valueOf(i5)) : String.format("%02d:%02d", Integer.valueOf(i4), Integer.valueOf(i5));
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void c(int i) {
|
|
TextView textView = this.a;
|
|
if (textView != null) {
|
|
textView.setText(a(i));
|
|
}
|
|
}
|
|
|
|
public void a(boolean z) {
|
|
this.b.setEnabled(z);
|
|
}
|
|
|
|
public void a(final long j) {
|
|
this.e.post(new Runnable() { // from class: com.ubt.jimu.widgets.player.bar.SimpleMediaController.4
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
SimpleMediaController.this.setCache((int) j);
|
|
}
|
|
});
|
|
}
|
|
}
|