arcore视频未显示

时间:2020-08-01 22:21:26

标签: android android-studio arcore

我想使用ARCore播放视频,但它仅显示video_screen.sfb文件的矩形形状和视频的声音

enter image description here

enter image description here

这是我的mainActivity

    ExternalTexture externalTexture = new ExternalTexture();
    MediaPlayer mediaPlayer = MediaPlayer.create(this , R.raw.n);
    mediaPlayer.setSurface(externalTexture.getSurface());
    mediaPlayer.setLooping(true);

    ModelRenderable.builder()
            .setSource(this , R.raw.video_screen)
            .build()
            .thenAccept(modelRenderable -> {
                videoRenderable = modelRenderable;
                videoRenderable.getMaterial().setExternalTexture("videoTexture" , externalTexture);
                videoRenderable.getMaterial().setFloat4("keyColor", new Color(0.01843f,1.0f, 0.098f));

            });
    ArFragment arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.arFragment);
    arFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
        AnchorNode anchorNode = new AnchorNode(hitResult.createAnchor());
        if (!mediaPlayer.isPlaying()){
            mediaPlayer.start();
            externalTexture.getSurfaceTexture().setOnFrameAvailableListener(surfaceTexture -> {
                anchorNode.setRenderable(videoRenderable);
                externalTexture.getSurfaceTexture().setOnFrameAvailableListener(null);
            });
        }
        else {
            anchorNode.setRenderable(videoRenderable);
        }

        float width = mediaPlayer.getVideoWidth();
        float height = mediaPlayer.getVideoHeight();

        anchorNode.setLocalScale(new Vector3(HEIGHT * (width/height) , HEIGHT ,1.0f));

        arFragment.getArSceneView().getScene().addChild(anchorNode);

    });

1 个答案:

答案 0 :(得分:0)

videoRenderable.getMaterial().setFloat4("keyColor", new Color(0.01843f,1.0f, 0.098f));

在此行中,使用0.0987f而不是0.098f,此行用于从视频中过滤出CHROME_KEY_COLOR,大多数最新视频具有CHROME_KEY_COLOR,因此需要确切的值。