我正在尝试使用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文档:
答案 0 :(得分:1)
有几种方法可以获取Surface:
但是请注意,请勿使用已附加到视图层次结构的Surface。