---
title: "Loop video in Jetpack Compose: exercise clips with Media3"
description: "Loop video in Jetpack Compose with Media3 ExoPlayer: Gradle setup, REPEAT_MODE_ONE, PlayerView in AndroidView, lifecycle, lists, preloading and alpha."
canonical: "https://setskit.com/guides/exercise-videos-android-compose"
updated: "2026-11-30"
---

# Loop video in Jetpack Compose: exercise clips with Media3

> To loop video in Jetpack Compose, build a Media3 ExoPlayer, set its repeat mode to REPEAT_MODE_ONE and its volume to 0, and show it in a PlayerView with the controller off, inside AndroidView. Play it when the screen starts, pause it when the screen stops and release it when the composable leaves. In lists, show a poster in every row and create a player only for the row that is playing.

Updated 2026-11-30. Source: https://setskit.com/guides/exercise-videos-android-compose

Media3 ExoPlayer, one muted loop, released when the screen goes.

Lifts shown: [Romanian deadlift](https://setskit.com/exercises/romanian-deadlift), [Hack squat](https://setskit.com/exercises/hack-squat), [Incline dumbbell press](https://setskit.com/exercises/incline-dumbbell-press)

## Gradle: Media3 1.11.1

Media3 1.11.1, released on 10 September 2026, is the current stable version, and 1.12.0 is at release candidate. Keep every Media3 module on the same version.

You need media3-exoplayer for playback and media3-ui for PlayerView. lifecycle-runtime-compose 2.11.1 gives you LifecycleStartEffect, and Coil 3.6.3 draws the poster stills from the app’s assets.

```kotlin
// app/build.gradle.kts (a Compose app)
dependencies {
    val media3 = "1.11.1" // every Media3 module on the same version
    implementation("androidx.media3:media3-exoplayer:$media3")
    implementation("androidx.media3:media3-ui:$media3") // PlayerView
    implementation("androidx.lifecycle:lifecycle-runtime-compose:2.11.1")
    implementation("io.coil-kt.coil3:coil-compose:3.6.3") // poster stills
}

// src/main/assets/exercises/goblet-squat.mp4
// src/main/assets/exercises/goblet-squat.png
```

## PlayerView or PlayerSurface?

media3-ui-compose ships at the same 1.11.1 version and has a Compose-native PlayerSurface. In 1.11.1 the source still marks PlayerSurface and ContentFrame @UnstableApi, so you must opt in, and their signatures can change between releases.

This guide uses PlayerView inside AndroidView, because every PlayerView call here is stable API. If you prefer PlayerSurface, it takes the player and a modifier in place of the AndroidView. Note that 1.12.0-rc01 fixes a bug where its SurfaceView turned surrounding Compose backgrounds black on Android 11 and earlier.

## Loop video in Jetpack Compose

REPEAT_MODE_ONE replays the current item for as long as the player runs, and volume 0 keeps it silent. ExoPlayer does not take audio focus unless you ask it to, so the user’s music keeps playing under the clip.

PlayerView covers the video with a black shutter until the first frame renders. Draw the poster on top and hide it in onRenderedFirstFrame, so the square goes from still to motion without a flash of black.

Lifts: [Overhead press](https://setskit.com/exercises/overhead-press), [T-bar row](https://setskit.com/exercises/t-bar-row), [Kettlebell goblet squat](https://setskit.com/exercises/kettlebell-goblet-squat). What ExerciseVideo plays: a muted loop with no controller over it, repeating without a cut until the screen stops.

```kotlin
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.compose.LifecycleStartEffect
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import coil3.compose.AsyncImage

fun clipUri(slug: String) = "asset:///exercises/$slug.mp4"
fun posterUri(slug: String) = "file:///android_asset/exercises/$slug.png"

@Composable
fun rememberLoopingPlayer(): ExoPlayer {
    val context = LocalContext.current
    val player = remember {
        ExoPlayer.Builder(context).build().apply {
            repeatMode = Player.REPEAT_MODE_ONE
            volume = 0f
        }
    }
    DisposableEffect(player) {
        onDispose { player.release() }
    }
    return player
}

@Composable
fun ExerciseVideo(slug: String, modifier: Modifier = Modifier) {
    val exoPlayer = rememberLoopingPlayer()
    var showPoster by remember { mutableStateOf(true) }

    DisposableEffect(exoPlayer) {
        val listener = object : Player.Listener {
            override fun onRenderedFirstFrame() {
                showPoster = false
            }
        }
        exoPlayer.addListener(listener)
        onDispose { exoPlayer.removeListener(listener) }
    }

    LaunchedEffect(slug) {
        showPoster = true
        exoPlayer.setMediaItem(MediaItem.fromUri(clipUri(slug)))
        exoPlayer.prepare()
    }

    LifecycleStartEffect(exoPlayer) {
        exoPlayer.play()
        onStopOrDispose { exoPlayer.pause() }
    }

    Box(modifier.aspectRatio(1f)) { // the clips are square
        AndroidView(
            factory = { context ->
                PlayerView(context).apply {
                    useController = false
                    player = exoPlayer
                }
            },
            modifier = Modifier.fillMaxSize(),
            onRelease = { view -> view.player = null },
        )
        if (showPoster) {
            AsyncImage(
                model = posterUri(slug),
                contentDescription = null,
                modifier = Modifier.fillMaxSize(),
            )
        }
    }
}
```

## Lifecycle and release

LifecycleStartEffect plays the clip when the screen starts and pauses it when the screen stops or the composable leaves. That covers the home button and the app switcher.

The DisposableEffect in rememberLoopingPlayer releases the player when the composable leaves composition, and onRelease detaches the PlayerView. Android’s Media3 guide puts it plainly: "It's important to release the player when it's no longer needed, so as to free up limited resources such as video decoders for use by other applications."

A rotation rebuilds the composition, so the clip starts again from a new player. For a three second loop that is fine, and a ViewModel can hold the player if it is not.

## LazyColumn: posters, one player

Each ExoPlayer that renders video holds a hardware decoder, and devices limit how many run at once. Show a poster in every row and create a player only for the row the user opens.

When the open row scrolls out of the LazyColumn, its composition goes and the DisposableEffect releases its player. Tapping another row closes the first, so there is never more than one.

Lifts: [Bulgarian split squat](https://setskit.com/exercises/bulgarian-split-squat), [Leg extension](https://setskit.com/exercises/leg-extension), [Leg curl](https://setskit.com/exercises/leg-curl), [Dumbbell lunge](https://setskit.com/exercises/dumbbell-lunge). Four lifts from a leg day, as rows of a LazyColumn. In the app each row is a poster until it is tapped, so there is never more than one player.

```kotlin
// imports as above, plus androidx.compose.foundation.clickable,
// androidx.compose.foundation.lazy.*, androidx.compose.foundation.layout.*,
// androidx.compose.material3.*, androidx.compose.runtime.saveable.rememberSaveable,
// androidx.compose.ui.Alignment and androidx.compose.ui.unit.dp

data class Exercise(val slug: String, val name: String, val equipment: String)

@Composable
fun ExerciseList(exercises: List<Exercise>) {
    var playing by rememberSaveable { mutableStateOf<String?>(null) }

    LazyColumn {
        items(exercises, key = { it.slug }) { exercise ->
            Column(
                Modifier
                    .fillMaxWidth()
                    .clickable { playing = if (playing == exercise.slug) null else exercise.slug }
                    .padding(horizontal = 16.dp, vertical = 8.dp),
            ) {
                Row(verticalAlignment = Alignment.CenterVertically) {
                    AsyncImage(
                        model = posterUri(exercise.slug),
                        contentDescription = null,
                        modifier = Modifier.size(56.dp),
                    )
                    Spacer(Modifier.width(12.dp))
                    Column {
                        Text(exercise.name)
                        Text(exercise.equipment, style = MaterialTheme.typography.bodySmall)
                    }
                }
                if (playing == exercise.slug) {
                    ExerciseVideo(
                        slug = exercise.slug,
                        modifier = Modifier.fillMaxWidth().padding(top = 8.dp),
                    )
                }
            }
        }
    }
}
```

## Preload the next exercise

In a workout, prepare the next clip while the current one plays. prepare() without play() reads and buffers it, so the next exercise starts as soon as the user moves on.

Keep two players at most: the one on screen and the next. Release the old one only after the PlayerView shows the new one, which is what releaseRetired does. Media3 also has DefaultPreloadManager for long feeds, but it is marked @UnstableApi.

- **222 KB** the average clip that prepare() buffers, as MP4
- **3 s** the median loop

```kotlin
// imports as above, plus android.content.Context and
// androidx.compose.runtime.mutableIntStateOf

class WorkoutClips(context: Context, private val slugs: List<String>) {
    private val appContext = context.applicationContext
    private val retired = mutableListOf<ExoPlayer>()
    private var next: ExoPlayer? = null

    var index by mutableIntStateOf(0)
        private set
    var current: ExoPlayer by mutableStateOf(load(slugs.first()))
        private set

    init {
        next = slugs.getOrNull(1)?.let(::load)
    }

    private fun load(slug: String): ExoPlayer =
        ExoPlayer.Builder(appContext).build().apply {
            setMediaItem(MediaItem.fromUri(clipUri(slug)))
            repeatMode = Player.REPEAT_MODE_ONE
            volume = 0f
            prepare() // reads and buffers now, plays when told
        }

    fun advance() {
        val upcoming = next ?: return
        retired += current
        current = upcoming
        index += 1
        upcoming.play()
        next = slugs.getOrNull(index + 1)?.let(::load)
    }

    /** Call once the view shows [current]. */
    fun releaseRetired() {
        retired.forEach { it.release() }
        retired.clear()
    }

    fun release() {
        releaseRetired()
        current.release()
        next?.release()
    }
}

@Composable
fun WorkoutVideo(clips: WorkoutClips, modifier: Modifier = Modifier) {
    LifecycleStartEffect(clips) {
        clips.current.play()
        onStopOrDispose { clips.current.pause() }
    }
    AndroidView(
        factory = { context -> PlayerView(context).apply { useController = false } },
        modifier = modifier.aspectRatio(1f),
        update = { view ->
            view.player = clips.current // runs again when current changes
            clips.releaseRetired()
        },
        onRelease = { view -> view.player = null },
    )
}

// in the workout screen:
val context = LocalContext.current
val clips = remember { WorkoutClips(context, slugs) }
DisposableEffect(clips) { onDispose { clips.release() } }
WorkoutVideo(clips)
```

## Transparency on Android, honestly

Media3 ExoPlayer has no transparent video. The platform decoders do not pass the alpha channel on, so HEVC or VP9 with alpha plays opaque, and androidx/media issue 1388, which asks for transparent video, was still open on 30 November 2026. That holds for Flutter and React Native apps too, since their usual Android players use ExoPlayer.

The real options, from simplest to most work:

- Match the background: play the opaque MP4 on a colour the same as the clip’s own field. It is the smallest file and plays on every device.
- A WebView: Chromium plays VP9 WebM with alpha, so a WebView can show a transparent clip. You make and test the WebM yourself, and a WebView per clip is heavy.
- Stacked alpha: encode the picture and its alpha mask into one opaque video and join them again in an OpenGL shader. Any decoder plays it, at the cost of writing and testing the renderer.
- Animated WebP: from Android 9, ImageDecoder returns an AnimatedImageDrawable for an animated WebP, alpha included. It is an image format, so expect bigger files than video and no hardware video decoding.

## Clips that suit this code

The code assumes square MP4 clips whose last frame meets the first, with a poster still beside each, which is how the Setskit library ships: 720 by 720 pixels at 30 frames a second. Every clip sits on the same white field, #F5F7F7, so a Compose background of Color(0xFFF5F7F7) hides the clip’s edge without any alpha. The free sample at setskit.com/free-sample has five lifts to try, and the integration guide at setskit.com/integration has the same player for iOS, React Native, Flutter and the web.

## Questions

**How do I loop a video with ExoPlayer in Compose?**

Set repeatMode = Player.REPEAT_MODE_ONE on the ExoPlayer, then show it in a PlayerView inside AndroidView. The join is clean when the clip’s last frame meets its first.

**Is PlayerSurface stable?**

The media3-ui-compose artifact ships with each stable Media3 release, but PlayerSurface is still annotated @UnstableApi in 1.11.1. You can use it with @OptIn(UnstableApi::class), accepting that its signature may change.

**Will a muted ExoPlayer stop the user’s music?**

No. ExoPlayer requests audio focus only when you pass handleAudioFocus = true to setAudioAttributes, and the default is false.

**Can ExoPlayer play transparent video?**

Not in Media3 1.11.1. Use an opaque clip on a matching background, a WebView with VP9 alpha, or a stacked-alpha video and a shader.

## Sources

- [Media3 release notes](https://developer.android.com/jetpack/androidx/releases/media3)
- [Media3 RELEASENOTES.md (GitHub)](https://github.com/androidx/media/blob/main/RELEASENOTES.md)
- [Media3, ExoPlayer hello world](https://developer.android.com/media/media3/exoplayer/hello-world)
- [Media3, Compose UI](https://developer.android.com/media/media3/ui/compose)
- [PlayerSurface API reference](https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/PlayerSurface.composable)
- [PlayerSurface.kt at Media3 1.11.1](https://github.com/androidx/media/blob/1.11.1/libraries/ui_compose/src/main/java/androidx/media3/ui/compose/PlayerSurface.kt)
- [PlayerView API reference](https://developer.android.com/reference/androidx/media3/ui/PlayerView)
- [Player API reference (REPEAT_MODE_ONE, onRenderedFirstFrame)](https://developer.android.com/reference/androidx/media3/common/Player)
- [ExoPlayer.Builder API reference](https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlayer.Builder)
- [DefaultPreloadManager API reference](https://developer.android.com/reference/androidx/media3/exoplayer/source/preload/DefaultPreloadManager)
- [Lifecycle release notes](https://developer.android.com/jetpack/androidx/releases/lifecycle)
- [Compose, Views in Compose (AndroidView)](https://developer.android.com/develop/ui/compose/migrate/interoperability-apis/views-in-compose)
- [Coil, getting started](https://coil-kt.github.io/coil/getting_started/)
- [androidx/media issue 1388, Support transparent video with ExoPlayer](https://github.com/androidx/media/issues/1388)
- [Android ImageDecoder](https://developer.android.com/reference/android/graphics/ImageDecoder)
- [Chrome, Alpha transparency in Chrome video](https://developer.chrome.com/blog/alpha-transparency-in-chrome-video)
