I am new to AR, trying to apply video texture to materialInstance by creating a surfaceTexture stream and using this stream to create the videoTexture , surfaceTexture is being updated by a video with MediaPlayer.
For my implementation I am getting “stream has not been initialized” error.
How can this be corrected?
Is there any other way to build and add videoTexture to materialInstance in sceneview:2.2.0?
private fun applyVideoTexture(
context: Context,
engine: Engine,
materialInstance: MaterialInstance
) {
try {
val surfaceTexture = SurfaceTexture(1)
val stream = Stream.Builder()
.stream(surfaceTexture)
.build(engine)
val videoTexture = VideoTexture.Builder()
.build(engine)
videoTexture.setExternalStream(engine, stream) // Attach the Stream
val mediaPlayer = MediaPlayer.create(context, R.raw.samp)
mediaPlayer.setSurface(Surface(surfaceTexture))
mediaPlayer.isLooping = true
mediaPlayer.start()
materialInstance.setParameter("texture", videoTexture, TextureSampler())
} catch (e: Exception) {
e.printStackTrace()
}
}
Abhi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.