Take Screenshot Simultaneously While Recording Screen using media Projection API in Android

41 Views Asked by At

I am working with Media Projection API to Record Screen. But I also want to Capture Screenshot of device screen while recording is running. I searched a lot but couldn't find any details on how to achieve this functionality.

I have achieved taking screenshot with Media Projection API by setting ImageReader surface to Virtual Display then it calls ImageAvailable Listener when something is changed on screen but it does not work as expected when screen recording is running.

If screen recording is running and I also execute above screenshot taking code it does takes screenshot but than output video stops at time where the screenshot is taken. for example if I record video which is 10 seconds long and I took screenshot at 5 seconds mark than output video will end at 5 second mark exactly the time when screenshot was taken and player shows video duration of 10 seconds.

How to fix this issue or How this functionality can be achieved?

I am using code from following repo for both screenshot and screen recording functionality if someone wants to see the code.

https://github.com/mtsahakis/MediaProjectionDemo/tree/master/app/src/main/java/com/mtsahakis/mediaprojectiondemo

0

There are 0 best solutions below