jimu-decompiled/sources/com/bottle/hp/album/capture/VideoPlayFragment.java
2025-05-13 19:24:51 +02:00

386 lines
12 KiB
Java

package com.bottle.hp.album.capture;
import android.app.Fragment;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.VideoView;
import com.bottle.hp.album.R$id;
import com.bottle.hp.album.R$layout;
import com.bottle.hp.album.Utils;
import com.ubt.jimu.base.mvp.SingleClickListener;
import com.ubtrobot.log.ALog;
import java.lang.ref.WeakReference;
import java.util.Timer;
import java.util.TimerTask;
/* loaded from: classes.dex */
public class VideoPlayFragment extends Fragment implements MediaPlayer.OnCompletionListener, View.OnClickListener, View.OnTouchListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnInfoListener {
private static StaticHandler s;
private Uri b;
private VideoView h;
private ImageView i;
private ProgressBar j;
private TextView k;
private TextView l;
private RelativeLayout m;
private int o;
private IPlayListener p;
private Timer q;
private MediaPlayer.OnPreparedListener r;
private final String a = VideoPlayFragment.class.getSimpleName();
private boolean c = false;
private boolean d = true;
private boolean e = false;
private boolean f = false;
private ImageView.ScaleType g = ImageView.ScaleType.FIT_CENTER;
private long n = 0;
public interface IPlayListener {
void b(String str);
void m0();
void onFinished();
boolean onInfo(MediaPlayer mediaPlayer, int i, int i2);
void onProgress(int i, int i2, int i3);
void v0();
}
private class ProgressTimerTask extends TimerTask {
private ProgressTimerTask() {
}
@Override // java.util.TimerTask, java.lang.Runnable
public void run() {
if (VideoPlayFragment.this.f) {
return;
}
int currentPosition = VideoPlayFragment.this.h.getCurrentPosition();
int duration = VideoPlayFragment.this.h.getDuration();
if (duration <= 0) {
return;
}
int i = (currentPosition * 100) / duration;
VideoPlayFragment.this.o = currentPosition;
VideoPlayFragment.s.sendMessage(VideoPlayFragment.s.obtainMessage(101, i, VideoPlayFragment.this.o, null));
if (VideoPlayFragment.this.p != null) {
VideoPlayFragment.this.p.onProgress(currentPosition, duration, i);
}
}
}
public static class StaticHandler extends Handler {
private final WeakReference<VideoPlayFragment> a;
public StaticHandler(VideoPlayFragment videoPlayFragment) {
this.a = new WeakReference<>(videoPlayFragment);
}
public WeakReference<VideoPlayFragment> a() {
return this.a;
}
}
/* JADX WARN: Multi-variable type inference failed */
@Override // android.app.Fragment
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof IPlayListener) {
this.p = (IPlayListener) context;
}
}
@Override // android.view.View.OnClickListener
public void onClick(View view) {
int id = view.getId();
if (id == R$id.imgPlay) {
b();
} else if (id == R$id.video_view) {
a();
}
}
@Override // android.media.MediaPlayer.OnCompletionListener
public void onCompletion(MediaPlayer mediaPlayer) {
this.f = true;
this.o = 0;
if (this.d) {
this.i.setVisibility(0);
}
Timer timer = this.q;
if (timer != null) {
timer.cancel();
this.q = null;
}
StaticHandler staticHandler = s;
staticHandler.sendMessage(staticHandler.obtainMessage(101, 100, this.h.getDuration(), null));
IPlayListener iPlayListener = this.p;
if (iPlayListener != null) {
iPlayListener.onFinished();
this.p.onProgress(this.h.getCurrentPosition(), this.h.getDuration(), 100);
}
}
@Override // android.app.Fragment
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
s = new StaticHandler(this, this) { // from class: com.bottle.hp.album.capture.VideoPlayFragment.1
@Override // android.os.Handler
public void handleMessage(Message message) {
if (message.what != 101 || a() == null || a().get() == null) {
return;
}
a().get().a(message.arg1);
}
};
new Thread();
if (getArguments() != null) {
this.b = (Uri) getArguments().getParcelable("url");
this.c = getArguments().getBoolean("auto");
this.d = getArguments().getBoolean("show_ui", true);
}
}
@Override // android.app.Fragment
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
View inflate = layoutInflater.inflate(R$layout.video_play_fragment, (ViewGroup) null, false);
this.k = (TextView) inflate.findViewById(R$id.tvCurrent);
this.l = (TextView) inflate.findViewById(R$id.tvDuration);
this.m = (RelativeLayout) inflate.findViewById(R$id.rlProgress);
this.h = (VideoView) inflate.findViewById(R$id.video_view);
this.h.setOnCompletionListener(this);
this.h.setOnTouchListener(this);
this.h.setOnPreparedListener(this);
this.h.setOnErrorListener(this);
if (Build.VERSION.SDK_INT >= 17) {
this.h.setOnInfoListener(this);
}
this.i = (ImageView) inflate.findViewById(R$id.imgPlay);
this.i.setOnClickListener(this);
this.j = (ProgressBar) inflate.findViewById(R$id.progressBar);
if (!this.d) {
this.m.setVisibility(4);
this.i.setVisibility(8);
}
try {
if (this.b != null) {
this.h.setVideoURI(this.b);
}
} catch (Exception e) {
e.printStackTrace();
a(e.getMessage());
}
if (this.c) {
b();
}
return inflate;
}
@Override // android.app.Fragment
public void onDestroy() {
super.onDestroy();
s.removeCallbacksAndMessages(null);
}
@Override // android.app.Fragment
public void onDetach() {
super.onDetach();
Timer timer = this.q;
if (timer != null) {
timer.cancel();
}
}
@Override // android.media.MediaPlayer.OnErrorListener
public boolean onError(MediaPlayer mediaPlayer, int i, int i2) {
a("msg:" + i2);
return true;
}
@Override // android.media.MediaPlayer.OnInfoListener
public boolean onInfo(MediaPlayer mediaPlayer, int i, int i2) {
ALog.a(this.a).d("what:" + i + " extra " + i2);
IPlayListener iPlayListener = this.p;
if (iPlayListener == null) {
return false;
}
iPlayListener.onInfo(mediaPlayer, i, i2);
return false;
}
@Override // android.app.Fragment
public void onPause() {
super.onPause();
this.e = true;
}
@Override // android.media.MediaPlayer.OnPreparedListener
public void onPrepared(MediaPlayer mediaPlayer) {
int b = Utils.b(getActivity());
int a = Utils.a(getActivity());
int videoWidth = mediaPlayer.getVideoWidth();
int videoHeight = mediaPlayer.getVideoHeight();
if (ImageView.ScaleType.FIT_CENTER == this.g) {
if (b > a) {
b = (videoWidth * a) / videoHeight;
} else {
a = (videoHeight * b) / videoWidth;
}
} else if (b <= a) {
a = (videoHeight * b) / videoWidth;
} else if (videoWidth > videoHeight) {
a = (videoHeight * b) / videoWidth;
} else {
b = (videoWidth * a) / videoHeight;
}
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(b, a);
layoutParams.gravity = 17;
this.h.setLayoutParams(layoutParams);
MediaPlayer.OnPreparedListener onPreparedListener = this.r;
if (onPreparedListener != null) {
onPreparedListener.onPrepared(mediaPlayer);
}
}
@Override // android.view.View.OnTouchListener
public boolean onTouch(View view, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (action == 0) {
this.n = System.currentTimeMillis();
ALog.a(this.a).d("action down");
return true;
}
if (action == 1) {
e();
return true;
}
if (action != 2) {
return false;
}
ALog.a(this.a).d("action move");
return false;
}
private void e() {
if (System.currentTimeMillis() - this.n > 500) {
return;
}
if (this.h.isPlaying()) {
a();
} else {
b();
}
ALog.a(this.a).d("action up");
}
public void c() {
a(this.o, true);
}
public static VideoPlayFragment a(Uri uri, boolean z, boolean z2) {
VideoPlayFragment videoPlayFragment = new VideoPlayFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("url", uri);
bundle.putBoolean("auto", z);
bundle.putBoolean("show_ui", z2);
videoPlayFragment.setArguments(bundle);
return videoPlayFragment;
}
public void b() {
if (this.e) {
a(this.o, true);
} else {
a(this.o, false);
}
this.e = false;
}
/* JADX INFO: Access modifiers changed from: private */
public void a(int i) {
this.j.setProgress(i);
this.k.setText(Utils.a(this.h.getCurrentPosition()));
this.l.setText(Utils.a(this.h.getDuration() + SingleClickListener.FAST_CLICK_DELAY_TIME));
if (i == 100) {
this.k.setText(Utils.a(this.h.getDuration() + SingleClickListener.FAST_CLICK_DELAY_TIME));
}
}
private void a(int i, boolean z) {
if (z && !this.f) {
this.h.seekTo(i);
}
this.f = false;
this.h.start();
this.q = new Timer();
this.q.schedule(new ProgressTimerTask(), 10L, 300L);
this.i.setVisibility(8);
IPlayListener iPlayListener = this.p;
if (iPlayListener != null) {
iPlayListener.v0();
}
}
private void a(String str) {
this.i.post(new Runnable() { // from class: com.bottle.hp.album.capture.VideoPlayFragment.2
@Override // java.lang.Runnable
public void run() {
VideoPlayFragment.this.i.setVisibility(4);
}
});
IPlayListener iPlayListener = this.p;
if (iPlayListener != null) {
iPlayListener.b(str);
}
}
public void a(Uri uri) {
if (uri == null) {
a("播放地址为null");
return;
}
Uri uri2 = this.b;
if (uri2 == null || !uri2.equals(uri)) {
this.b = uri;
this.h.setVideoURI(uri);
this.o = 0;
this.l.setText(Utils.a(this.h.getDuration() + SingleClickListener.FAST_CLICK_DELAY_TIME));
this.k.setText(Utils.a(0L));
}
}
public void a() {
this.o = this.h.getCurrentPosition();
if (this.d) {
this.i.setVisibility(0);
}
this.h.pause();
Timer timer = this.q;
if (timer != null) {
timer.cancel();
this.q = null;
}
IPlayListener iPlayListener = this.p;
if (iPlayListener != null) {
iPlayListener.m0();
}
}
}