Skip to content

Commit c714e37

Browse files
authored
Merge pull request #4 from brarcher/consolidate
Consolidate FFmpeg interfacing code
2 parents 438e729 + 56e87b8 commit c714e37

File tree

12 files changed

+1096
-277
lines changed

12 files changed

+1096
-277
lines changed

app/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ android {
2525
disable "GoogleAppIndexingWarning"
2626
disable "MissingTranslation"
2727
}
28+
29+
// Starting with Android Studio 3 Robolectric is unable to find resources.
30+
// The following allows it to find the resources.
31+
testOptions {
32+
unitTests {
33+
includeAndroidResources = true
34+
}
35+
}
2836
}
2937

3038
dependencies {
@@ -40,6 +48,7 @@ dependencies {
4048
compile 'commons-io:commons-io:2.5'
4149
compile group: 'com.google.guava', name: 'guava', version: '20.0'
4250
testCompile 'junit:junit:4.12'
51+
testCompile "org.robolectric:robolectric:3.6.1"
4352
}
4453

4554
task findbugs(type: FindBugs, dependsOn: 'assembleDebug') {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package protect.videotranscoder;
2+
3+
import android.app.ProgressDialog;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.util.Log;
7+
8+
import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler;
9+
10+
public class FFmpegResponseHandler extends ExecuteBinaryResponseHandler
11+
{
12+
private static final String TAG = "VideoTranscoder";
13+
14+
private final Context _context;
15+
private final Intent _intentToLaunch;
16+
private final long _durationMs;
17+
private final ProgressDialog _progressDialog;
18+
19+
public FFmpegResponseHandler(Context context, Intent intent, long durationMs, ProgressDialog progressDialog)
20+
{
21+
_context = context;
22+
_intentToLaunch = intent;
23+
_durationMs = durationMs;
24+
_progressDialog = progressDialog;
25+
}
26+
27+
@Override
28+
public void onFailure(String s)
29+
{
30+
Log.d(TAG, "Failed with output : " + s);
31+
}
32+
33+
@Override
34+
public void onSuccess(String s)
35+
{
36+
Log.d(TAG, "Success with output : " +s);
37+
_context.startActivity(_intentToLaunch);
38+
}
39+
40+
@Override
41+
public void onProgress(String s)
42+
{
43+
// Progress updates look like the following:
44+
// frame= 15 fps=7.1 q=2.0 size= 26kB time=00:00:00.69 bitrate= 309.4kbits/s dup=6 drop=0 speed=0.329x
45+
46+
Log.d(TAG, "progress : " + s);
47+
48+
Long currentTimeMs = null;
49+
50+
String [] split = s.split(" ");
51+
for(String item : split)
52+
{
53+
if(item.startsWith("time="))
54+
{
55+
item = item.replace("time=", "");
56+
currentTimeMs = FFmpegUtil.timestampToMs(item);
57+
58+
break;
59+
}
60+
}
61+
62+
if(currentTimeMs != null)
63+
{
64+
int percentComplete = (int)Math.floor((currentTimeMs * 100) / (float)_durationMs);
65+
66+
_progressDialog.setMessage(percentComplete + "%");
67+
}
68+
}
69+
70+
@Override
71+
public void onStart()
72+
{
73+
Log.d(TAG, "Started FFmpeg command");
74+
_progressDialog.setMessage("Processing...");
75+
_progressDialog.show();
76+
}
77+
78+
@Override
79+
public void onFinish()
80+
{
81+
Log.d(TAG, "Finished command");
82+
_progressDialog.dismiss();
83+
}
84+
}

0 commit comments

Comments
 (0)