diff --git a/app/src/main/java/com/frank/ffmpeg/activity/VideoPreviewActivity.java b/app/src/main/java/com/frank/ffmpeg/activity/VideoPreviewActivity.java index 331ad62..8203db3 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoPreviewActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoPreviewActivity.java @@ -97,7 +97,7 @@ public class VideoPreviewActivity extends BaseActivity implements VideoPreviewBa mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { - Log.e(TAG, "onPrepared..."); + Log.i(TAG, "onPrepared..."); mediaPlayer.start(); mHandler.sendEmptyMessage(MSG_UPDATE); } @@ -133,7 +133,7 @@ public class VideoPreviewActivity extends BaseActivity implements VideoPreviewBa @Override public void onStopTracking(long progress) { if (mediaPlayer != null) { - Log.e(TAG, "onStopTracking progress=" + progress); + Log.i(TAG, "onStopTracking progress=" + progress); mediaPlayer.seekTo((int) progress); } } diff --git a/app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java b/app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java index bdcdc4a..4b6ffb2 100644 --- a/app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java +++ b/app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java @@ -15,6 +15,7 @@ import android.widget.TextView; import com.frank.ffmpeg.R; import com.frank.ffmpeg.hardware.HardwareDecode; +import com.frank.ffmpeg.util.ScreenUtil; import com.frank.ffmpeg.util.TimeUtil; /** @@ -40,6 +41,14 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On private TextView txtVideoDuration; + private boolean isShowing; + + private int screenWidth; + + private int moveEndPos = 0; + + private int previewHalfWidth; + public VideoPreviewBar(Context context) { super(context); initView(context); @@ -57,6 +66,23 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On txtVideoProgress = view.findViewById(R.id.txt_video_progress); txtVideoDuration = view.findViewById(R.id.txt_video_duration); setListener(); + screenWidth = ScreenUtil.getScreenWidth(context); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + super.onLayout(changed, l, t, r, b); + if (moveEndPos == 0) { + int previewWidth = texturePreView.getWidth(); + previewHalfWidth = previewWidth / 2; + int marginEnd = 0; + MarginLayoutParams layoutParams = (MarginLayoutParams) texturePreView.getLayoutParams(); + if (layoutParams != null) { + marginEnd = layoutParams.getMarginEnd(); + } + moveEndPos = screenWidth - previewWidth - marginEnd; + Log.i(TAG, "previewWidth=" + previewWidth); + } } private void setPreviewCallback(final String filePath, TextureView texturePreView) { @@ -104,15 +130,26 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On // us to ms hardwareDecode.seekTo(progress * 1000); } + int percent = progress * screenWidth / duration; + if (percent > previewHalfWidth && percent < moveEndPos && texturePreView != null) { + texturePreView.setTranslationX(percent - previewHalfWidth); + } } @Override public void onStartTrackingTouch(SeekBar seekBar) { - + if (!isShowing && texturePreView != null) { + isShowing = true; + texturePreView.setVisibility(VISIBLE); + } } @Override public void onStopTrackingTouch(SeekBar seekBar) { + if (isShowing && texturePreView != null) { + isShowing = false; + texturePreView.setVisibility(GONE); + } if (mPreviewBarCallback != null) { mPreviewBarCallback.onStopTracking(seekBar.getProgress()); } @@ -131,6 +168,7 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On public void run() { previewBar.setMax(durationMs); txtVideoDuration.setText(TimeUtil.getVideoTime(durationMs)); + texturePreView.setVisibility(GONE); } }); }