I was able to figure out how to capture a video frame from a VideoView that is playing a video stored locally on the phone. However, when the video is being streamed over IP in the VideoView, it appears very difficult to capture a screenshot/image/video frame. I would appreciate a solution to this problem.
Here is a similar question which has not received an answer: How to capture a frame from video in android?
Here is a solution to capturing the video frame (ONLY if the video is stored on the phone):
public static Bitmap captureVideoFrame(Activity activity, VideoView vv, String viewSource, int currPosInMs)
{
MediaMetadataRetriever mmRetriever = new MediaMetadataRetriever();
mmRetriever.setDataSource(viewSource);
Bitmap bmFrame = mmRetriever.getFrameAtTime(currPosInMs * 1000); // unit in microsecond
if(bmFrame == null){
Toast.makeText(activity.getApplicationContext(), "Bitmap is null! Curr Position: " + currPosInMs, Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(activity.getApplicationContext(), "Bitmap is not null! Curr Position: " + currPosInMs, Toast.LENGTH_SHORT).show();
// Save file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + SCREENSHOT_DIRECTORY + "myScreenshot.png";
OutputStream fout = null;
File imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bmFrame.compress(Bitmap.CompressFormat.JPEG, 100, fout);
fout.flush();
fout.close();
Toast.makeText(activity.getApplicationContext(), "Saved file successfully!", Toast.LENGTH_SHORT).show();
}
catch(Exception e){
}
}
return bmFrame;
}