|
@@ -7,6 +7,7 @@ import android.graphics.Bitmap;
|
|
|
import android.media.MediaMetadataRetriever;
|
|
import android.media.MediaMetadataRetriever;
|
|
|
import android.support.v7.widget.GridLayoutManager;
|
|
import android.support.v7.widget.GridLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.AttributeSet;
|
|
import android.util.AttributeSet;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
import android.view.MotionEvent;
|
|
@@ -22,7 +23,6 @@ import com.chad.library.adapter.base.BaseViewHolder;
|
|
|
import com.kfzs.cfyl.media.R;
|
|
import com.kfzs.cfyl.media.R;
|
|
|
import com.kfzs.cfyl.media.bean.VideoFrame;
|
|
import com.kfzs.cfyl.media.bean.VideoFrame;
|
|
|
import com.kfzs.cfyl.media.glide.VideoFrameTransform;
|
|
import com.kfzs.cfyl.media.glide.VideoFrameTransform;
|
|
|
-import com.kfzs.cfyl.media.util.VideoUtil;
|
|
|
|
|
import com.kfzs.cfyl.share_library.util.LogUtil;
|
|
import com.kfzs.cfyl.share_library.util.LogUtil;
|
|
|
import com.sheep.gamegroup.model.entity.Video;
|
|
import com.sheep.gamegroup.model.entity.Video;
|
|
|
|
|
|
|
@@ -181,109 +181,110 @@ public class VideoFramesView extends RelativeLayout {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public VideoFramesView initVideo(Video data) {
|
|
public VideoFramesView initVideo(Video data) {
|
|
|
- if (data == null || data.getFilePath() == null) {
|
|
|
|
|
|
|
+ if (data == null) {
|
|
|
|
|
+ LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "data is null");
|
|
|
|
|
+ return this;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (data.getFilePath() == null) {
|
|
|
LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "videoPath is null");
|
|
LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "videoPath is null");
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
File videoFile = new File(data.getFilePath());
|
|
File videoFile = new File(data.getFilePath());
|
|
|
if (!videoFile.exists()) {
|
|
if (!videoFile.exists()) {
|
|
|
LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "videoFile not exists");
|
|
LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "videoFile not exists");
|
|
|
- return this;
|
|
|
|
|
}
|
|
}
|
|
|
if (!videoFile.canRead()) {
|
|
if (!videoFile.canRead()) {
|
|
|
LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "videoFile cant read");
|
|
LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "videoFile cant read");
|
|
|
- return this;
|
|
|
|
|
}
|
|
}
|
|
|
if (data.getDuration() < 1) {
|
|
if (data.getDuration() < 1) {
|
|
|
LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "duration < 1");
|
|
LogUtil.println(VideoFramesView.class.getSimpleName(), "showList", "error", "duration < 1");
|
|
|
- return this;
|
|
|
|
|
}
|
|
}
|
|
|
this.video = data;
|
|
this.video = data;
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private List<Bitmap> bitmapList = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 显示视频帧图片列表
|
|
|
|
|
- */
|
|
|
|
|
- public VideoFramesView showVideoList1(final Activity activity) {
|
|
|
|
|
- final int size = 10;
|
|
|
|
|
- long duration = video.getDuration();
|
|
|
|
|
- final long per = duration * 1000L / size;
|
|
|
|
|
- int max = 20;
|
|
|
|
|
- int width = max, height = max;
|
|
|
|
|
- if (video.getWidth() > video.getHeight()) {
|
|
|
|
|
- width = max * video.getWidth() / video.getHeight();
|
|
|
|
|
- } else {
|
|
|
|
|
- height = max * video.getHeight() / video.getWidth();
|
|
|
|
|
- }
|
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
|
|
- final int finalWidth = width;
|
|
|
|
|
- final int finalHeight = height;
|
|
|
|
|
- final int finalI = i;
|
|
|
|
|
- new Thread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- Bitmap bitmap = VideoUtil.getVideoFrameBitmap(video, finalI * per, finalWidth, finalHeight);
|
|
|
|
|
- bitmapList.add(bitmap);
|
|
|
|
|
- activity.runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- if (recyclerView.getAdapter() != null)
|
|
|
|
|
- recyclerView.getAdapter().notifyDataSetChanged();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }).start();
|
|
|
|
|
- }
|
|
|
|
|
- recyclerView.setLayoutManager(new GridLayoutManager(activity.getApplicationContext(), size));
|
|
|
|
|
- BaseQuickAdapter<Bitmap, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<Bitmap, BaseViewHolder>(R.layout.item_iv_mh, bitmapList) {
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void convert(BaseViewHolder helper, Bitmap item) {
|
|
|
|
|
- ImageView imageView = helper.getView(R.id.item_iv);
|
|
|
|
|
- imageView.setImageBitmap(item);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- recyclerView.setAdapter(baseQuickAdapter);
|
|
|
|
|
-
|
|
|
|
|
- return this;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 显示视频帧图片列表
|
|
|
|
|
- */
|
|
|
|
|
- public VideoFramesView showVideoList2(final Activity activity) {
|
|
|
|
|
- new Thread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- final int size = 10;
|
|
|
|
|
- final List<Bitmap> bitmapList = VideoUtil.getVideoFrameBitmapList(video, size);
|
|
|
|
|
- activity.runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- recyclerView.setLayoutManager(new GridLayoutManager(activity.getApplicationContext(), size));
|
|
|
|
|
- BaseQuickAdapter<Bitmap, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<Bitmap, BaseViewHolder>(R.layout.item_iv_mh, bitmapList) {
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void convert(BaseViewHolder helper, Bitmap item) {
|
|
|
|
|
- ImageView imageView = helper.getView(R.id.item_iv);
|
|
|
|
|
- imageView.setImageBitmap(item);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- recyclerView.setAdapter(baseQuickAdapter);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- }).start();
|
|
|
|
|
-
|
|
|
|
|
- return this;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+// private List<Bitmap> bitmapList = new ArrayList<>();
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 显示视频帧图片列表
|
|
|
|
|
+// */
|
|
|
|
|
+// public VideoFramesView showVideoList1(final Activity activity) {
|
|
|
|
|
+// final int size = 10;
|
|
|
|
|
+// long duration = video.getDuration();
|
|
|
|
|
+// final long per = duration * 1000L / size;
|
|
|
|
|
+// int max = 20;
|
|
|
|
|
+// int width = max, height = max;
|
|
|
|
|
+// if (video.getWidth() > video.getHeight()) {
|
|
|
|
|
+// width = max * video.getWidth() / video.getHeight();
|
|
|
|
|
+// } else {
|
|
|
|
|
+// height = max * video.getHeight() / video.getWidth();
|
|
|
|
|
+// }
|
|
|
|
|
+// for (int i = 0; i < size; i++) {
|
|
|
|
|
+// final int finalWidth = width;
|
|
|
|
|
+// final int finalHeight = height;
|
|
|
|
|
+// final int finalI = i;
|
|
|
|
|
+// new Thread(new Runnable() {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void run() {
|
|
|
|
|
+// Bitmap bitmap = VideoUtil.getVideoFrameBitmap(video, finalI * per, finalWidth, finalHeight);
|
|
|
|
|
+// bitmapList.add(bitmap);
|
|
|
|
|
+// activity.runOnUiThread(new Runnable() {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void run() {
|
|
|
|
|
+// if (recyclerView.getAdapter() != null)
|
|
|
|
|
+// recyclerView.getAdapter().notifyDataSetChanged();
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
|
|
+// }
|
|
|
|
|
+// }).start();
|
|
|
|
|
+// }
|
|
|
|
|
+// recyclerView.setLayoutManager(new GridLayoutManager(activity.getApplicationContext(), size));
|
|
|
|
|
+// BaseQuickAdapter<Bitmap, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<Bitmap, BaseViewHolder>(R.layout.item_iv_mh, bitmapList) {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// protected void convert(BaseViewHolder helper, Bitmap item) {
|
|
|
|
|
+// ImageView imageView = helper.getView(R.id.item_iv);
|
|
|
|
|
+// imageView.setImageBitmap(item);
|
|
|
|
|
+// }
|
|
|
|
|
+// };
|
|
|
|
|
+// recyclerView.setAdapter(baseQuickAdapter);
|
|
|
|
|
+//
|
|
|
|
|
+// return this;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 显示视频帧图片列表
|
|
|
|
|
+// */
|
|
|
|
|
+// public VideoFramesView showVideoList2(final Activity activity) {
|
|
|
|
|
+// new Thread(new Runnable() {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void run() {
|
|
|
|
|
+// final int size = 10;
|
|
|
|
|
+// final List<Bitmap> bitmapList = VideoUtil.getVideoFrameBitmapList(video, size);
|
|
|
|
|
+// activity.runOnUiThread(new Runnable() {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void run() {
|
|
|
|
|
+// recyclerView.setLayoutManager(new GridLayoutManager(activity.getApplicationContext(), size));
|
|
|
|
|
+// BaseQuickAdapter<Bitmap, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<Bitmap, BaseViewHolder>(R.layout.item_iv_mh, bitmapList) {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// protected void convert(BaseViewHolder helper, Bitmap item) {
|
|
|
|
|
+// ImageView imageView = helper.getView(R.id.item_iv);
|
|
|
|
|
+// imageView.setImageBitmap(item);
|
|
|
|
|
+// }
|
|
|
|
|
+// };
|
|
|
|
|
+// recyclerView.setAdapter(baseQuickAdapter);
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+// }).start();
|
|
|
|
|
+//
|
|
|
|
|
+// return this;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
/**
|
|
/**
|
|
|
* 显示视频帧图片列表
|
|
* 显示视频帧图片列表
|
|
|
*/
|
|
*/
|
|
|
- public VideoFramesView showVideoList3(final Activity activity) {
|
|
|
|
|
|
|
+ public VideoFramesView showVideoList(final Activity activity) {
|
|
|
List<VideoFrame> videoFrameList = new ArrayList<>();
|
|
List<VideoFrame> videoFrameList = new ArrayList<>();
|
|
|
final int size = 10;
|
|
final int size = 10;
|
|
|
long duration = video.getDuration();
|
|
long duration = video.getDuration();
|
|
@@ -299,13 +300,13 @@ public class VideoFramesView extends RelativeLayout {
|
|
|
for (int i = 0; i < size; i++) {
|
|
for (int i = 0; i < size; i++) {
|
|
|
videoFrameList.add(new VideoFrame().setVideoPath(path).setAtTime(i * per).setWidth(width).setHeight(height));
|
|
videoFrameList.add(new VideoFrame().setVideoPath(path).setAtTime(i * per).setWidth(width).setHeight(height));
|
|
|
}
|
|
}
|
|
|
- recyclerView.setLayoutManager(new GridLayoutManager(activity.getApplicationContext(), 10));
|
|
|
|
|
|
|
+ recyclerView.setLayoutManager(new GridLayoutManager(activity.getApplicationContext(), size));
|
|
|
BaseQuickAdapter<VideoFrame, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<VideoFrame, BaseViewHolder>(R.layout.item_iv_mh, videoFrameList) {
|
|
BaseQuickAdapter<VideoFrame, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<VideoFrame, BaseViewHolder>(R.layout.item_iv_mh, videoFrameList) {
|
|
|
@Override
|
|
@Override
|
|
|
protected void convert(BaseViewHolder helper, VideoFrame item) {
|
|
protected void convert(BaseViewHolder helper, VideoFrame item) {
|
|
|
ImageView imageView = helper.getView(R.id.item_iv);
|
|
ImageView imageView = helper.getView(R.id.item_iv);
|
|
|
Glide.with(activity.getApplicationContext()).load(item.getVideoPath())
|
|
Glide.with(activity.getApplicationContext()).load(item.getVideoPath())
|
|
|
- .apply(RequestOptions.frameOf(item.getAtTime()).set(VideoBitmapDecoder.FRAME_OPTION, MediaMetadataRetriever.OPTION_CLOSEST).transform(new VideoFrameTransform(item, false)))
|
|
|
|
|
|
|
+ .apply(RequestOptions.frameOf(item.getAtTime()).set(VideoBitmapDecoder.FRAME_OPTION, MediaMetadataRetriever.OPTION_CLOSEST).transform(new VideoFrameTransform(item)))
|
|
|
.into(imageView);
|
|
.into(imageView);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -313,40 +314,52 @@ public class VideoFramesView extends RelativeLayout {
|
|
|
|
|
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
- /**
|
|
|
|
|
- * 显示视频帧图片列表
|
|
|
|
|
- */
|
|
|
|
|
- public VideoFramesView showVideoList(final Activity activity) {
|
|
|
|
|
- List<VideoFrame> videoFrameList = new ArrayList<>();
|
|
|
|
|
- final int size = 10;
|
|
|
|
|
- long duration = video.getDuration();
|
|
|
|
|
- final long per = duration * 1000L / size;
|
|
|
|
|
- int max = 20;
|
|
|
|
|
- int width = max, height = max;
|
|
|
|
|
- if (video.getWidth() > video.getHeight()) {
|
|
|
|
|
- width = max * video.getWidth() / video.getHeight();
|
|
|
|
|
- } else {
|
|
|
|
|
- height = max * video.getHeight() / video.getWidth();
|
|
|
|
|
- }
|
|
|
|
|
- String path = video.getFilePath();
|
|
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
|
|
- videoFrameList.add(new VideoFrame().setVideoPath(path).setAtTime(i * per)
|
|
|
|
|
- .setWidth(width).setHeight(height)
|
|
|
|
|
- .setWidth(video.getWidth()).setHeight(video.getHeight())
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- recyclerView.setLayoutManager(new GridLayoutManager(activity.getApplicationContext(), size));
|
|
|
|
|
- BaseQuickAdapter<VideoFrame, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<VideoFrame, BaseViewHolder>(R.layout.item_iv_mh, videoFrameList) {
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void convert(BaseViewHolder helper, VideoFrame item) {
|
|
|
|
|
- ImageView imageView = helper.getView(R.id.item_iv);
|
|
|
|
|
- Glide.with(activity.getApplicationContext()).load(R.drawable.qiandao).apply(new RequestOptions().transform(new VideoFrameTransform(item))).into(imageView);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- recyclerView.setAdapter(baseQuickAdapter);
|
|
|
|
|
-
|
|
|
|
|
- return this;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 显示视频帧图片列表
|
|
|
|
|
+// */
|
|
|
|
|
+// public VideoFramesView showVideoList(final Activity activity) {
|
|
|
|
|
+// if(TextUtils.equals(android.os.Build.CPU_ABI, "x86")) {//x86不兼容,不能在模拟器中连续调用FFmpegMediaMetadataRetriever
|
|
|
|
|
+// return showVideoList1(activity);
|
|
|
|
|
+// } else {
|
|
|
|
|
+// return showVideoList2(activity);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// /**
|
|
|
|
|
+// * 显示视频帧图片列表
|
|
|
|
|
+// */
|
|
|
|
|
+// public VideoFramesView showVideoList2(final Activity activity) {
|
|
|
|
|
+// List<VideoFrame> videoFrameList = new ArrayList<>();
|
|
|
|
|
+// final int size = 10;
|
|
|
|
|
+// long duration = video.getDuration();
|
|
|
|
|
+// final long per = duration * 1000L / size;
|
|
|
|
|
+// int max = 20;
|
|
|
|
|
+// int width = max, height = max;
|
|
|
|
|
+// if (video.getWidth() > video.getHeight()) {
|
|
|
|
|
+// width = max * video.getWidth() / video.getHeight();
|
|
|
|
|
+// } else {
|
|
|
|
|
+// height = max * video.getHeight() / video.getWidth();
|
|
|
|
|
+// }
|
|
|
|
|
+// String path = video.getFilePath();
|
|
|
|
|
+// for (int i = 0; i < size; i++) {
|
|
|
|
|
+// videoFrameList.add(new VideoFrame().setVideoPath(path).setAtTime(i * per)
|
|
|
|
|
+// .setWidth(width).setHeight(height)
|
|
|
|
|
+// .setWidth(video.getWidth()).setHeight(video.getHeight())
|
|
|
|
|
+// );
|
|
|
|
|
+// }
|
|
|
|
|
+// recyclerView.setLayoutManager(new GridLayoutManager(activity.getApplicationContext(), size));
|
|
|
|
|
+// BaseQuickAdapter<VideoFrame, BaseViewHolder> baseQuickAdapter = new BaseQuickAdapter<VideoFrame, BaseViewHolder>(R.layout.item_iv_mh, videoFrameList) {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// protected void convert(BaseViewHolder helper, VideoFrame item) {
|
|
|
|
|
+// ImageView imageView = helper.getView(R.id.item_iv);
|
|
|
|
|
+// Glide.with(activity.getApplicationContext()).load(R.drawable.qiandao)
|
|
|
|
|
+// .apply(new RequestOptions().transform(new VideoFrameTransform(item)))
|
|
|
|
|
+// .into(imageView);
|
|
|
|
|
+// }
|
|
|
|
|
+// };
|
|
|
|
|
+// recyclerView.setAdapter(baseQuickAdapter);
|
|
|
|
|
+//
|
|
|
|
|
+// return this;
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
private Action1<Float> onTimeChangeListener;
|
|
private Action1<Float> onTimeChangeListener;
|
|
|
|
|
|