how two android apps use MediaProjection at the same time?

566 views Asked by At

I need two apps to use the MediaProjection API to record the screen at the same time.

When the second app starts to record the screen, I found that the first one not working.

---code--- and what I found:

I use

        var projectionManager =

        getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager

    startActivityForResult(projectionManager.createScreenCaptureIntent(), 1)

to ask permission. in

 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) 

save data as

  data.clone() as Intent

to set things up,i use

mImageReader = ImageReader.newInstance(
        mScreenWidth,
        mScreenHeight,
        PixelFormat.RGBA_8888,
        2
    )

 getMediaProjectionManager().getMediaProjection(Activity.RESULT_OK, mResultData)

mVirtualDisplay = mMediaProjection!!.createVirtualDisplay(
        "screen-mirror",
        mScreenWidth, mScreenWidth,
        mScreenDensity,
        DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mImageReader?.surface,
        null,
        null
    )

to get record image back,i use

var image = mImageReader.acquireLatestImage()

when only one app is recording, acquireLatestImage() will return image when the screen changes,

when the second app starts to record, this function of the first app will always return null.

Could anyone help me?Thanks.


I have a project to make screen pixels bigger and into raw rgb, at https://github.com/zhengyitian/pxbig.

All code come from there.

0

There are 0 answers