安卓屏幕共享--表面参数

问题描述 投票:0回答:1

我正在尝试使用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();

但是在... 创建虚拟显示器 他们有一个表面参数。我不知道这是从哪里来的--或者说,我是如何得到的?表面 的屏幕?还是要实例化一个新的Surface实例?使用接受SurfaceTexture作为参数的构造函数。或者实现SurfaceTexture.OnFrameAvailableListener OnImageAvailableListener(不确定)。

Surface docs:

https:/developer.android.comreferenceandroidviewSurface。

createVirtualDisplay文档。

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

android screen agora.io
1个回答
1
投票

你有几种方法可以获得Surface。

  1. 如果你要做一些视频编码,就用... MediaCodec.createInputSurface() 作为编码模块的输入。
  2. 创建Surface,使用 ImageReader.getSurface() 如果你想接收YUV帧。
  3. 而如果你想自己进行OpenGL渲染,你可以在OpenGL上下文下创建一个纹理,并使用该纹理创建一个SurfaceTexture,从而创建自己的Surface。

但注意,不要使用已经附着在视图层次结构中的Surface。

© www.soinside.com 2019 - 2024. All rights reserved.