我正在使用sceneform创建一个ar应用程序,不管我做了什么尝试,sceneform都不能在图像上正确显示视频。这是我在相机检测到图像时得到的结果:我得到的视频图像
下面是我在相应类上的代码:
纹理=新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条答案
按热度按时间qlvxas9a1#
问题是由
video_screen.sfb
文件。如果其他人也面临同样的问题,请尝试使用以下视频屏幕文件:
https://github.com/heyletscode/play-video-on-augmented-image/blob/master/project/app/src/main/assets/video_screen.sfb