android - Android Screen Share - 表面参数
问题描述
我正在尝试使用 Agora.io 在 Android 上实现屏幕共享。他们的样本很清楚:
MediaProjectionManager projectManager = (MediaProjectionManager) mContext.getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
// Create the intent for screen capture. Call the startActivityForResult method to use the sharing function.
Intent intent = projectManager.createScreenCaptureIntent();
startActivityForResult(intent);
MediaProjection projection;
VirtualDisplay display;
// Override and implement the onActivityResult method of the Activity where you just called startActivityForResult.
@Override
onActivityResult(int requestCode, int resultCode, Intent resuleData) {
projection = projectManager.getMediaProjection(resultCode, resultData);
display = projection.createVirtualDisplay(name, width, height, dpi, flags, surface, callback, handler);
}
// The texture retrieved from the Surface will be sent by the SDK.
rtcEngine.pushExternalVideoFrame(new AgoraVideoFrame(...));
// Stop screen sharing.
projection.stop();
然而在createVirtualDisplay它们是一个表面参数。我不确定它来自哪里 - 或者更多我如何获得屏幕表面?还是我要实例化一个新的 Surface 实例?使用接受 SurfaceTexture 作为参数的构造函数。或者可能实现 SurfaceTexture.OnFrameAvailableListener / OnImageAvailableListener (不确定)。
表面文档:
https://developer.android.com/reference/android/view/Surface
createVirtualDisplay 文档:
解决方案
您可以通过多种方式获取 Surface:
- 如果你正在做一些视频编码,使用MediaCodec.createInputSurface()作为编码模块的输入;
- 如果要接收 YUV 帧,请使用ImageReader.getSurface()创建 Surface ;
- 如果你想自己做 OpenGL 渲染,你可以在 OpenGL 上下文下创建一个纹理,并使用该纹理创建一个 SurfaceTexture,从而创建你自己的 Surface。
但请注意,不要使用已附加到视图层次结构的 Surface。
推荐阅读
- alpine.js - 在函数中访问 x 数据
- asp.net-core - .Net Core 仅在上传文件时被 CORS 策略错误阻止
- nearprotocol - 如何免费查看 NEAR 协议合约中的数据?
- c++ - 什么是 C++ 中的公共接口
- python - 我的列表比较器不想按照我想要的方式运行
- java - 当我无法更改原始函数时如何在java中将函数作为方法参数传递
- vba - 修改ms访问图表ValueAxis最小值
- excel - 如何将两列与数据合并,如果一列的单元格为空,则相邻的单元格已满?
- amazon-web-services - 无法解析 AmazonS3 依赖项导入
- javascript - 更改请求的响应缓存标头