视频预览改为选择文件播放

视频预览改为选择文件播放
pull/107/head
xufulong 5 years ago
parent 5165277b64
commit e64559b722
  1. 20
      app/src/main/java/com/frank/ffmpeg/activity/VideoPreviewActivity.java
  2. 4
      app/src/main/java/com/frank/ffmpeg/activity/VideoReverseActivity.java
  3. 16
      app/src/main/java/com/frank/ffmpeg/view/VideoPreviewBar.java

@ -2,7 +2,6 @@ package com.frank.ffmpeg.activity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.Environment;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
@ -18,6 +17,8 @@ import com.frank.ffmpeg.view.VideoPreviewBar;
import java.io.IOException; import java.io.IOException;
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_TOAST;
/** /**
* 视频拖动实时预览 * 视频拖动实时预览
* Created by frank on 2019/11/16. * 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 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 MediaPlayer mediaPlayer;
private SurfaceView surfaceVideo;
private VideoPreviewBar videoPreviewBar; private VideoPreviewBar videoPreviewBar;
private final static int TIME_UPDATE = 1000; private final static int TIME_UPDATE = 1000;
private final static int MSG_UPDATE = 1234; private final static int MSG_UPDATE = 1234;
@ -48,6 +44,8 @@ public class VideoPreviewActivity extends BaseActivity implements VideoPreviewBa
videoPreviewBar.updateProgress(mediaPlayer.getCurrentPosition()); videoPreviewBar.updateProgress(mediaPlayer.getCurrentPosition());
} }
mHandler.sendEmptyMessageDelayed(MSG_UPDATE, TIME_UPDATE); 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); super.onCreate(savedInstanceState);
initView(); initView();
mHandler.sendEmptyMessageDelayed(MSG_TOAST, 500);
} }
private void initView() { private void initView() {
SurfaceView surfaceVideo = getView(R.id.surface_view); surfaceVideo = getView(R.id.surface_view);
setPlayCallback(videoPath, surfaceVideo);
videoPreviewBar = getView(R.id.preview_video); videoPreviewBar = getView(R.id.preview_video);
videoPreviewBar.init(videoPath, this);
} }
private void setPlayCallback(final String filePath, SurfaceView surfaceView) { private void setPlayCallback(final String filePath, SurfaceView surfaceView) {
@ -127,7 +124,8 @@ public class VideoPreviewActivity extends BaseActivity implements VideoPreviewBa
@Override @Override
void onSelectedFile(String filePath) { void onSelectedFile(String filePath) {
setPlayCallback(filePath, surfaceVideo);
videoPreviewBar.init(filePath, this);
} }
@Override @Override

@ -40,7 +40,7 @@ public class VideoReverseActivity extends BaseActivity {
if (msg.what == MSG_FINISH){ if (msg.what == MSG_FINISH){
changeVisibility(); changeVisibility();
startPlay(); startPlay();
}else if (msg.what == MSG_TOAST) { } else if (msg.what == MSG_TOAST) {
showToast(getString(R.string.please_click_select)); showToast(getString(R.string.please_click_select));
} }
} }
@ -57,7 +57,7 @@ public class VideoReverseActivity extends BaseActivity {
initView(); initView();
initPlayer(); initPlayer();
mHandler.sendEmptyMessageDelayed(MSG_TOAST, 1000); mHandler.sendEmptyMessageDelayed(MSG_TOAST, 500);
ffmpegHandler = new FFmpegHandler(mHandler); ffmpegHandler = new FFmpegHandler(mHandler);
} }

@ -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) { 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; this.mPreviewBarCallback = previewBarCallback;
setPreviewCallback(videoPath, texturePreView); setPreviewCallback(videoPath, texturePreView);
} }

Loading…
Cancel
Save