VideoPlayer

fun VideoPlayer(modifier: Modifier = Modifier, mediaItems: List<VideoPlayerMediaItem>, handleLifecycle: Boolean = true, autoPlay: Boolean = true, usePlayerController: Boolean = true, controllerConfig: VideoPlayerControllerConfig = VideoPlayerControllerConfig.Default, seekBeforeMilliSeconds: Long = 10000, seekAfterMilliSeconds: Long = 10000, repeatMode: RepeatMode = RepeatMode.NONE, @FloatRange(from = 0.0, to = 1.0) volume: Float = 1.0f, onCurrentTimeChanged: (Long) -> Unit = {}, fullScreenSecurePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit, onFullScreenEnter: () -> Unit = {}, onFullScreenExit: () -> Unit = {}, enablePip: Boolean = false, enablePipWhenBackPressed: Boolean = false, handleAudioFocus: Boolean = true, playerInstance: ExoPlayer.() -> Unit = {})

VideoPlayer is UI component that can play video in Jetpack Compose. It works based on ExoPlayer. You can play local (e.g. asset files, resource files) files and all video files in the network environment. For all video formats supported by the VideoPlayer component, see the ExoPlayer link below.

If you rotate the screen, the default action is to reset the player state. To prevent this happening, put the following options in the android:configChanges option of your app's AndroidManifest.xml to keep the settings.

keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode

This component is linked with Compose androidx.compose.runtime.DisposableEffect. This means that it move out of the Composable Scope, the ExoPlayer instance will automatically be destroyed as well.

See also

Parameters

modifier

Modifier to apply to this layout node.

mediaItems

VideoPlayerMediaItem to be played by the video player. The reason for receiving media items as an array is to configure multi-track. If it's a single track, provide a single list (e.g. listOf(mediaItem)).

handleLifecycle

Sets whether to automatically play/stop the player according to the activity lifecycle. Default is true.

autoPlay

Autoplay when media item prepared. Default is true.

usePlayerController

Using player controller. Default is true.

controllerConfig

Player controller config. You can customize the Video Player Controller UI.

seekBeforeMilliSeconds

The seek back increment, in milliseconds. Default is 10sec (10000ms). Read-only props (Changes in values do not take effect.)

seekAfterMilliSeconds

The seek forward increment, in milliseconds. Default is 10sec (10000ms). Read-only props (Changes in values do not take effect.)

repeatMode

Sets the content repeat mode.

volume

Sets thie player volume. It's possible from 0.0 to 1.0.

onCurrentTimeChanged

A callback that returned once every second for player current time when the player is playing.

fullScreenSecurePolicy

Windows security settings to apply when full screen. Default is off. (For example, avoid screenshots that are not DRM-applied.)

onFullScreenEnter

A callback that occurs when the player is full screen. (The VideoPlayerControllerConfig.showFullScreenButton must be true to trigger a callback.)

onFullScreenExit

A callback that occurs when the full screen is turned off. (The VideoPlayerControllerConfig.showFullScreenButton must be true to trigger a callback.)

enablePip

Enable PIP (Picture-in-Picture).

enablePipWhenBackPressed

With enablePip is true, set whether to enable PIP mode even when you press Back. Default is false.

handleAudioFocus

Set whether to handle the video playback control automatically when it is playing in PIP mode and media is played in another app. Default is true.

playerInstance

Return exoplayer instance. This instance allows you to add androidx.media3.exoplayer.analytics.AnalyticsListener to receive various events from the player.