为什么Sceneform 1.17.1只显示音频不显示视频?
Why Sceneform 1.17.1 displays only audio and not video corectly?
我正在使用 Sceneform 创建一个 AR 应用程序,到目前为止,无论我尝试了什么,Sceneform 都无法在图像上正确显示视频。这是我在相机检测到图像时得到的结果:
The Video Image that I get
这是我在相应class上的代码:
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')
问题是由 video_screen.sfb
文件引起的。
如果其他人遇到同样的问题,请尝试使用以下 video_screen 文件:
我正在使用 Sceneform 创建一个 AR 应用程序,到目前为止,无论我尝试了什么,Sceneform 都无法在图像上正确显示视频。这是我在相机检测到图像时得到的结果: The Video Image that I get
这是我在相应class上的代码:
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')
问题是由 video_screen.sfb
文件引起的。
如果其他人遇到同样的问题,请尝试使用以下 video_screen 文件: