Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

order tab preview now uses trim points

  • Loading branch information...
commit 612839ec745b3f7ac90014dd17eec577c9535832 1 parent 179af21
@vitriolix vitriolix authored
Showing with 58 additions and 12 deletions.
  1. +58 −12 app/src/info/guardianproject/mrapp/PreviewVideoView.java
View
70 app/src/info/guardianproject/mrapp/PreviewVideoView.java
@@ -8,6 +8,7 @@
import info.guardianproject.mrapp.model.Media;
import android.content.Context;
import android.media.MediaPlayer;
+import android.os.Handler;
import android.util.AttributeSet;
import android.widget.VideoView;
@@ -22,6 +23,15 @@
//MediaPlayer mp;
protected Runnable mCompletionCallback = null;
+ private Handler mHandler = new Handler();
+ private Runnable mTrimClipEndTask = new Runnable() {
+ public void run() {
+ PreviewVideoView.this.stopPlayback();
+ PreviewVideoView.this.doComplete();
+ }
+ };
+
+
public PreviewVideoView(Context context) {
super(context);
setOnCompletionListener(this);
@@ -59,12 +69,18 @@ public void play() {
}
break;
} else {
- String path = mMediaArray[mCurrentMedia].getPath();
+ Media media = mMediaArray[mCurrentMedia];
+ String path = media.getPath();
if (path != null) {
File file = new File(path);
if (file.exists()) {
- this.setVideoPath(path);
- this.start();
+ setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+ @Override
+ public void onPrepared(MediaPlayer mp) {
+ PreviewVideoView.this.doPlay();
+ }
+ });
+ this.setVideoPath(path);
break;
}
}
@@ -72,6 +88,31 @@ public void play() {
}
}
+ private void doPlay() {
+ Media media = mMediaArray[mCurrentMedia];
+
+ int duration = getDuration();
+ int trimStart = media.getTrimStart();
+ int trimEnd = media.getTrimEnd();
+ float startPercent = (trimStart + 1) / 100F;
+ float endPercent = (trimEnd + 1) / 100F;
+ int startTime = Math.round(startPercent * duration);
+ int endTime = Math.round(endPercent * duration);
+ int trimmedLength = endTime - startTime;
+
+ if ((media.getTrimStart() > 0) && (media.getTrimStart() < 99)) {
+ seekTo(startTime);
+ }
+
+ if ((media.getTrimEnd() != 0) && (media.getTrimEnd() < 99)) {// && (media.getTrimStart() < media.getTrimEnd())) {
+ mHandler.removeCallbacks(mTrimClipEndTask);
+ mHandler.postDelayed(mTrimClipEndTask, trimmedLength);
+ }
+
+ start();
+ // FIXME make sure to kill off the time if we close the activity/stop
+ }
+
public void play(int startFrom) {
// TODO if we are already playing, stop, load the new video and start.
if (startFrom >= 0 && startFrom < mMediaArray.length) {
@@ -83,14 +124,19 @@ public void play(int startFrom) {
@Override
public void onCompletion(MediaPlayer mp) {
- if (mCurrentMedia < mMediaArray.length) {
- mCurrentMedia++;
- play();
- } else {
- mCurrentMedia = 0;
- if (mCompletionCallback != null) {
- mCompletionCallback.run();
- }
- }
+ doComplete();
+ }
+
+ private void doComplete() {
+ mHandler.removeCallbacks(mTrimClipEndTask);
+ if (mCurrentMedia < mMediaArray.length) {
+ mCurrentMedia++;
+ play();
+ } else {
+ mCurrentMedia = 0;
+ if (mCompletionCallback != null) {
+ mCompletionCallback.run();
+ }
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.