Take camera screenshot while recording - Like in Galaxy S3?

≯℡__Kan透↙ 提交于 2019-12-01 10:31:47

Well after hours, I got a nice solution for that.
Maybe it isn't the best way, but it is good enough for me.

private long start;
private long end;
private long period;

First get a start time right after the media recorder starts:

private void startRecording()
{
   mMediaRecoder.start();
   start = System.currentTimeMillis();
}

Then, when u press on the screen/button for taking screenshot, save the period:

private void captureImage()
{
   end = System.currentTimeMillis();
   period = end - start;
}

Finally, when you stop recording, get the bitmap using the period and the Media retriever:

private void saveVideo()
{
   MediaMetadataRetriever retriever = new MediaMetadataRetriever();
   //path -> the path to the video
   retriever.setDataSource(path);
   Bitmap bitmap = retriever.getFrameAtTime(period * 1000,MediaMetadataRetriever.OPTION_CLOSEST);
}

Hope it helps you!

No cache is maintained for the surfaceview. That is why you are not able get the cached bitmap. Actually when any view is render and its cache is turned on the view bitmap is render no mathematical calculation is done by system for drawing to improve the efficiency of rendering of view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!