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?
After further investigation I found a Solution. You can use a
ImageReader
on theMediaProjection
and implement itsOnImageAvailable
callback this callback gets called every time a VSync is done. Then you are able to extract a Bitmap from the reader.