When I find an image, I want to place a text and a video above it. The text view is placed on the scene but the video is not, it is just added to my main layout in the middle. I'm using the component VideoView, I'm not sure that's the problem
override fun onCreate(savedInstanceState: Bundle?) {
(....)
arFragment!!.arSceneView.scene.addOnUpdateListener { this.onUpdateFrame(it) }
arSceneView = arFragment!!.arSceneView
}
private fun onUpdateFrame(frameTime: FrameTime) {
val frame = arFragment!!.arSceneView.arFrame
val augmentedImages = frame.getUpdatedTrackables(AugmentedImage::class.java)
for (augmentedImage in augmentedImages) {
if (augmentedImage.trackingState == TrackingState.TRACKING) {
if (augmentedImage.name.contains("car") && !modelCarAdded) {
renderView(arFragment!!,
augmentedImage.createAnchor(augmentedImage.centerPose))
modelCarAdded = true
}
}
}
}
The text_info is only a TextView component, the video_youtube is a RelativeLayout with the VideoView inside.
private fun renderView(fragment: ArFragment, anchor: Anchor) {
//WORKING
ViewRenderable.builder()
.setView(this, R.layout.text_info)
.build()
.thenAccept { renderable ->
(renderable.view as TextView).text = "Example"
addNodeToScene(fragment, anchor, renderable, Vector3(0f, 0.2f, 0f))
}
.exceptionally { throwable ->
val builder = AlertDialog.Builder(this)
builder.setMessage(throwable.message)
.setTitle("Error!")
val dialog = builder.create()
dialog.show()
null
}
//NOT WORKING
ViewRenderable.builder()
.setView(this, R.layout.video_youtube)
.build()
.thenAccept { renderable ->
val view = renderable.view
videoRenderable = renderable
val path = "android.resource://" + packageName + "/" + R.raw.googlepixel
view.video_player.setVideoURI(Uri.parse(path))
renderable.material.setExternalTexture("videoTexture", texture)
val videoNode = addNodeToScene(fragment, anchor, renderable, Vector3(0.2f, 0.5f, 0f))
if (!view.video_player.isPlaying) {
view.video_player.start()
texture
.surfaceTexture
.setOnFrameAvailableListener {
videoNode.renderable = videoRenderable
texture.surfaceTexture.setOnFrameAvailableListener(null)
}
} else {
videoNode.renderable = videoRenderable
}
}
.exceptionally { throwable ->
null
}
}
private fun addNodeToScene(fragment: ArFragment, anchor: Anchor, renderable: Renderable, vector3: Vector3): Node {
val anchorNode = AnchorNode(anchor)
val node = TransformableNode(fragment.transformationSystem)
node.renderable = renderable
node.setParent(anchorNode)
node.localPosition = vector3
fragment.arSceneView.scene.addChild(anchorNode)
return node
}
I tried using the Chroma Key Video example but I don't want the white parts of the video to be transparent. And I'm not sure that I need the model (.sfb) to show a video.