CypressMediaPlayer
Controls video playback in combination with VideoPlayerComponent.
Currently, as part of the Spatial Video Module, CypressMediaPlayer cannot render videos independently. It only provides APIs for controlling video playback, including play, pause, stop, and more. Video Rendering must be done with VideoPlayerComponent.
It's recommended to check the player's validity before using its APIs.
Code sample:
// Create the media player
val player = CypressMediaPlayer()
// Implement the callback
val callback =
object : CypressMediaPlayerCallback {
override fun onPrepared() {
player?.apply {
play()
Log.i(TAG, "onPrepared Event")
}
}
// Override other methods
}
// Register the callback
player.registerPlayerCallBack(callBack)
// Set the video source
player.setDataSource("your_video_path.mp4")
// Create a mesh and material
val mesh = MeshResource.generatePanel(2.0f, 1.0f, 0.3f)
val material =
VideoMaterial(
BlendingMode.TRANSPARENT,
VideoDimensionMode.SIDE_BY_SIDE,
MaterialCullingMode.BACK
)
// Create an entity, a VideoPlayerComponent, and add the component to the entity
val entity = Entity()
if (mesh.valid && material.valid) {
val videoPlayerComponent = VideoPlayerComponent(player,mesh, material)
entity.components.set(videoPlayerComponent)
// We recommend to call prepareAsync() first. Since preparation is asynchronous, you should
// wait for the [CypressMediaPlayerCallback.onPrepared] callback before other methods.
player.prepareAsync()
// Other operations to control the playback
}
// Release the resource
player.unregisterCypressMediaPlayerCallback()
player.close()Constructors
Constructs a new CypressMediaPlayer instance.
Properties
Functions
Gets the current playback position of the video in milliseconds.
Gets the total duration of the video, in milliseconds.
Gets the playback speed of the player.
Gets the height of the currently configured video data source.
Gets the width of the currently configured video data source.
Checks whether the video playback is complete.
Asynchronously prepares the video for playback.
Registers callback(s) for the player.
Sets a video file as the data source using an AssetFileDescriptor. It is safe to close the AssetFileDescriptor after setting the data source.
Sets a video file as the data source for the player.
Sets a video file as the data source using a file descriptor, offset, and length. It is safe to close the file descriptor after setting the data source.
Sets the speed for video playback.
Unregisters all callback(s) for the player.