Revision 9fa2835a app/src/main/java/org/witness/ssc/video/VideoEditor.java
app/src/main/java/org/witness/ssc/video/VideoEditor.java | ||
---|---|---|
64 | 64 |
import android.widget.ImageButton; |
65 | 65 |
import android.widget.ImageView; |
66 | 66 |
import android.widget.MediaController; |
67 |
import android.widget.ProgressBar; |
|
67 | 68 |
import android.widget.SeekBar; |
68 | 69 |
import android.widget.Toast; |
69 | 70 |
import android.widget.VideoView; |
70 | 71 |
|
71 | 72 |
import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler; |
72 | 73 |
|
73 |
import net.londatiga.android.ActionItem; |
|
74 |
import net.londatiga.android.QuickAction; |
|
75 |
import net.londatiga.android.QuickAction.OnActionItemClickListener; |
|
76 | 74 |
|
77 | 75 |
import org.witness.securesmartcam.detect.AndroidFaceDetection; |
78 | 76 |
import org.witness.securesmartcam.detect.DetectedFace; |
... | ... | |
96 | 94 |
OnBufferingUpdateListener, OnPreparedListener, OnSeekCompleteListener, |
97 | 95 |
OnVideoSizeChangedListener, SurfaceHolder.Callback, |
98 | 96 |
MediaController.MediaPlayerControl, OnTouchListener, |
99 |
InOutPlayheadSeekBarChangeListener, OnActionItemClickListener {
|
|
97 |
InOutPlayheadSeekBarChangeListener { |
|
100 | 98 |
|
101 | 99 |
public static final String LOGTAG = ObscuraApp.TAG; |
102 | 100 |
|
... | ... | |
111 | 109 |
|
112 | 110 |
private final static int HUMAN_OFFSET_BUFFER = 50; |
113 | 111 |
|
114 |
ProgressDialog progressDialog; |
|
115 | 112 |
int completeActionFlag = 3; |
116 | 113 |
|
117 | 114 |
Uri originalVideoUri; |
... | ... | |
140 | 137 |
|
141 | 138 |
Bitmap bitmapPixel; |
142 | 139 |
|
143 |
InOutPlayheadSeekBar progressBar;
|
|
140 |
InOutPlayheadSeekBar mVideoSeekbar;
|
|
144 | 141 |
//RegionBarArea regionBarArea; |
145 | 142 |
|
146 | 143 |
int videoWidth = 0; |
... | ... | |
181 | 178 |
private final static String DEFAULT_OUT_WIDTH = "480"; |
182 | 179 |
private final static String DEFAULT_OUT_HEIGHT = "320"; |
183 | 180 |
|
181 |
private ProgressBar mProgressBar; |
|
184 | 182 |
|
185 | 183 |
private Handler mHandler = new Handler() { |
186 | 184 |
public void handleMessage(Message msg) { |
... | ... | |
201 | 199 |
Date dateProgress = sdf.parse(time); |
202 | 200 |
long progress = dateProgress.getSeconds()*1000; |
203 | 201 |
int percentComplete = (int)((((float)progress)/((float)mDuration))*100f); |
204 |
progressDialog.setProgress(percentComplete);
|
|
202 |
mProgressBar.setProgress(percentComplete);
|
|
205 | 203 |
} |
206 | 204 |
} |
207 | 205 |
catch (Exception e) |
... | ... | |
215 | 213 |
mCancelled = true; |
216 | 214 |
mAutoDetectEnabled = false; |
217 | 215 |
killVideoProcessor(); |
218 |
|
|
216 |
mProgressBar.setVisibility(View.GONE); |
|
219 | 217 |
break; |
220 | 218 |
|
221 | 219 |
case 3: //completed |
222 |
progressDialog.dismiss(); |
|
223 | 220 |
askPostProcessAction(); |
224 | 221 |
|
222 |
mProgressBar.setVisibility(View.GONE); |
|
225 | 223 |
break; |
226 | 224 |
|
227 | 225 |
case 5: |
... | ... | |
312 | 310 |
mediaPlayer.prepare(); |
313 | 311 |
mDuration = mediaPlayer.getDuration(); |
314 | 312 |
|
315 |
progressBar.setMax(mDuration);
|
|
313 |
mVideoSeekbar.setMax(mDuration);
|
|
316 | 314 |
|
317 | 315 |
} catch (Exception e) { |
318 | 316 |
Log.v(LOGTAG, "IllegalStateException " + e.getMessage()); |
... | ... | |
375 | 373 |
mediaPlayer.prepare(); |
376 | 374 |
mDuration = mediaPlayer.getDuration(); |
377 | 375 |
|
378 |
progressBar.setMax(mDuration);
|
|
376 |
mVideoSeekbar.setMax(mDuration);
|
|
379 | 377 |
|
380 | 378 |
} catch (Exception e) { |
381 | 379 |
Log.v(LOGTAG, "IllegalStateException " + e.getMessage()); |
... | ... | |
462 | 460 |
private void beginAutoDetect() { |
463 | 461 |
mAutoDetectEnabled = true; |
464 | 462 |
|
465 |
progressDialog = new ProgressDialog(this); |
|
466 |
progressDialog = ProgressDialog.show(this, "", "Detecting faces...", true, true); |
|
467 |
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
|
468 |
progressDialog.setCancelable(true); |
|
469 |
Message msg = mHandler.obtainMessage(2); |
|
470 |
msg.getData().putString("status", "cancelled"); |
|
471 |
progressDialog.setCancelMessage(msg); |
|
472 |
|
|
473 |
progressDialog.show(); |
|
474 |
|
|
475 | 463 |
new Thread(doAutoDetect).start(); |
476 | 464 |
|
477 | 465 |
} |
... | ... | |
623 | 611 |
try { |
624 | 612 |
seekTo(f); |
625 | 613 |
|
626 |
progressBar.setProgress(mediaPlayer.getCurrentPosition());
|
|
614 |
mVideoSeekbar.setProgress(mediaPlayer.getCurrentPosition());
|
|
627 | 615 |
|
628 | 616 |
//Bitmap bmp = getVideoFrame(rPath,f*1000); |
629 | 617 |
|
... | ... | |
668 | 656 |
try { |
669 | 657 |
if (mediaPlayer != null && mediaPlayer.isPlaying()) { |
670 | 658 |
int curr = mediaPlayer.getCurrentPosition(); |
671 |
progressBar.setProgress(curr);
|
|
659 |
mVideoSeekbar.setProgress(curr);
|
|
672 | 660 |
updateRegionDisplay(curr); |
673 | 661 |
mHandler.post(this); |
674 | 662 |
} |
... | ... | |
835 | 823 |
|
836 | 824 |
boolean handled = false; |
837 | 825 |
|
838 |
if (v == progressBar) {
|
|
826 |
if (v == mVideoSeekbar) {
|
|
839 | 827 |
|
840 | 828 |
if (currentUri != originalVideoUri) |
841 | 829 |
{ |
... | ... | |
853 | 841 |
} |
854 | 842 |
|
855 | 843 |
|
856 |
mediaPlayer.seekTo(progressBar.getProgress());
|
|
844 |
mediaPlayer.seekTo(mVideoSeekbar.getProgress());
|
|
857 | 845 |
// Attempt to get the player to update it's view - NOT WORKING |
858 | 846 |
} |
859 | 847 |
|
... | ... | |
1042 | 1030 |
|
1043 | 1031 |
case R.id.menu_save: |
1044 | 1032 |
|
1045 |
|
|
1033 |
resetMediaPlayer(originalVideoUri); |
|
1046 | 1034 |
processVideo(false); |
1047 | 1035 |
|
1048 | 1036 |
return true; |
... | ... | |
1068 | 1056 |
|
1069 | 1057 |
PowerManager.WakeLock wl; |
1070 | 1058 |
|
1071 |
private void processVideo(boolean isPreview) { |
|
1059 |
private synchronized void processVideo(boolean isPreview) { |
|
1060 |
|
|
1061 |
if (ffmpeg != null |
|
1062 |
&& ffmpeg.getFFMPEG().isFFmpegCommandRunning()) |
|
1063 |
ffmpeg.getFFMPEG().killRunningProcesses(); |
|
1072 | 1064 |
|
1073 | 1065 |
mIsPreview = isPreview; |
1074 | 1066 |
|
1067 |
mProgressBar.setVisibility(View.VISIBLE); |
|
1068 |
mProgressBar.setProgress(0); |
|
1069 |
|
|
1075 | 1070 |
if (isPreview) |
1076 | 1071 |
{ |
1077 | 1072 |
saveFile = new File(fileExternDir,"obscuracam-preview-tmp." + outFormat); |
1078 | 1073 |
} |
1079 | 1074 |
else { |
1075 |
if (saveFile != null |
|
1076 |
&& saveFile.exists() && saveFile.getName().contains("preview")) |
|
1077 |
saveFile.delete(); |
|
1078 |
|
|
1080 | 1079 |
createCleanSavePath(outFormat); |
1080 |
|
|
1081 |
mSnackbar = Snackbar.make(findViewById(R.id.frameRoot), R.string.processing, Snackbar.LENGTH_INDEFINITE); |
|
1082 |
mSnackbar.show(); |
|
1081 | 1083 |
} |
1082 | 1084 |
|
1083 | 1085 |
mCancelled = false; |
1084 | 1086 |
|
1085 | 1087 |
mediaPlayer.pause(); |
1086 | 1088 |
|
1087 |
progressDialog = new ProgressDialog(this); |
|
1088 |
progressDialog.setMessage("Processing. Please wait..."); |
|
1089 |
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); |
|
1090 |
progressDialog.setMax(100); |
|
1091 |
progressDialog.setProgress(0); |
|
1092 |
progressDialog.setCancelable(true); |
|
1093 |
|
|
1094 |
Message msg = mHandler.obtainMessage(2); |
|
1095 |
msg.getData().putString("status", "cancelled"); |
|
1096 |
progressDialog.setCancelMessage(msg); |
|
1097 |
|
|
1098 |
progressDialog.show(); |
|
1099 |
|
|
1100 | 1089 |
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
1101 | 1090 |
wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); |
1102 | 1091 |
wl.acquire(); |
... | ... | |
1105 | 1094 |
if (ffmpeg == null) |
1106 | 1095 |
ffmpeg = new FFMPEGWrapper(VideoEditor.this.getBaseContext()); |
1107 | 1096 |
|
1108 |
int outputLength = -1; |
|
1109 | 1097 |
int frameRate = 0; |
1110 | 1098 |
|
1099 |
float startTime = ((float)mediaPlayer.getCurrentPosition())/1000f; |
|
1100 |
float duration = (float)mDuration/1000f; |
|
1101 |
|
|
1111 | 1102 |
if (isPreview) { |
1112 | 1103 |
frameRate = 1; |
1113 |
outputLength = Math.min(mDuration, 5); |
|
1114 |
mDuration = outputLength; |
|
1104 |
duration = Math.min(duration - startTime, 1f); |
|
1115 | 1105 |
} |
1106 |
|
|
1116 | 1107 |
else if (mObscureVideoAmount > 0) |
1117 | 1108 |
{ |
1118 |
frameRate = 15;
|
|
1109 |
frameRate = 3;
|
|
1119 | 1110 |
} |
1120 | 1111 |
|
1121 | 1112 |
// Could make some high/low quality presets |
1122 | 1113 |
ffmpeg.processVideo(obscureTrails, recordingFile, saveFile, |
1123 |
frameRate, mDuration, outputLength, mCompressVideo, mObscureVideoAmount, mObscureAudioAmount,
|
|
1114 |
frameRate, startTime, duration, mCompressVideo, mObscureVideoAmount, mObscureAudioAmount,
|
|
1124 | 1115 |
new ExecuteBinaryResponseHandler() { |
1125 | 1116 |
|
1126 | 1117 |
@Override |
... | ... | |
1187 | 1178 |
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(saveFile))); |
1188 | 1179 |
} |
1189 | 1180 |
|
1181 |
Snackbar mSnackbar; |
|
1182 |
|
|
1190 | 1183 |
private void askPostProcessAction() { |
1191 | 1184 |
if (saveFile != null && saveFile.exists()) { |
1192 | 1185 |
|
... | ... | |
1194 | 1187 |
start(); |
1195 | 1188 |
|
1196 | 1189 |
if (!mIsPreview) { |
1197 |
Snackbar snackbar = Snackbar.make(findViewById(R.id.frameRoot), R.string.processing_complete, Snackbar.LENGTH_LONG); |
|
1198 |
snackbar.setAction("Open", new OnClickListener() { |
|
1190 |
|
|
1191 |
if (mSnackbar != null) |
|
1192 |
{ |
|
1193 |
mSnackbar.dismiss(); |
|
1194 |
mSnackbar = null; |
|
1195 |
} |
|
1196 |
|
|
1197 |
mSnackbar = Snackbar.make(findViewById(R.id.frameRoot), R.string.processing_complete, Snackbar.LENGTH_LONG); |
|
1198 |
mSnackbar.setAction("Open", new OnClickListener() { |
|
1199 | 1199 |
@Override |
1200 | 1200 |
public void onClick(View view) { |
1201 | 1201 |
playVideoExternal(); |
1202 | 1202 |
} |
1203 | 1203 |
}); |
1204 |
snackbar.show();
|
|
1204 |
mSnackbar.show();
|
|
1205 | 1205 |
} |
1206 | 1206 |
} |
1207 | 1207 |
|
... | ... | |
1313 | 1313 |
|
1314 | 1314 |
videoView = (VideoView) this.findViewById(R.id.SurfaceView); |
1315 | 1315 |
|
1316 |
mProgressBar = (ProgressBar) this.findViewById(R.id.progress_spinner); |
|
1317 |
|
|
1316 | 1318 |
regionsView = (ImageView) this.findViewById(R.id.VideoEditorImageView); |
1317 | 1319 |
regionsView.setOnClickListener(new OnClickListener() { |
1318 | 1320 |
@Override |
... | ... | |
1320 | 1322 |
resetMediaPlayer(originalVideoUri); |
1321 | 1323 |
} |
1322 | 1324 |
}); |
1323 |
// regionsView.setOnTouchListener(this);
|
|
1325 |
regionsView.setOnTouchListener(this); |
|
1324 | 1326 |
|
1325 | 1327 |
surfaceHolder = videoView.getHolder(); |
1326 | 1328 |
|
... | ... | |
1329 | 1331 |
|
1330 | 1332 |
currentDisplay = getWindowManager().getDefaultDisplay(); |
1331 | 1333 |
|
1332 |
progressBar = (InOutPlayheadSeekBar) this.findViewById(R.id.InOutPlayheadSeekBar);
|
|
1334 |
mVideoSeekbar = (InOutPlayheadSeekBar) this.findViewById(R.id.InOutPlayheadSeekBar);
|
|
1333 | 1335 |
|
1334 |
progressBar.setIndeterminate(false);
|
|
1335 |
progressBar.setSecondaryProgress(0);
|
|
1336 |
progressBar.setProgress(0);
|
|
1337 |
progressBar.setInOutPlayheadSeekBarChangeListener(this);
|
|
1338 |
progressBar.setThumbsInactive();
|
|
1339 |
progressBar.setOnTouchListener(this);
|
|
1336 |
mVideoSeekbar.setIndeterminate(false);
|
|
1337 |
mVideoSeekbar.setSecondaryProgress(0);
|
|
1338 |
mVideoSeekbar.setProgress(0);
|
|
1339 |
mVideoSeekbar.setInOutPlayheadSeekBarChangeListener(this);
|
|
1340 |
mVideoSeekbar.setThumbsInactive();
|
|
1341 |
mVideoSeekbar.setOnTouchListener(this);
|
|
1340 | 1342 |
|
1341 | 1343 |
playPauseButton = (ImageButton) this.findViewById(R.id.PlayPauseImageButton); |
1342 | 1344 |
playPauseButton.setOnClickListener(new OnClickListener() { |
... | ... | |
1347 | 1349 |
playPauseButton.setImageDrawable(getResources().getDrawable(android.R.drawable.ic_media_play)); |
1348 | 1350 |
mAutoDetectEnabled = false; |
1349 | 1351 |
} else { |
1352 |
if (currentUri != originalVideoUri) |
|
1353 |
{ |
|
1354 |
resetMediaPlayer(originalVideoUri); |
|
1355 |
seekTo(0); |
|
1356 |
} |
|
1350 | 1357 |
start(); |
1351 | 1358 |
|
1352 | 1359 |
|
... | ... | |
1376 | 1383 |
} |
1377 | 1384 |
});**/ |
1378 | 1385 |
|
1379 |
findViewById(R.id.button_preview).setOnClickListener(new OnClickListener() { |
|
1380 |
@Override |
|
1381 |
public void onClick(View view) { |
|
1382 |
processVideo(true); |
|
1383 |
} |
|
1384 |
}); |
|
1385 |
|
|
1386 | 1386 |
((SeekBar)findViewById(R.id.seekbar_video_obscure)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { |
1387 | 1387 |
@Override |
1388 | 1388 |
public void onProgressChanged(SeekBar seekBar, int i, boolean b) { |
... | ... | |
1393 | 1393 |
} |
1394 | 1394 |
|
1395 | 1395 |
mObscureVideoAmount = i; |
1396 |
|
|
1396 | 1397 |
} |
1397 | 1398 |
|
1398 | 1399 |
@Override |
... | ... | |
1403 | 1404 |
@Override |
1404 | 1405 |
public void onStopTrackingTouch(SeekBar seekBar) { |
1405 | 1406 |
|
1407 |
processVideo(true); |
|
1406 | 1408 |
} |
1407 | 1409 |
}); |
1408 | 1410 |
|
... | ... | |
1420 | 1422 |
@Override |
1421 | 1423 |
public void onStopTrackingTouch(SeekBar seekBar) { |
1422 | 1424 |
|
1425 |
processVideo(true); |
|
1423 | 1426 |
} |
1424 | 1427 |
}); |
1425 | 1428 |
|
... | ... | |
1688 | 1691 |
|
1689 | 1692 |
} |
1690 | 1693 |
|
1691 |
@Override
|
|
1694 |
/**
|
|
1692 | 1695 |
public void onItemClick(QuickAction source, int pos, int actionId) { |
1693 | 1696 |
|
1694 | 1697 |
switch (actionId) { |
... | ... | |
1742 | 1745 |
updateRegionDisplay(mediaPlayer.getCurrentPosition()); |
1743 | 1746 |
|
1744 | 1747 |
} |
1745 |
|
|
1748 |
**/ |
|
1746 | 1749 |
|
1747 | 1750 |
/* |
1748 | 1751 |
* Actual deletion of original |
Also available in: Unified diff