BunnyPlayer

interface BunnyPlayer(source)

The playback engine behind net.bunny.bunnystreamplayer.ui.BunnyStreamPlayer. One engine instance is shared by every player view in the process; the views are meant to be used one at a time.

Most apps never touch this interface directly: the net.bunny.bunnystreamplayer.ui.BunnyStreamPlayer view drives it and re-exposes the pieces an app usually needs (play, progress, resume positions). Reach for the engine when you build your own player chrome and need direct control over tracks, quality, volume or speed.

Call engine methods from the main thread.

Inheritors

Properties

Link copied to clipboard
abstract var autoPaused: Boolean

True while playback is paused by the SDK itself (for example when the host activity went to the background) rather than by the user. Such playback resumes automatically.

Link copied to clipboard
abstract val context: Context

Context the engine was created with; used for device-type checks below.

Link copied to clipboard
abstract var currentPlayer: Player?

The underlying media3 Player - the local ExoPlayer or, while casting, the cast player.

Link copied to clipboard

Player settings of the current video, fetched from the Bunny API when playback starts.

Link copied to clipboard

Receives playback state callbacks. See PlayerStateListener.

Link copied to clipboard

Storage for resume positions. Set automatically when resume positions are enabled.

Link copied to clipboard

Seek-bar preview thumbnails of the current video, when the video has them.

Functions

Link copied to clipboard

Returns true while captions are turned on.

Link copied to clipboard

Removes saved positions older than the retention configured in ResumeConfig.

Link copied to clipboard
abstract fun clearAllSavedPositions()

Deletes every saved position.

Link copied to clipboard
abstract fun clearSavedPosition(videoId: String)

Deletes the saved position of one video.

Link copied to clipboard
abstract fun disableResumePosition()

Turns resume positions off. Already saved positions are kept.

Link copied to clipboard
abstract fun enableResumePosition(config: ResumeConfig = ResumeConfig())

Turns on local resume positions: playback positions are saved on the device automatically. Saving alone does not seek - to resume, set a ResumePositionListener (or pass the resume callback to the player view's enableResumePosition) and confirm the jump from there. See ResumeConfig for thresholds and retention.

Link copied to clipboard
abstract fun exportPositions(callback: (String) -> Unit)

Serializes all saved positions to JSON, for backup or transfer between devices.

Link copied to clipboard
abstract fun getAllSavedPositions(callback: (List<PlaybackPosition>) -> Unit)

Returns every saved position. The callback runs on the main thread.

Link copied to clipboard

Returns the selectable audio tracks of the current video, or null before playback starts.

Link copied to clipboard
abstract fun getCurrentPosition(): Long

Returns the current playback position in milliseconds.

Link copied to clipboard

Classifies the device this code is running on. See DeviceType.

Link copied to clipboard
abstract fun getDuration(): Long

Returns the duration of the current video in milliseconds.

Link copied to clipboard
abstract fun getPlaybackSpeeds(): List<Float>

Returns the speeds offered in the settings menu.

Link copied to clipboard
abstract fun getSpeed(): Float

Returns the current playback speed.

Link copied to clipboard
abstract fun getSubtitles(): Subtitles

Returns the caption tracks of the current video and which one is showing.

Link copied to clipboard

Returns the selectable renditions of the current video, or null before playback starts.

Link copied to clipboard
@FloatRange(from = 0.0, to = 1.0)
abstract fun getVolume(): Float

Returns the player volume, from 0 (silent) to 1 (full volume).

Link copied to clipboard
abstract fun importPositions(jsonData: String, callback: (Boolean) -> Unit)

Restores positions exported with exportPositions. The callback reports success.

Link copied to clipboard
abstract fun isMuted(): Boolean

Returns true while the player is muted.

Link copied to clipboard
abstract fun isPlaying(): Boolean

Returns true while playback is running.

Link copied to clipboard

Returns true on Android TV devices.

Link copied to clipboard

Returns true when the device requires a touch screen.

Link copied to clipboard
abstract fun loadSavedSpeed()

Reapplies the speed remembered from the previous playback, when that option is enabled.

Link copied to clipboard
abstract fun mute()

Mutes the player by setting the volume to 0.

Link copied to clipboard
abstract fun pause(autoPaused: Boolean = false)

Pauses playback. autoPaused is used by the SDK's own lifecycle handling; leave it false when pausing on behalf of the user.

Link copied to clipboard
abstract fun play()

Starts or resumes playback.

Link copied to clipboard
abstract fun playVideo(playerView: PlayerView, video: Video, retentionData: Map<Int, Int>, playerSettings: PlayerSettings, licenseBaseApi: String = net.bunny.api.BuildConfig.BASE_API, token: String? = null, expires: Long? = null)

Starts playback of video inside playerView. Used internally by the net.bunny.bunnystreamplayer.ui.BunnyStreamPlayer view, which fetches the video and its playerSettings first; prefer that view's playVideo(videoId) unless you are building a fully custom player.

Link copied to clipboard
abstract fun release()

Releases codecs and every other resource held by the engine. Playback cannot be resumed.

Link copied to clipboard
abstract fun replay()

Skips 10 seconds back.

Link copied to clipboard
abstract fun seekTo(positionMs: Long)

Seeks to positionMs, in milliseconds from the start of the video.

Link copied to clipboard
abstract fun selectAudioTrack(audioTrackInfo: AudioTrackInfo)

Switches to the given audio track. Pick one from getAudioTrackOptions.

Link copied to clipboard
abstract fun selectQuality(quality: VideoQuality)

Locks playback to the given rendition. Pick one from getVideoQualityOptions.

Link copied to clipboard
abstract fun selectSubtitle(subtitleInfo: SubtitleInfo)

Shows the given caption track. Pick one from getSubtitles.

Link copied to clipboard

Applies a PlaybackSpeedConfig. See that class for the available options.

Link copied to clipboard
abstract fun setResumePosition(position: Long)

Seeks to a resume position. Used by the SDK after the resume prompt.

Link copied to clipboard

The resume mechanism: notified when a saved position exists for the starting video. The listener decides whether to seek (ask the user, then call seekTo); without a listener playback starts from the beginning.

Link copied to clipboard
abstract fun setSpeed(speed: Float)

Sets the playback speed, for example 1.5f.

Link copied to clipboard
abstract fun setSubtitlesEnabled(enabled: Boolean)

Turns captions on or off without changing the selected track.

Link copied to clipboard
abstract fun setVolume(@FloatRange(from = 0.0, to = 1.0) volume: Float)

Sets the player volume, from 0 (silent) to 1 (full volume).

Link copied to clipboard
abstract fun skipForward()

Skips 10 seconds forward.

Link copied to clipboard
abstract fun stop()

Stops playback and resets the engine to its initial state.

Link copied to clipboard
abstract fun unmute()

Unmutes the player by setting the volume back to full (1.0).