VideoComponent
A Component that can be constructed using a provided VideoMaterial and MeshResource. With the given parameters, this component can be used to render a 3D video.
By utilizing this component, you can project a 3D video onto the surface of a chosen entity. This component integrates with third-party video players, allowing video playback through the android.view.Surface method.
Usage Example:
//Create an video player
val mediaPlayer = MediaPlayer()
mediaPlayer.setDataSource("your_video_path.mp4")
mediaPlayer.prepare()
.........
//Create a SpatialView to display the video.
val videoEntity = Entity()
SpatialView(
modifier = Modifier.size(782.dp, 412.dp),
initial = { content, _ ->
//Create a mesh for the video
val mesh = MeshResource.createPlane(0.9f, 0.45f, 0.0f)
//Create a VideoMaterial for the video.
val videoMaterial = VideoMaterial(BlendingMode.OPAQUE,
VideoDimensionMode.MONO,
MaterialCullingMode.BACK)
//Create a SurfaceRenderTexture and acquire an surface, set it to player.
val surfaceRenderTexture = SurfaceRenderTexture()
surfaceRenderTexture.toGlobal()
videoMaterial.bindSurfaceRenderTexture(surfaceRenderTexture)
if(surfaceRenderTexture.valid)
{
val surface = surfaceRenderTexture.acquireSurface()
surface?.apply{
mediaPlayer.setSurface(surface)
}
}
//Create a VideoComponent for the video.
val videoComponent = VideoComponent(mesh, videoMaterial)
//Add video component to video entity.
videoEntity.apply {
components.set(videoComponent)
}
content.addEntity(videoEntity)
//Start playing the video.
mediaPlayer.start()
})
......
//Stop and release player and resource when no longer needed.
mediaPlayer.stop()
mediaPlayer.release()
videoEntity.destroy()See also
for how to acquire android.view.Surface.
Constructors
Creates a VideoComponent instance with the given MeshResource and VideoMaterial.
Functions
Gets the audio binding ID when using VideoComponent to play video with spatial audio effects.
Gets the display mode of the VideoComponent.
Gets the mesh of the VideoComponent.
Gets the VideoTextureSampleMode of the VideoComponent set before. Default:NONE.
Gets the texture sample name of the VideoComponent set before.
Gets the transform mode of the video image.
Gets the material of the VideoComponent.
Sets the crop rectangle of the VideoComponent.
Sets the display mode of the VideoComponent.
Sets the material of the VideoComponent.
Sets the mesh for the VideoComponent.
Sets the VideoTextureSampleMode for the VideoComponent instance. Default is NONE. Typically used together with setTextureSampleName.
Sets the texture sample name for the VideoComponent instance.
Sets the margin rectangle of the VideoComponent.