NewPlayerViewModel

The NewPlayerViewModel must live and be owned by an Activity context.

Properties

Link copied to clipboard

Depicts weather the picture of the video should be stretched, fit inside or be cropped. You can set it yourself, but NewPlayerUI can also change it.

Link copied to clipboard
abstract val embeddedPlayerDraggedDownBy: SharedFlow<Float>

If the user dragged down the embedded video or audio player. This callback will tell you how far the user dragged down. Keep in mind that the user can also decide to drag the NewPlayerUI up again. If the NewPlayerUI is not dragged up to its original position you should take over control and maybe make the NewPlayerUI snap to the bottom of the screen to make space for your UI.

Link copied to clipboard
abstract var newPlayer: NewPlayer?

The current instance of NewPlayer. If set to null the NewPlayerUI instance which the viewModel talks too will display the same as if NewPlayer was in IDLE mode.

Link copied to clipboard
abstract val onBackPressed: SharedFlow<Unit>

NewPlayerUI will use some back press events for its own navigation purposes. If the viewModel decides that a back press event should not be handled by itself. It will forward the event to you through this callback.

Link copied to clipboard
abstract val uiState: StateFlow<NewPlayerUIState>

This represents the state the UI is in. NewPlayerUI will basically render out that state. You can make your UI also listen to changes to this state. This is especially helpful for switching to or from fullscreen or to or from PiP mode.

Functions

Link copied to clipboard
abstract fun onPictureInPictureModeChanged(isPictureInPictureMode: Boolean)

This is something you have to call in the Activity that should host the NewPlayerUI. See the example app's main activity to find out how to use this.