mtsahakis / MediaProjectionDemo

One Activity sample app of using Android Lollipop MediaProjection API to capture device screenshots
Other
211 stars 76 forks source link

Slows down in its own activity #8

Closed moster67 closed 7 years ago

moster67 commented 7 years ago

Many thanks for this code example. My idea is to use it as a base for screen-mirroring. I noted that when the sample app's activity is the forefront, the capture of the images slows down drastically whereas if I move on to another screen (of another app or the home-screen) the image-creation is very fast (numerous ones within a second).

Any idea why this is happening and how this can be resolved? Could a service resolve this problem?

Edit: I tried your activity/service code but with the same result.

Thank you.

mtsahakis commented 7 years ago

Hi,

I am not sure as to why you are experiencing this, in both versions of the code screen capture functionality is happening on a different Thread than the UI Thread.

Note that the OS decides when to send new images via the ImageReader.OnImageAvailableListener interface, so maybe the OS thinks that the sample app's main Activity is rather stale, so no updates are send. Try integrating the code to your own app and see if screen capture rate is sufficient when something is happening to your UI, like pressing a button or doing an animation.

Also, repeat your tests on different Android versions. We were able to identify a small break in functionality in latest Android Nougat, see https://code.google.com/p/android/issues/detail?id=231642.

Thanks,

Manos

moster67 commented 7 years ago

You were right. Once I start doing something in my Activity, the updates are much more frequent. The reason why it worked faster in my first test on a screen which was not my activity was that I had an animation on this screen so the OS detected movements and frequent updates were generated. Many thanks for your help clarifying this and once again my thanks for sharing your code.

mtsahakis commented 7 years ago

No worries, I am glad I could help.