From e64559b72273d6079201d064ad46ed265209b72f Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Thu, 21 Nov 2019 01:03:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E9=A2=84=E8=A7=88=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E9=80=89=E6=8B=A9=E6=96=87=E4=BB=B6=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 视频预览改为选择文件播放 --- .../ffmpeg/activity/VideoPreviewActivity.java | 20 +++++++++---------- .../ffmpeg/activity/VideoReverseActivity.java | 4 ++-- .../frank/ffmpeg/view/VideoPreviewBar.java | 16 +++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) 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 8203db3..72fec7b 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoPreviewActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoPreviewActivity.java @@ -2,7 +2,6 @@ package com.frank.ffmpeg.activity; import android.annotation.SuppressLint; import android.media.MediaPlayer; -import android.os.Environment; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -18,6 +17,8 @@ import com.frank.ffmpeg.view.VideoPreviewBar; import java.io.IOException; +import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_TOAST; + /** * 视频拖动实时预览 * Created by frank on 2019/11/16. @@ -27,13 +28,8 @@ public class VideoPreviewActivity extends BaseActivity implements VideoPreviewBa private final static String TAG = VideoPreviewActivity.class.getSimpleName(); - private final static String ROOT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath(); - private String videoPath = ROOT_PATH + "/What.mp4"; -// private final static String videoPath = ROOT_PATH + "/bird-1080P.mkv"; -// videoPath = "https://www.apple.com/105/media/cn/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797" + -// "/films/bruce/mac-bruce-tpl-cn-2018_1280x720h.mp4"; - private MediaPlayer mediaPlayer; + private SurfaceView surfaceVideo; private VideoPreviewBar videoPreviewBar; private final static int TIME_UPDATE = 1000; private final static int MSG_UPDATE = 1234; @@ -48,6 +44,8 @@ public class VideoPreviewActivity extends BaseActivity implements VideoPreviewBa videoPreviewBar.updateProgress(mediaPlayer.getCurrentPosition()); } mHandler.sendEmptyMessageDelayed(MSG_UPDATE, TIME_UPDATE); + } else if (msg.what == MSG_TOAST) { + showToast(getString(R.string.please_click_select)); } } }; @@ -62,13 +60,12 @@ public class VideoPreviewActivity extends BaseActivity implements VideoPreviewBa super.onCreate(savedInstanceState); initView(); + mHandler.sendEmptyMessageDelayed(MSG_TOAST, 500); } private void initView() { - SurfaceView surfaceVideo = getView(R.id.surface_view); - setPlayCallback(videoPath, surfaceVideo); + surfaceVideo = getView(R.id.surface_view); videoPreviewBar = getView(R.id.preview_video); - videoPreviewBar.init(videoPath, this); } private void setPlayCallback(final String filePath, SurfaceView surfaceView) { @@ -127,7 +124,8 @@ public class VideoPreviewActivity extends BaseActivity implements VideoPreviewBa @Override void onSelectedFile(String filePath) { - + setPlayCallback(filePath, surfaceVideo); + videoPreviewBar.init(filePath, this); } @Override diff --git a/app/src/main/java/com/frank/ffmpeg/activity/VideoReverseActivity.java b/app/src/main/java/com/frank/ffmpeg/activity/VideoReverseActivity.java index 36f4bea..09cec47 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoReverseActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoReverseActivity.java @@ -40,7 +40,7 @@ public class VideoReverseActivity extends BaseActivity { if (msg.what == MSG_FINISH){ changeVisibility(); startPlay(); - }else if (msg.what == MSG_TOAST) { + } else if (msg.what == MSG_TOAST) { showToast(getString(R.string.please_click_select)); } } @@ -57,7 +57,7 @@ public class VideoReverseActivity extends BaseActivity { initView(); initPlayer(); - mHandler.sendEmptyMessageDelayed(MSG_TOAST, 1000); + mHandler.sendEmptyMessageDelayed(MSG_TOAST, 500); ffmpegHandler = new FFmpegHandler(mHandler); } 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 33bd3f4..3d4f69a 100644 --- a/app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java +++ b/app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java @@ -175,7 +175,23 @@ public class VideoPreviewBar extends RelativeLayout implements HardwareDecode.On }); } + private void checkArgument(String videoPath) { + if (texturePreView == null) { + throw new IllegalStateException("Must init TextureView first..."); + } + if (videoPath == null || videoPath.isEmpty()) { + throw new IllegalStateException("videoPath is empty..."); + } + } + public void init(String videoPath, PreviewBarCallback previewBarCallback) { + checkArgument(videoPath); + this.mPreviewBarCallback = previewBarCallback; + doPreview(videoPath, new Surface(texturePreView.getSurfaceTexture())); + } + + public void initDefault(String videoPath, PreviewBarCallback previewBarCallback) { + checkArgument(videoPath); this.mPreviewBarCallback = previewBarCallback; setPreviewCallback(videoPath, texturePreView); }