VideoPlayerComponent
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
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
Gets the display mode of the VideoPlayerComponent.
Gets the MeshResource of the VideoPlayerComponent instance.
Gets the VideoTextureSampleMode of the VideoPlayerComponent set before. Default:NONE.
Gets the texture sample name of the VideoPlayerComponent set before.
Gets the material of the VideoPlayerComponent.
Gets the specified CypressMediaPlayer instance you set.
Sets the display mode of the VideoPlayerComponent.
Sets the VideoMaterial of the VideoPlayerComponent instance.
Sets the MeshResource of the VideoPlayerComponent instance.
Sets the VideoTextureSampleMode for the VideoPlayerComponent instance. Default is NONE. Typically used together with setTextureSampleName.
Sets the texture sample name for the VideoPlayerComponent instance.