VideoPlayerComponent

@MainThread
class VideoPlayerComponent : Component

A Component that can be constructed with CypressMediaPlayer, VideoMaterial, and MeshResource, allowing you to render a 3D video.

This component allows you to play a 3D video on the surface of a specified entity. It utilizes CypressMediaPlayer as the video player and is a high-level component, Using this component for 3D video rendering is highly recommended due to its simplicity and ease of use.

Usage Example:

//Create an entity
val entity = Entity()

//Create player
val player = CypressMediaPlayer()

//Implement callback
val callback =
object : CypressMediaPlayerCallback {
override fun onPrepared() {
player?.apply {
play()
Log.i(TAG, "onPrepared Event")
}
}

override fun onStarted() {
Log.i(TAG, "onStarted Event")
}

override fun onStopped() {
Log.i(TAG, "onStopped Event")
}

override fun onCompleted() {
Log.i(TAG, "onCompleted Event")
}

override fun onSeekToCompleted() {
Log.i(TAG, "onSeekToCompleted Event")
}

override fun onError(error: CypressMediaPlayerErrorCode) {
Log.e(TAG, "onError Event, error: $error")
}

override fun onPaused() {
Log.i(TAG, "onPaused Event")
}

override fun onVideoSizeChanged(width: Int, height: Int) {
Log.i(TAG, "onVideoSizeChanged Event, width: $width, height: $height")
}
}

//Register callback
player.registerPlayerCallBack(callBack)

//setDataSource
player.setDataSource("your_video_path.mp4")


//create mesh
val mesh = MeshResource.generatePanel(2.0f, 1.0f, 0.3f)

//create material
val videoMat =
VideoMaterial(
BlendingMode.TRANSPARENT,
VideoDimensionMode.SIDE_BY_SIDE,
MaterialCullingMode.BACK
)

//create VideoPlayerComponent
if (mesh.valid && videoMat.valid) {

val videoPlayerComponent = VideoPlayerComponent(player,mesh, videoMat)

//add component to entity
entity.components.set(videoPlayerComponent)

//prepareAsync, after VideoPlayerComponent is added to entity, the video can start to play.
//you can also call the prepareAsync method to prepare the video and because the prepare is asynchronously,
//so please play it when the prepare callback happened.
player.prepareAsync()

//do something you want to do, you can control the video by the player.

}

//release resources, you can call the close method to release the resources manually one by one.
entity.destroy()

//release player when you don't need it anymore, don't forget to call the close method to release the player.
player.unregisterCypressMediaPlayerCallback()
player.close()

See also

for how to create a CypressMediaPlayer.

for how to create a VideoMaterial.

for how to create a MeshResource.

Constructors

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

Creates a VideoPlayerComponent instance with the given CypressMediaPlayer, MeshResource, and VideoMaterial, allowing the user to create a customized mesh themselves or use an existing model's mesh to render the video on the model entity's surface.

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

Gets the display mode of the VideoPlayerComponent.

Link copied to clipboard

Gets the MeshResource of the VideoPlayerComponent instance.

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

Gets the texture sample name of the VideoPlayerComponent set before.

Link copied to clipboard

Gets the material of the VideoPlayerComponent.

Link copied to clipboard

Gets the specified CypressMediaPlayer instance you set.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun setDisplayMode(displayMode: DisplayMode)

Sets the display mode of the VideoPlayerComponent.

Link copied to clipboard
fun setMaterial(material: VideoMaterial)

Sets the VideoMaterial of the VideoPlayerComponent instance.

Link copied to clipboard
fun setMesh(meshResource: MeshResource)

Sets the MeshResource of the VideoPlayerComponent instance.

Link copied to clipboard

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

Link copied to clipboard
fun setTextureSampleName(textureSampleName: String)

Sets the texture sample name for the VideoPlayerComponent instance.

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