-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathFFprobe.java
More file actions
86 lines (69 loc) · 2.59 KB
/
FFprobe.java
File metadata and controls
86 lines (69 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package nl.bravobit.ffmpeg;
import android.content.Context;
import android.os.AsyncTask;
import java.io.File;
import java.util.Map;
public class FFprobe implements FFbinaryInterface {
private final FFbinaryContextProvider context;
private static final long MINIMUM_TIMEOUT = 10 * 1000;
private long timeout = Long.MAX_VALUE;
private static FFprobe instance = null;
private FFprobe(FFbinaryContextProvider context) {
this.context = context;
Log.setDebug(Util.isDebug(this.context.provide()));
}
public static FFprobe getInstance(final Context context) {
if (instance == null) {
instance = new FFprobe(new FFbinaryContextProvider() {
@Override
public Context provide() {
return context;
}
});
}
return instance;
}
@Override
public boolean isSupported() {
// get ffprobe file
File ffprobe = FileUtils.getFFprobe(context.provide());
// check if ffprobe can be executed
if (!ffprobe.canExecute()) {
// try to make executable
Log.e("ffprobe cannot execute");
return false;
}
Log.d("ffprobe is ready!");
return true;
}
@Override
public FFtask execute(Map<String, String> environvenmentVars, String[] cmd, FFcommandExecuteResponseHandler ffcommandExecuteResponseHandler) {
if (cmd.length != 0) {
final String[] command = new String[cmd.length + 1];
command[0] = FileUtils.getFFprobe(context.provide()).getAbsolutePath();
System.arraycopy(cmd, 0, command, 1, cmd.length);
FFcommandExecuteAsyncTask task = new FFcommandExecuteAsyncTask(command, environvenmentVars, timeout, ffcommandExecuteResponseHandler);
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return task;
} else {
throw new IllegalArgumentException("shell command cannot be empty");
}
}
@Override
public FFtask execute(String[] cmd, FFcommandExecuteResponseHandler ffcommandExecuteResponseHandler) {
return execute(null, cmd, ffcommandExecuteResponseHandler);
}
public boolean isCommandRunning(FFtask task) {
return task != null && !task.isProcessCompleted();
}
@Override
public boolean killRunningProcesses(FFtask task) {
return task != null && task.killRunningProcess();
}
@Override
public void setTimeout(long timeout) {
if (timeout >= MINIMUM_TIMEOUT) {
this.timeout = timeout;
}
}
}