DefaultBunnyPlayer

The ExoPlayer-based implementation of BunnyPlayer, obtained through getInstance.

The engine is a process-wide singleton: every net.bunny.bunnystreamplayer.ui.BunnyStreamPlayer view in the app shares this one instance; use one player view at a time. Apps that embed the player view never create this class themselves; use the engine directly only when building custom player chrome on top of the BunnyPlayer interface.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override 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
open override val context: Context

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

Link copied to clipboard
open override var currentPlayer: Player?

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

Link copied to clipboard
open override var playerSettings: PlayerSettings?

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
open override var seekThumbnail: SeekThumbnail?

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

Functions

Link copied to clipboard
open override fun areSubtitlesEnabled(): Boolean

Returns true while captions are turned on.

Link copied to clipboard
open override fun cleanupExpiredPositions()

Removes saved positions older than the retention configured in ResumeConfig.

Link copied to clipboard
open override fun clearAllSavedPositions()

Deletes every saved position.

Link copied to clipboard
open override fun clearSavedPosition(videoId: String)

Deletes the saved position of one video.

Link copied to clipboard
open override fun disableResumePosition()

Turns resume positions off. Already saved positions are kept.

Link copied to clipboard
open override 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
open override fun exportPositions(callback: (String) -> Unit)

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

Link copied to clipboard
open override 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
open override 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
open override fun getDuration(): Long

Returns the duration of the current video in milliseconds.

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

Returns the speeds offered in the settings menu.

Link copied to clipboard
open override fun getSpeed(): Float

Returns the current playback speed.

Link copied to clipboard
open override 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
open override fun getVolume(): Float

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

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

Restores positions exported with exportPositions. The callback reports success.

Link copied to clipboard
open override fun isMuted(): Boolean

Returns true while the player is muted.

Link copied to clipboard
open override 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
open override fun loadSavedSpeed()

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

Link copied to clipboard
open override fun mute()

Mutes the player by setting the volume to 0.

Link copied to clipboard
open override 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
open override fun play()

Starts or resumes playback.

Link copied to clipboard
open override 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
open override fun release()

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

Link copied to clipboard
open override fun replay()

Skips 10 seconds back.

Link copied to clipboard
open override fun seekTo(positionMs: Long)

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

Link copied to clipboard
open override fun selectAudioTrack(audioTrackInfo: AudioTrackInfo)

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

Link copied to clipboard
open override fun selectQuality(quality: VideoQuality)

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

Link copied to clipboard
open override fun selectSubtitle(subtitleInfo: SubtitleInfo)

Shows the given caption track. Pick one from getSubtitles.

Link copied to clipboard
open override fun setPlaybackSpeedConfig(config: PlaybackSpeedConfig)

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

Link copied to clipboard
open override 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
open override fun setSpeed(speed: Float)

Sets the playback speed, for example 1.5f.

Link copied to clipboard
open override fun setSubtitlesEnabled(enabled: Boolean)

Turns captions on or off without changing the selected track.

Link copied to clipboard
open override fun setVolume(volume: Float)

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

Link copied to clipboard
open override fun skipForward()

Skips 10 seconds forward.

Link copied to clipboard
open override fun stop()

Stops playback and resets the engine to its initial state.

Link copied to clipboard
open override fun unmute()

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