I'm doing an app that receives video stream from an RTSP address and I want to take a screenshot of stream by just touching the screen ... I've already managed to make it take the screenshot but the problem is that all screenshot are black images and I really need to solve this.
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
videoView.setDrawingCacheEnabled(true);
// Este es el código importante :)
// Sin él la vista tendrá una dimensión de 0,0 y el mapa de bits será nula
//btn.measure(VideoView.MeasureSpec.makeMeasureSpec(0, VideoView.MeasureSpec.UNSPECIFIED),
// VideoView.MeasureSpec.makeMeasureSpec(0, VideoView.MeasureSpec.UNSPECIFIED));
//btn.layout(0, 0, videoView.getMeasuredWidth(), videoView.getMeasuredHeight());
videoView.buildDrawingCache(true);
videoView.invalidate();
//videoView.buildDrawingCache(true);
final Bitmap bmp = Bitmap.createBitmap(videoView.getDrawingCache());
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
// Carpeta dónde guardamos la captura
// En este caso, la raíz de la SD Card
File sd = Environment.getExternalStorageDirectory();
// El archivo que contendrá la captura
File f = new File(sd, timeStamp+".JPEG");
try {
if (sd.canWrite()) {
f.createNewFile();
OutputStream os = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.JPEG, 90, os);
os.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
videoView.setDrawingCacheEnabled(false);
videoView.destroyDrawingCache();
}
});
I use a button and a videoview both the size of the screen and the button is transparent ... I wanted to do it only with the videoview but it does not react to the onclicklistener event