为什么Sceneform 1.17.1仅显示音频而不显示视频?

时间:2020-08-19 21:06:02

标签: java android arcore sceneform

我正在使用Sceneform创建一个AR应用程序,无论到目前为止我做了什么尝试,Sceneform都无法在图像上正确显示视频。这是相机检测到图像时得到的结果: The Video Image that I get

这是我在相应课程上的代码:

texture = new ExternalTexture();

    mediaPlayer = MediaPlayer.create(this, R.raw.video);
    mediaPlayer.setSurface(texture.getSurface());
    mediaPlayer.setLooping(true);

    ModelRenderable
            .builder()
            .setSource(this, Uri.parse("video_screen.sfb"))
            .build()
            .thenAccept(modelRenderable -> {
                renderable = modelRenderable;
                modelRenderable.getMaterial().setExternalTexture("videoTexture",
                        texture);
                modelRenderable.getMaterial().setFloat4("keyColor",
                        new Color(0.01843f, 1f, 0.098f));
            })
            .exceptionally(
                    throwable -> {
                        Toast toast = Toast.makeText(this, "Unable to load video renderable", Toast.LENGTH_LONG);
                        toast.setGravity(Gravity.CENTER, 0, 0);
                        toast.show();
                        return null;
                    });


    arFragment = (com.stratos.syrostownhall.CustomArFragment)getSupportFragmentManager().findFragmentById(R.id.arFragment);

    if (arFragment != null) {
        scene = arFragment.getArSceneView().getScene();
    }

    scene.addOnUpdateListener(this::onUpdate);

}

private void onUpdate(FrameTime frameTime) {

    if (isImageDetected)
        return;

    Frame frame = arFragment.getArSceneView().getArFrame();

    Collection<AugmentedImage> augmentedImages =
            frame != null ? frame.getUpdatedTrackables(AugmentedImage.class) : null;


    for (AugmentedImage painting : Objects.requireNonNull(augmentedImages)) {
        if (painting.getTrackingState() == TrackingState.TRACKING) {

            if (painting.getName().equals("painting")) {

                isImageDetected = true;

                playVideo(painting.createAnchor(painting.getCenterPose()), painting.getExtentX(),
                        painting.getExtentZ());

                break;
            }

        }
    }

}

private void playVideo(Anchor anchor, float extentX, float extentZ) {

    mediaPlayer.start();

    AnchorNode anchorNode = new AnchorNode(anchor);

    texture.getSurfaceTexture().setOnFrameAvailableListener(surfaceTexture -> {
        anchorNode.setRenderable(renderable);
        texture.getSurfaceTexture().setOnFrameAvailableListener(null);
    });

    anchorNode.setWorldScale(new Vector3(extentX, 1f, extentZ));

    scene.addChild(anchorNode);

} 

此外,我使用以下语法手动添加资产:

sceneform.asset ('sampledata/video_screen.obj',
        'default',
        'sampledata/video_screen.sfa',
        'src/main/assets/video_screen')

1 个答案:

答案 0 :(得分:0)

问题是由video_screen.sfb文件引起的。

如果其他人也遇到相同的问题,请尝试使用以下video_screen文件:

https://github.com/heyletscode/Play-Video-On-Augmented-Image/blob/master/Project/app/src/main/assets/video_screen.sfb