Is it possible to use MediaProjection API and process every recorded frame during recording?

317 views Asked by At

I want to build an app which simulates ambilight you know from Philips TV's. For this I have an Arduino that controls my LEDs and listens for commands on the serial port to set the color of the LEDs.

In theory I want my app to record the screen of my Android TV in background. This can be achieved with the MediaProjection API. But as far as I know you can only get the video file after stopping the recording. But I want to process every frame or take a screenshot every n milliseconds.

My Question: Can you access a single frame while recording or is it possible to take a screenshot every n seconds in background using the MediaProjection API. Or is there another way achieving this?

1

There are 1 answers

0
Lukas Schüler On

After further investigation I found a Solution. You can use a ImageReader on the MediaProjection and implement its OnImageAvailable callback this callback gets called every time a VSync is done. Then you are able to extract a Bitmap from the reader.