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 对象。接下来,我们使用 `

相关内容

热门资讯

发现玩家!德扑圈辅助挂多功能透... 发现玩家!德扑圈辅助挂多功能透视工具,本来是有挂(有挂细节)1、不需要AI权限,帮助你快速的进行德扑...
玩家实测!德扑圈辅助挂多功能透... 玩家实测!德扑圈辅助挂多功能透视工具,一直是有挂(有挂透视)德扑圈是不是有人用挂微扑克wpk插件教程...
科普攻略!德普之星辅助挂多功能... 科普攻略!德普之星辅助挂多功能透视工具,一直是真的有挂(有挂头条)德普之星是不是有人用挂微扑克wpk...
科普常识!智星菠萝德州辅助挂多... 科普常识!智星菠萝德州辅助挂多功能透视工具,真是真的是有挂(发现有挂)1、完成智星菠萝德州辅助器v3...
玩家必看攻略!AAPoKer辅... 玩家必看攻略!AAPoKer辅助挂多功能透视工具,确实是有挂(竟然有挂)1、不需要AI权限,帮助你快...
免费测试版!WPK辅助挂多功能... 免费测试版!WPK辅助挂多功能透视工具,真是是有挂(真的有挂)1、很好的工具软件,可以解锁游戏的WP...
玩家必看科普!AAPoKer辅... 玩家必看科普!AAPoKer辅助挂多功能透视工具,其实有挂(揭秘有挂)1、AAPoKer有没有辅助教...
一分钟揭秘!AAPoKer辅助... 一分钟揭秘!AAPoKer辅助挂多功能透视工具,都是有挂(揭秘有挂)1、AAPoKer模拟器是什么优...
今日科普!微扑克辅助挂多功能透... 今日科普!微扑克辅助挂多功能透视工具,果然真的有挂(有挂工具)1、微扑克模拟器是什么优化,微扑克俱乐...
终于懂了!微扑克辅助挂多功能透... 终于懂了!微扑克辅助挂多功能透视工具,真是真的有挂(确实有挂)一、微扑克可以开透视的定义与意义1、微...