android - 两个 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 。
所有代码都来自那里。
解决方案
推荐阅读
- r - 无法使用 FreeTDS 连接到 Docker 容器内的 Microsoft SQL Server
- angular - 在 Firebase 托管中启用 CORS
- flutter - MaterialApp 必须是整个应用程序中的唯一一个吗?
- java - VisualVM 为线程使用什么名称?
- python - 在 Python 中将函数导出到 .csv 或 .xlsx 文件
- javascript - 如何使用 reduce() 连接数组并删除重复的项目
- android - 在新的 Google billing Api 2.0 中确认购买后无法获取更新的购买对象
- python - 是否有标准的文档字符串格式来显示需要函数的参数的签名?
- sql - 如何在 SQL 查询中对数据进行非规范化
- r - r中绘图功能的主要项目中的“小于或等于”符号