|
3 | 3 | import android.content.Context; |
4 | 4 | import android.text.TextUtils; |
5 | 5 |
|
| 6 | +import java.lang.reflect.Array; |
6 | 7 | import java.util.Map; |
7 | 8 |
|
8 | 9 | import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException; |
@@ -61,28 +62,41 @@ public void loadBinary(FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseH |
61 | 62 | } |
62 | 63 |
|
63 | 64 | @Override |
64 | | - public void execute(Map<String, String> environvenmentVars, String cmd, FFmpegExecuteResponseHandler ffmpegExecuteResponseHandler) throws FFmpegCommandAlreadyRunningException { |
| 65 | + public void execute(Map<String, String> environvenmentVars, String[] cmd, FFmpegExecuteResponseHandler ffmpegExecuteResponseHandler) throws FFmpegCommandAlreadyRunningException { |
65 | 66 | if (ffmpegExecuteAsyncTask != null && !ffmpegExecuteAsyncTask.isProcessCompleted()) { |
66 | 67 | throw new FFmpegCommandAlreadyRunningException("FFmpeg command is already running, you are only allowed to run single command at a time"); |
67 | 68 | } |
68 | | - if (!TextUtils.isEmpty(cmd)) { |
69 | | - String ffmpegCmd = FileUtils.getFFmpeg(context, environvenmentVars) + " "+ cmd; |
70 | | - ffmpegExecuteAsyncTask = new FFmpegExecuteAsyncTask(ffmpegCmd, timeout, ffmpegExecuteResponseHandler); |
| 69 | + if (cmd.length != 0) { |
| 70 | + String[] ffmpegBinary = new String[] { FileUtils.getFFmpeg(context, environvenmentVars) }; |
| 71 | + String[] command = concatenate(ffmpegBinary, cmd); |
| 72 | + ffmpegExecuteAsyncTask = new FFmpegExecuteAsyncTask(command , timeout, ffmpegExecuteResponseHandler); |
71 | 73 | ffmpegExecuteAsyncTask.execute(); |
72 | 74 | } else { |
73 | 75 | throw new IllegalArgumentException("shell command cannot be empty"); |
74 | 76 | } |
75 | 77 | } |
76 | 78 |
|
| 79 | + public <T> T[] concatenate (T[] a, T[] b) { |
| 80 | + int aLen = a.length; |
| 81 | + int bLen = b.length; |
| 82 | + |
| 83 | + @SuppressWarnings("unchecked") |
| 84 | + T[] c = (T[]) Array.newInstance(a.getClass().getComponentType(), aLen + bLen); |
| 85 | + System.arraycopy(a, 0, c, 0, aLen); |
| 86 | + System.arraycopy(b, 0, c, aLen, bLen); |
| 87 | + |
| 88 | + return c; |
| 89 | + } |
| 90 | + |
77 | 91 | @Override |
78 | | - public void execute(String cmd, FFmpegExecuteResponseHandler ffmpegExecuteResponseHandler) throws FFmpegCommandAlreadyRunningException { |
| 92 | + public void execute(String[] cmd, FFmpegExecuteResponseHandler ffmpegExecuteResponseHandler) throws FFmpegCommandAlreadyRunningException { |
79 | 93 | execute(null, cmd, ffmpegExecuteResponseHandler); |
80 | 94 | } |
81 | 95 |
|
82 | 96 | @Override |
83 | 97 | public String getDeviceFFmpegVersion() throws FFmpegCommandAlreadyRunningException { |
84 | 98 | ShellCommand shellCommand = new ShellCommand(); |
85 | | - CommandResult commandResult = shellCommand.runWaitFor(FileUtils.getFFmpeg(context) + " -version"); |
| 99 | + CommandResult commandResult = shellCommand.runWaitFor(new String[] { FileUtils.getFFmpeg(context), "-version" }); |
86 | 100 | if (commandResult.success) { |
87 | 101 | return commandResult.output.split(" ")[2]; |
88 | 102 | } |
|
0 commit comments