Timing the capture of screen shots using Androids MediaProjector

313 views Asked by At

I have used mtsahkis's example to implement a screen capture system on Android: https://github.com/mtsahakis/MediaProjectionDemo/blob/master/src/com/mtsahakis/mediaprojectiondemo/ScreenCaptureImageActivity.java

The basic implementation works very well, but I am having an issue understanding how to control the speed of the creation of screen shots.

I can see that the VirtualDisplay is fed an ImageReader and a Handler, the image reader has an setOnImageAvailableListener attached, so presumably this is what is throttling the speed of capture, which on my Galaxy edge is an inconsistent 1 capture a second.

Has anyone with more experience of using Handlers know how to set a consistent timing on the thread? would that be done when creating the thread?

    // start capture handling thread
    new Thread()
    {
        @Override
        public void run()
        {
            Looper.prepare();
            mHandler = new Handler();
            Looper.loop();
        }
    }.start();

Best

Steve

1

There are 1 answers

0
Steve On BEST ANSWER

I contacted the author of the Media projection demo repository, his suggestion was to simply sleep the thread within the onImageAvailable listener, this is working very well for my purposes.

Thread.sleep(mi_Delay);