首页 > 解决方案 > 两个 android 应用程序如何同时使用 MediaProjection?

问题描述

我需要两个应用程序来使用 MediaProjection API 同时录制屏幕。

当第二个应用程序开始录屏时,我发现第一个应用程序不起作用。

---代码---以及我发现的:

我用

        var projectionManager =

        getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager

    startActivityForResult(projectionManager.createScreenCaptureIntent(), 1)

请求许可。在

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

将数据另存为

  data.clone() as Intent

设置东西,我用

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
    )

要恢复记录图像,我使用

var image = mImageReader.acquireLatestImage()

当只有一个应用程序正在录制时,acquireLatestImage() 将在屏幕变化时返回图像,

当第二个应用程序开始录制时,第一个应用程序的此功能将始终返回 null。

谁能帮助我?谢谢。


我在https://github.com/zhengyitian/pxbig有一个项目可以使屏幕像素更大并变成原始 rgb 。

所有代码都来自那里。

标签: androidmediaprojection

解决方案


推荐阅读