Skip to content

Commit 2d92a71

Browse files
Added Live examples + updated version name and code + Added class bindings over interfaces
1 parent a2d539b commit 2d92a71

File tree

14 files changed

+246
-33
lines changed

14 files changed

+246
-33
lines changed

FFmpegAndroid/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.github.hiteshsondhi88.libffmpeg"
99
minSdkVersion 16
1010
targetSdkVersion 16
11-
versionCode 1
12-
versionName "1.0"
11+
versionCode 21
12+
versionName "0.2.1"
1313
}
1414

1515
sourceSets.main {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.github.hiteshsondhi88.libffmpeg;
2+
3+
public class ExecuteBinaryResponseHandler implements FFmpegExecuteResponseHandler {
4+
5+
@Override
6+
public void onSuccess(String message) {
7+
8+
}
9+
10+
@Override
11+
public void onProgress(String message) {
12+
13+
}
14+
15+
@Override
16+
public void onFailure(String message) {
17+
18+
}
19+
20+
@Override
21+
public void onStart() {
22+
23+
}
24+
25+
@Override
26+
public void onFinish() {
27+
28+
}
29+
}

FFmpegAndroid/src/main/java/com/github/hiteshsondhi88/libffmpeg/FFmpegExecuteAsyncTask.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class FFmpegExecuteAsyncTask extends AsyncTask<Void, String, CommandResult> {
1515
private final long timeout;
1616
private long startTime;
1717
private Process process;
18+
private String output = "";
1819

1920
FFmpegExecuteAsyncTask(String cmd, long timeout, FFmpegExecuteResponseHandler ffmpegExecuteResponseHandler) {
2021
this.cmd = cmd;
@@ -62,10 +63,11 @@ protected void onProgressUpdate(String... values) {
6263
@Override
6364
protected void onPostExecute(CommandResult commandResult) {
6465
if (ffmpegExecuteResponseHandler != null) {
66+
output += commandResult.output;
6567
if (commandResult.success) {
66-
ffmpegExecuteResponseHandler.onSuccess(commandResult.output);
68+
ffmpegExecuteResponseHandler.onSuccess(output);
6769
} else {
68-
ffmpegExecuteResponseHandler.onFailure(commandResult.output);
70+
ffmpegExecuteResponseHandler.onFailure(output);
6971
}
7072
ffmpegExecuteResponseHandler.onFinish();
7173
}
@@ -87,6 +89,7 @@ private void checkAndUpdateProcess() throws TimeoutException, InterruptedExcepti
8789
String line;
8890
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
8991
while ((line = reader.readLine()) != null) {
92+
output += line+"\n";
9093
publishProgress(line);
9194
}
9295
} catch (IOException e) {

FFmpegAndroid/src/main/java/com/github/hiteshsondhi88/libffmpeg/FFmpegExecuteResponseHandler.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22

33
public interface FFmpegExecuteResponseHandler extends ResponseHandler {
44

5-
public void onFailure(String message);
5+
/**
6+
* on Success
7+
* @param message complete output of the FFmpeg command
8+
*/
69
public void onSuccess(String message);
10+
11+
/**
12+
* on Progress
13+
* @param message current output of FFmpeg command
14+
*/
715
public void onProgress(String message);
816

17+
/**
18+
* on Failure
19+
* @param message complete output of the FFmpeg command
20+
*/
21+
public void onFailure(String message);
22+
923
}

FFmpegAndroid/src/main/java/com/github/hiteshsondhi88/libffmpeg/FFmpegLoadBinaryResponseHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
public interface FFmpegLoadBinaryResponseHandler extends ResponseHandler {
44

5+
/**
6+
* on Fail
7+
*/
58
public void onFailure();
9+
10+
/**
11+
* on Success
12+
*/
613
public void onSuccess();
714

815
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.hiteshsondhi88.libffmpeg;
2+
3+
public class LoadBinaryResponseHandler implements FFmpegLoadBinaryResponseHandler {
4+
5+
@Override
6+
public void onFailure() {
7+
8+
}
9+
10+
@Override
11+
public void onSuccess() {
12+
13+
}
14+
15+
@Override
16+
public void onStart() {
17+
18+
}
19+
20+
@Override
21+
public void onFinish() {
22+
23+
}
24+
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package com.github.hiteshsondhi88.libffmpeg;
22

3-
interface ResponseHandler {
3+
abstract interface ResponseHandler {
44

5+
/**
6+
* on Start
7+
*/
58
public void onStart();
9+
10+
/**
11+
* on Finish
12+
*/
613
public void onFinish();
714

815
}

app/app.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<orderEntry type="library" exported="" scope="TEST" name="assertj-core-1.6.1" level="project" />
8686
<orderEntry type="library" exported="" scope="TEST" name="support-annotations-20.0.0" level="project" />
8787
<orderEntry type="library" exported="" name="dagger-compiler-1.2.2" level="project" />
88+
<orderEntry type="library" exported="" name="butterknife-5.1.2" level="project" />
8889
<orderEntry type="library" exported="" name="javawriter-2.5.0" level="project" />
8990
<orderEntry type="module" module-name="FFmpegAndroid" exported="" />
9091
</component>

app/build.gradle

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.github.hiteshsondhi88.sampleffmpeg"
99
minSdkVersion 16
1010
targetSdkVersion 20
11-
versionCode 1
12-
versionName "1.0"
11+
versionCode 21
12+
versionName "0.2.1"
1313
}
1414

1515
sourceSets.main {
@@ -18,6 +18,10 @@ android {
1818
jni.srcDirs = [] //disable automatic ndk-build
1919
}
2020

21+
packagingOptions {
22+
exclude 'META-INF/services/javax.annotation.processing.Processor'
23+
}
24+
2125
buildTypes {
2226
release {
2327
runProguard false
@@ -29,10 +33,8 @@ android {
2933
dependencies {
3034
compile 'com.squareup.dagger:dagger-compiler:1.2.2'
3135
compile 'com.squareup.dagger:dagger:1.2.2'
32-
36+
compile 'com.jakewharton:butterknife:5.1.2'
3337
compile fileTree(dir: 'libs', include: ['*.jar'])
34-
35-
compile project(':FFmpegAndroid')
36-
3738
androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0'
39+
compile project(':FFmpegAndroid')
3840
}
Lines changed: 112 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,154 @@
11
package com.github.hiteshsondhi88.sampleffmpeg;
22

33
import android.app.Activity;
4+
import android.app.AlertDialog;
5+
import android.app.ProgressDialog;
6+
import android.content.DialogInterface;
47
import android.os.Bundle;
8+
import android.text.TextUtils;
59
import android.util.Log;
10+
import android.view.View;
11+
import android.widget.Button;
12+
import android.widget.EditText;
13+
import android.widget.LinearLayout;
14+
import android.widget.TextView;
15+
import android.widget.Toast;
616

717
import javax.inject.Inject;
818

19+
import butterknife.ButterKnife;
20+
import butterknife.InjectView;
921
import dagger.ObjectGraph;
22+
23+
import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler;
1024
import com.github.hiteshsondhi88.libffmpeg.FFmpeg;
11-
import com.github.hiteshsondhi88.libffmpeg.FFmpegLoadBinaryResponseHandler;
25+
import com.github.hiteshsondhi88.libffmpeg.LoadBinaryResponseHandler;
26+
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException;
1227
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegNotSupportedException;
1328

14-
public class Home extends Activity {
29+
public class Home extends Activity implements View.OnClickListener {
1530

1631
private static final String TAG = Home.class.getSimpleName();
1732

1833
@Inject
1934
FFmpeg ffmpeg;
2035

36+
@InjectView(R.id.command)
37+
EditText commandEditText;
38+
39+
@InjectView(R.id.command_output)
40+
LinearLayout outputLayout;
41+
42+
@InjectView(R.id.run_command)
43+
Button runButton;
44+
45+
private ProgressDialog progressDialog;
46+
2147
@Override
2248
protected void onCreate(Bundle savedInstanceState) {
2349
super.onCreate(savedInstanceState);
2450
setContentView(R.layout.activity_home);
25-
51+
ButterKnife.inject(this);
2652
ObjectGraph.create(new DaggerDependencyModule(this)).inject(this);
2753

54+
loadFFMpegBinary();
55+
initUI();
56+
}
57+
58+
private void initUI() {
59+
runButton.setOnClickListener(this);
60+
61+
progressDialog = new ProgressDialog(this);
62+
progressDialog.setTitle(null);
63+
}
64+
65+
private void loadFFMpegBinary() {
2866
try {
29-
ffmpeg.loadBinary(new FFmpegLoadBinaryResponseHandler() {
67+
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
68+
@Override
69+
public void onFailure() {
70+
showUnsupportedExceptionDialog();
71+
}
72+
});
73+
} catch (FFmpegNotSupportedException e) {
74+
showUnsupportedExceptionDialog();
75+
}
76+
}
3077

78+
private void execFFmpegBinary(final String command) {
79+
try {
80+
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
3181
@Override
32-
public void onStart() {
33-
// Do Nothing
82+
public void onFailure(String s) {
83+
addTextViewToLayout("FAILED with output : "+s);
3484
}
3585

3686
@Override
37-
public void onFailure() {
38-
Log.e(TAG, "FFmpeg loading failed");
87+
public void onSuccess(String s) {
88+
addTextViewToLayout("SUCCESS with output : "+s);
3989
}
4090

4191
@Override
42-
public void onSuccess() {
43-
Log.e(TAG, "FFmpeg loading success");
92+
public void onProgress(String s) {
93+
Log.d(TAG, "Started command : ffmpeg "+command);
94+
addTextViewToLayout("progress : "+s);
95+
progressDialog.setMessage("Processing\n"+s);
96+
}
97+
98+
@Override
99+
public void onStart() {
100+
outputLayout.removeAllViews();
101+
102+
Log.d(TAG, "Started command : ffmpeg " + command);
103+
progressDialog.setMessage("Processing...");
104+
progressDialog.show();
44105
}
45106

46107
@Override
47108
public void onFinish() {
48-
Log.e(TAG, "FFmpeg loading finished");
109+
Log.d(TAG, "Finished command : ffmpeg "+command);
110+
progressDialog.dismiss();
49111
}
50112
});
51-
} catch (FFmpegNotSupportedException e) {
52-
Log.e(TAG, "FFmpeg not supported", e);
113+
} catch (FFmpegCommandAlreadyRunningException e) {
114+
// do nothing for now
115+
}
116+
}
117+
118+
private void addTextViewToLayout(String text) {
119+
TextView textView = new TextView(Home.this);
120+
textView.setText(text);
121+
outputLayout.addView(textView);
122+
}
123+
124+
private void showUnsupportedExceptionDialog() {
125+
new AlertDialog.Builder(Home.this)
126+
.setIcon(android.R.drawable.ic_dialog_alert)
127+
.setTitle(getString(R.string.device_not_supported))
128+
.setMessage(getString(R.string.device_not_supported_message))
129+
.setCancelable(false)
130+
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
131+
@Override
132+
public void onClick(DialogInterface dialog, int which) {
133+
Home.this.finish();
134+
}
135+
})
136+
.create()
137+
.show();
138+
139+
}
140+
141+
@Override
142+
public void onClick(View v) {
143+
switch (v.getId()) {
144+
case R.id.run_command:
145+
String command = commandEditText.getText().toString();
146+
if (!TextUtils.isEmpty(command)) {
147+
execFFmpegBinary(command);
148+
} else {
149+
Toast.makeText(Home.this, getString(R.string.empty_command_toast), Toast.LENGTH_LONG).show();
150+
}
151+
break;
53152
}
54153
}
55154
}

0 commit comments

Comments
 (0)