CypressMediaPlayer

class CypressMediaPlayer : Closeable

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

Link copied to clipboard
constructor()

Constructs a new CypressMediaPlayer instance.

Properties

Link copied to clipboard
@get:JvmName(name = "isValid")
val valid: Boolean

The current state of the player.

Functions

Link copied to clipboard
open override fun close()

Releases the player manually to free the resources and memory it occupies.

Link copied to clipboard
fun getCurrentPosition(): Long

Gets the current playback position of the video in milliseconds.

Link copied to clipboard
fun getDuration(): Long

Gets the total duration of the video, in milliseconds.

Link copied to clipboard
fun getPlaybackSpeed(): Float

Gets the playback speed of the player.

Link copied to clipboard
fun getVideoHeight(): Int

Gets the height of the currently configured video data source.

Link copied to clipboard
fun getVideoWidth(): Int

Gets the width of the currently configured video data source.

Link copied to clipboard
fun getVolume(): Float

Gets the volume of video playback.

Link copied to clipboard
fun isComplete(): Boolean

Checks whether the video playback is complete.

Link copied to clipboard
fun isPlaying(): Boolean

Checks whether the video is currently playing.

Link copied to clipboard
fun pause(): Boolean

Pauses video playback.

Link copied to clipboard
fun play(): Boolean

Starts video playback.

Link copied to clipboard
fun prepare(): Boolean

Prepares the video player for playback.

Link copied to clipboard
fun prepareAsync(): Boolean

Asynchronously prepares the video for playback.

Link copied to clipboard

Registers callback(s) for the player.

Link copied to clipboard
fun reset(): Boolean

Resets the media player to its uninitialized state.

Link copied to clipboard
fun resume(): Boolean

Resumes video playback.

Link copied to clipboard
fun seekTo(time: Long): Boolean

Seeks to the specified position in the video.

Link copied to clipboard
fun setDataSource(afd: AssetFileDescriptor): Boolean

Sets a video file as the data source using an AssetFileDescriptor. It is safe to close the AssetFileDescriptor after setting the data source.

fun setDataSource(path: String): Boolean

Sets a video file as the data source for the player.

fun setDataSource(fd: Int, offset: Long, length: Long): Boolean

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.

Link copied to clipboard
fun setLoop(loop: Boolean): Boolean

Sets the loop mode for video playback.

Link copied to clipboard
fun setPlaybackSpeed(speed: Float): Boolean

Sets the speed for video playback.

Link copied to clipboard
fun setVolume(volume: Float): Boolean

Sets the volume for video playback.

Link copied to clipboard
fun stop(): Boolean

Stops video playback.

Link copied to clipboard

Unregisters all callback(s) for the player.