首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android屏幕共享面参数

Android屏幕共享面参数
EN

Stack Overflow用户
提问于 2020-05-15 05:59:57
回答 1查看 451关注 0票数 1

我正在尝试使用Agora.io在安卓上实现屏幕共享。他们的样本非常清楚:

代码语言:javascript
复制
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的?还是实例化一个新的Surface实例?使用接受SurfaceTexture作为参数的构造函数。或者可能实现SurfaceTexture.OnFrameAvailableListener / OnImageAvailableListener (不确定)。

表面医生:

https://developer.android.com/reference/android/view/Surface

createVirtualDisplay文档:

https://developer.android.com/reference/android/media/projection/MediaProjection#createVirtualDisplay(java.lang.String,%20int,%20int,%20int,%20int,%20android.view.Surface,%20android.hardware.display.VirtualDisplay.Callback,%20android.os.Handler)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-18 03:54:55

有几种方法可以获得Surface:

  1. 如果您正在进行视频编码,则使用MediaCodec.createInputSurface()作为编码模块的输入;
  2. 使用ImageReader.getSurface()创建曲面,如果您想接收YUV帧;
  3. 如果要自己绘制OpenGL,可以在OpenGL上下文下创建纹理,并使用该纹理创建SurfaceTexture,从而创建自己的SurfaceTexture。

但是请注意,不要使用已经附加到视图层次结构的Surface。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61812710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档