Skip to main content

Player Methods & Events

The TPStreamsPlayer provides several public methods and properties to control playback and query state.

Player Methods​

MethodDescription
play()Starts or resumes playback.
pause()Pauses playback.
seekTo(positionMs: Long)Seeks to a specific position in milliseconds.
getCurrentPosition()Returns the current playback position in milliseconds.
getDuration()Returns the total duration of the media in milliseconds.
getPlaybackState()Returns the current state of the player (IDLE, BUFFERING, READY, ENDED).
getPlaybackSpeed()Returns the current playback speed factor (e.g., 1.5f).
setPlaybackSpeed(speed: Float)Sets the playback speed factor (1.0f is normal).
isPlaying()Returns true if the player is currently playing.

Player Events​

You can listen to player events using TPStreamsPlayer.Listener.

player.listener = object : TPStreamsPlayer.Listener {
override fun onAccessTokenExpired(videoId: String, callback: (String) -> Unit) {
// Called when the access token has expired.
// Fetch a new token and pass it back to the player.
val newToken = fetchNewTokenFromServer(videoId)
callback(newToken)
}

override fun onError(error: PlaybackError, message: String) {
// Called when a playback error occurs
println("Error: $message")
}

override fun onSubtitleStateChanged(enabled: Boolean, language: String?) {
// Called when subtitle state changes (enabled/disabled or language changed)
println("Subtitles enabled: $enabled, language: $language")
}
}

Watermark Methods (TPStreamsPlayerView)​

Watermarks are configured on the TPStreamsPlayerView instance. For detailed parameters, configuration properties, and animation options, see Watermarks.

MethodDescription
setWatermarks(configs: List<BaseWatermarkConfig>)Applies a list of text (TextWatermarkConfig) and image (ImageWatermarkConfig) watermark overlays with configurable positioning, opacity, and animations (PING_PONG, RANDOM).
clearWatermarks()Removes all active watermark overlays and stops running animations.