VideoComponent

@MainThread
class VideoComponent : Component

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

Link copied to clipboard
constructor(meshResource: MeshResource, videoMaterial: VideoMaterial)

Creates a VideoComponent instance with the given MeshResource and VideoMaterial.

Functions

Link copied to clipboard
open override fun clone(): Component

Creates and returns a copy of this Component instance.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun getAudioBindId(): Long?

Gets the audio binding ID when using VideoComponent to play video with spatial audio effects.

Link copied to clipboard

Gets the display mode of the VideoComponent.

Link copied to clipboard

Gets the mesh of the VideoComponent.

Link copied to clipboard
Link copied to clipboard
fun getTextureSampleName(): String

Gets the texture sample name of the VideoComponent set before.

Link copied to clipboard

Gets the transform mode of the video image.

Link copied to clipboard

Gets the material of the VideoComponent.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun setCropRect(transformMode: Int, rect: Rect)

Sets the crop rectangle of the VideoComponent.

Link copied to clipboard
fun setDisplayMode(displayMode: DisplayMode)

Sets the display mode of the VideoComponent.

Link copied to clipboard
fun setMaterial(videoMaterial: VideoMaterial)

Sets the material of the VideoComponent.

Link copied to clipboard
fun setMesh(meshResource: MeshResource)

Sets the mesh for the VideoComponent.

Link copied to clipboard

Sets the VideoTextureSampleMode for the VideoComponent instance. Default is NONE. Typically used together with setTextureSampleName.

Link copied to clipboard
fun setTextureSampleName(textureSampleName: String)

Sets the texture sample name for the VideoComponent instance.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun trimMarginRect(marginRect: Rect)

Sets the margin rectangle of the VideoComponent.