AndroidTV上Netflix/Youtube上MediaProjection和ImageReader组合不起作用
创始人
2024-08-21 22:30:17
0

这是因为 Media Projection 和 Image Reader 无法跨进程使用,而 Netflix/Youtube 通常在自己的进程中运行。为了在 Netflix/Youtube 上使用 Media Projection 和 Image Reader,您需要使用 Android TV 上的屏幕录制功能来捕获屏幕上的视频帧。以下是示例代码:

private MediaProjectionManager mProjectionManager;
private MediaProjection mMediaProjection;
private VirtualDisplay mVirtualDisplay;
private ImageReader mImageReader;

private void startProjection() {
    if (mProjectionManager == null) {
        mProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    }
    Intent intent = mProjectionManager.createScreenCaptureIntent();
    startActivityForResult(intent, REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        mMediaProjection = mProjectionManager.getMediaProjection(resultCode, data);

        // Set up the ImageReader
        int width = getWindowManager().getDefaultDisplay().getWidth();
        int height = getWindowManager().getDefaultDisplay().getHeight();
        int dpi = getResources().getDisplayMetrics().densityDpi;
        mImageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2);
        mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture",
                width, height, dpi,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
                mImageReader.getSurface(), null, null);
        mImageReader.setOnImageAvailableListener(new ImageAvailableListener(), null);
    }
}

private class ImageAvailableListener implements ImageReader.OnImageAvailableListener {
    @Override
    public void onImageAvailable(ImageReader reader) {
        Image image = reader.acquireLatestImage();
        if (image != null) {
            // Do something with the image
            // ...
            image.close();
        }
    }
}

这里的 startProjection 方法将启动屏幕捕获意图,当用户允许捕获后,onActivityResult 方法将获得 MediaProjection 对象。接下来,我们使用 `

相关内容

热门资讯

aapoker有猫腻!aapo... aapoker有猫腻!aapoker俱乐部,(aapoker外挂)本来是真的有挂(详细挂教程)科技教...
wepoke辅助机器人!wop... wepoke辅助机器人!wopoker辅助(Wepoke规律)本来真的是有挂(详细黑科技教程);1分...
wepok软件透明挂!wepo... wepok软件透明挂!wepoke脚本(德州版Wepoke)确实真的是有挂(详细计算辅助教程)1、让...
aapoker猫腻!aapok... aapoker猫腻!aapoker安卓怎么下载,(aapoker辅助)果然是有挂(详细透视辅助教程)...
wepoke计算辅助!wepo... wepoke计算辅助!wepower有辅助器吗(weopke真的有挂)果然是真的有挂(详细辅助德之星...
德扑之星猫腻!德扑软件决策,德... 德扑之星猫腻!德扑软件决策,德扑之星决策总是真的有挂(详细辅助教程);德扑之星猫腻黑科技是一款具有i...
微扑克ai机器人!德州微扑克辅... 微扑克ai机器人!德州微扑克辅助透视,(微扑克开发)真是真的有挂(详细ai辅助工具教程);亲真的是有...
微扑克游戏辅助器!微扑克真的有... 1、微扑克游戏辅助器!微扑克真的有挂吗,(微扑克微乐)一直是真的有挂(详细全自动机器人教程)。2、微...
aapoker透明挂!aapo... aapoker透明挂!aapoker辅助软件,(aapoker俱乐部后台)一贯有挂(详细透视辅助教程...
德扑ai助手!德扑之星电脑版,... 《德扑ai助手软件透明挂》是一款多人竞技的德扑ai助手辅助透视游戏,你将微扑克对手来到同一个战场,为...