VideoFeedPlayerController

Controls a pool of players for video feed playback.

Typical UI integration:

  1. Create one controller for the feed, usually in a ViewModel, on the main thread.

  2. Observe items. When a VideoFeedItemState.player is non-null, attach it to your player view.

  3. Call prepare for the initial item, or call select for the first visible item and let it prepare.

  4. Call select whenever the visible/current item changes. Do not create or destroy players per row.

  5. Forward host lifecycle events to onStart, onResume, onPause, and onStop.

  6. Call release when the feed owner is disposed.

For Compose, keep scroll state in the UI, map the visible index to the matching VideoFeedItem, and pass that item to select.

This controller must be created and accessed on the application's main thread.

Constructors

Link copied to clipboard
constructor(context: Context, items: List<VideoFeedItem>, config: VideoFeedPlayerConfig)

Properties

Link copied to clipboard
val items: StateFlow<List<VideoFeedItemState>>

Functions

Link copied to clipboard

Appends items to the feed. Item IDs must be unique across existing and appended items.

Link copied to clipboard
fun itemAt(index: Int): VideoFeedItem

Returns the feed item at index.

Link copied to clipboard
fun onPause()

Forwards the host Activity or Fragment onPause event to all pooled players.

Link copied to clipboard
fun onResume()

Forwards the host Activity or Fragment onResume event to all pooled players.

Link copied to clipboard
fun onStart()

Forwards the host Activity or Fragment onStart event to all pooled players.

Link copied to clipboard
fun onStop()

Forwards the host Activity or Fragment onStop event to all pooled players.

Link copied to clipboard
fun pause()

Pauses playback of the current item.

Link copied to clipboard
fun play()

Starts playback of the current item.

Link copied to clipboard

Optionally loads item before the feed is shown.

fun preload(index: Int)

Optionally loads the item at index before the feed is shown.

Link copied to clipboard

Selects the initial current item, starts its player, and preloads neighboring items.

fun prepare(index: Int)

Selects the initial current item at index, starts its player, and preloads neighboring items.

Link copied to clipboard
fun release()

Releases all pooled players. This function is idempotent; other functions must not be called afterward.

Link copied to clipboard
fun retry()

Reloads the failed current item and starts playback.

Link copied to clipboard

Makes item current.

fun select(index: Int)

Makes the item at index current.