182 lines
6.1 KiB
Java
182 lines
6.1 KiB
Java
package com.ubt.jimu.video;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
import com.ubt.jimu.video.Configuration;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class VideoCompressUtils implements OnCompressListener {
|
|
private static VideoCompressUtils h;
|
|
private ExecutorService a;
|
|
private ExecutorService b;
|
|
private final LinkedBlockingQueue c;
|
|
private Context d;
|
|
private OnCompressListener e;
|
|
private volatile boolean f;
|
|
private volatile float g;
|
|
|
|
private VideoCompressUtils(Context context) {
|
|
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
|
|
this.c = new LinkedBlockingQueue();
|
|
if (context == null) {
|
|
throw new NullPointerException("Context 不能为null");
|
|
}
|
|
this.d = context;
|
|
}
|
|
|
|
private void a(int i) {
|
|
ExecutorService executorService = this.b;
|
|
if (executorService == null || executorService.isShutdown()) {
|
|
if (i >= 0) {
|
|
}
|
|
this.b = Executors.newSingleThreadExecutor();
|
|
LogUtils.c("创建请求线程");
|
|
}
|
|
}
|
|
|
|
private void b() {
|
|
ExecutorService executorService = this.a;
|
|
if (executorService == null || executorService.isShutdown()) {
|
|
this.a = Executors.newSingleThreadExecutor();
|
|
LogUtils.c("创建结果监听线程");
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.video.OnCompressListener
|
|
public void onAllCompressFail() {
|
|
a();
|
|
OnCompressListener onCompressListener = this.e;
|
|
if (onCompressListener != null) {
|
|
onCompressListener.onAllCompressFail();
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.video.OnCompressListener
|
|
public void onAllCompressSuccess() {
|
|
LogUtils.c("所有视频压缩成功");
|
|
OnCompressListener onCompressListener = this.e;
|
|
if (onCompressListener != null) {
|
|
onCompressListener.onAllCompressSuccess();
|
|
}
|
|
this.f = false;
|
|
}
|
|
|
|
@Override // com.ubt.jimu.video.OnCompressListener
|
|
public void onFail(boolean z) {
|
|
OnCompressListener onCompressListener = this.e;
|
|
if (onCompressListener != null) {
|
|
onCompressListener.onFail(z);
|
|
}
|
|
a();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.video.OnCompressListener
|
|
public void onProgress(float f) {
|
|
if (this.e != null) {
|
|
this.g += f;
|
|
this.e.onProgress(this.g * 100.0f);
|
|
LogUtils.c(Thread.currentThread().getName() + " ~~~~~ " + Math.round(this.g * 100.0f));
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.video.OnCompressListener
|
|
public void onSuccess(Configuration configuration) {
|
|
LogUtils.c("压缩成功:" + configuration);
|
|
OnCompressListener onCompressListener = this.e;
|
|
if (onCompressListener != null) {
|
|
onCompressListener.onSuccess(configuration);
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.video.OnCompressListener
|
|
public void prepareCompress() {
|
|
LogUtils.c("准备压缩");
|
|
OnCompressListener onCompressListener = this.e;
|
|
if (onCompressListener != null) {
|
|
onCompressListener.prepareCompress();
|
|
}
|
|
}
|
|
|
|
public static synchronized VideoCompressUtils a(Context context) {
|
|
VideoCompressUtils videoCompressUtils;
|
|
synchronized (VideoCompressUtils.class) {
|
|
if (h == null) {
|
|
h = new VideoCompressUtils(context);
|
|
}
|
|
videoCompressUtils = h;
|
|
}
|
|
return videoCompressUtils;
|
|
}
|
|
|
|
public void a(List<Configuration> list, OnCompressListener onCompressListener) {
|
|
this.e = onCompressListener;
|
|
if (this.f) {
|
|
return;
|
|
}
|
|
this.f = true;
|
|
synchronized (this.c) {
|
|
prepareCompress();
|
|
ArrayList arrayList = new ArrayList();
|
|
this.g = 0.0f;
|
|
if (this.d != null) {
|
|
if (list != null && list.size() != 0) {
|
|
a(list.size());
|
|
for (int i = 0; i < list.size(); i++) {
|
|
Configuration configuration = list.get(i);
|
|
if (configuration != null) {
|
|
a(configuration, arrayList);
|
|
}
|
|
}
|
|
if (arrayList.size() == 0 && list.size() != 0 && onCompressListener != null) {
|
|
onCompressListener.onAllCompressSuccess();
|
|
return;
|
|
}
|
|
b();
|
|
StartCompressMonitor startCompressMonitor = new StartCompressMonitor(this.b, arrayList, this);
|
|
LogUtils.c("111111111111111");
|
|
this.a.submit(startCompressMonitor);
|
|
LogUtils.c("2222222222222222");
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
throw new NullPointerException("Context 不能为null");
|
|
}
|
|
}
|
|
|
|
private void a(Configuration configuration, List<Callable<Configuration>> list) {
|
|
if (!TextUtils.isEmpty(configuration.a) && !TextUtils.isEmpty(configuration.b)) {
|
|
list.add(new VideoCompressTask(this.d, configuration, this));
|
|
return;
|
|
}
|
|
OnCompressListener onCompressListener = this.e;
|
|
if (onCompressListener != null) {
|
|
configuration.d = Configuration.CompressState.FAIL;
|
|
configuration.e = "视频输入或者输出路径错误/为空";
|
|
onCompressListener.onFail(true);
|
|
}
|
|
}
|
|
|
|
public void a() {
|
|
ExecutorService executorService = this.b;
|
|
if (executorService != null && !executorService.isShutdown()) {
|
|
this.b.shutdownNow();
|
|
}
|
|
ExecutorService executorService2 = this.a;
|
|
if (executorService2 != null && !executorService2.isShutdown()) {
|
|
this.a.shutdownNow();
|
|
}
|
|
this.f = false;
|
|
this.b = null;
|
|
this.a = null;
|
|
}
|
|
}
|