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

视频预览改为选择文件播放
pull/107/head
xufulong 5 years ago
parent 5165277b64
commit e64559b722
  1. 20
      app/src/main/java/com/frank/ffmpeg/activity/VideoPreviewActivity.java
  2. 2
      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.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

@ -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);
}

@ -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);
}

Loading…
Cancel
Save