我运行了这个例子:https://github.com/android/media-samples/tree/main/ScreenCapture
并将显示更改为公共显示,以便我可以使用scrcpy访问它:
mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture",
mSurfaceView.getWidth(), mSurfaceView.getHeight(), mScreenDensity,
DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
mSurface, null, null);
当我使用scrcpy打开显示时,我会得到一个完全黑色的屏幕,而在预览中它将正确显示。
为什么它在scrcpy中提供了一个黑色屏幕?
我假设这是因为显示不安全(警告:显示没有FLAG_SUPPORTS_PROTECTED_BUFFERS标志,镜像可以被限制),但普通应用程序无法创建安全的虚拟显示,因为权限仅针对系统应用程序。
有办法让它起作用吗?
发布于 2022-10-11 14:01:27
scrcpy显示一个黑色屏幕,因为在这个显示(您定义的显示)中,三个没有表示视图。请使用此代码在scrcpy上显示某些内容。
import android.app.ActivityOptions;
import android.app.Presentation;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
public class PresentationDisplay extends Presentation {
public PresentationDisplay(Context outerContext, Display display) {
super(outerContext, display);
}
public PresentationDisplay(Context outerContext, Display display, int theme) {
super(outerContext, display, theme);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_ui);
ActivityOptions options = ActivityOptions.makeTaskLaunchBehind();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
options.setLaunchDisplayId(getDisplay().getDisplayId());
}
Log.e("TAG", "DISPLAY_CATEGORY_PRESENTATION " + getDisplay().getDisplayId());
}
}
并使用它:
MediaRouter.RouteInfo route = ((MediaRouter) context.getSystemService(MEDIA_ROUTER_SERVICE)).getSelectedRoute(ROUTE_TYPE_LIVE_VIDEO);
if (route != null) {
PresentationDisplay secondaryDisplay = new PresentationDisplay(context,route.getPresentationDisplay());
secondaryDisplay.show();
}
https://stackoverflow.com/questions/73680519
复制相似问题