---
title: "Recipe: a video that keeps playing from a card into its detail and back"
description: "A video declared again in the detail restarts."
modificationDate: "2026-11-26"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a video that keeps playing from a card into its detail and back

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/keep-a-playing-video: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

A video declared again in the detail restarts. Write the player once, outside the
routes, and name where it shows with `portal`: the same element moves, so the video
plays on and the counter keeps its count.

```prompt Use this recipe in my app
Make the Exact app in this folder do what this recipe describes. Use https://github.com/expo/exact/blob/main/docs/recipes/keep-a-playing-video.md as the source for each step. The Exact checkout has the same page at docs/recipes/keep-a-playing-video.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. Read the recipe. If it leaves a choice that I did not make (which screen, which data, which platforms), propose one and ask me before you write code.
3. Do what the recipe says, in its order, with its tags, properties, functions and grants. Its component, state and URL names are examples. Change nothing else in the app.
4. Add a test in app.test.contract for each thing a person does that you changed. Copy the recipe's `contract-test` block where it has one. A drive operation the recipe shows (`call`, a ticket answer such as `tap @N accepted`) is not a test step: run it with `bun exact.mjs agent`.
5. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 6) and report it; do not keep trying.
6. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
7. Tell me what you changed, what the tests and checks reported, and what I must still do by hand.
```

```contract
routes nav
  tab feed "/"
  detail "/detail"

component App
  derive open = top(nav).name == "detail"
  action show
    nav = push(nav, path("detail"))
  action back
    nav = back(nav)
  view
    main navigationKey=`${top(nav).id}` navigationBack="back" width="100%" height="100%"
      for entry in stack(nav) key=entry.id
        if entry.name == "feed"
          column navigationKey=`${entry.id}` position="absolute" inset=0 gap=12 padding=16
            button press=show testId="open"
              text "Open"
            box id="card-player" width=168 height=148
        else if entry.name == "detail"
          column navigationKey=`${entry.id}` navigationPresentation="fullscreen" navigationSource="card-player" position="absolute" inset=0 gap=12 padding=16
            button id="back" press=back testId="back"
              text "Back"
            box id="detail-player" width="100%" height=320
      box
        column portal=(open ? "detail-player" : "card-player") width="100%" height="100%" gap=6
          video "assets/clip.mp4" autoplay=true muted=true playsinline=true loop=true width="100%" flex=1 min-height=0 testId="player"
          Counter()

component Counter
  state count = 0
  action increment
    count = count + 1
  view
    button press=increment testId="count"
      text `Count ${count}`
```

```contract-test
test "the counter keeps its count through Open and Back"
  tap "count"
  tap "open"
  clock settle
  expect text "count" == "Count 1"
  tap "count"
  tap "back"
  clock settle
  expect text "count" == "Count 2"
```

- **Write it** where it lives as long as both screens (here after the route loop), not
  in the card: a list row's element dies with its row. Its state stays there, and its
  presses and keys bubble there.
- **The destination** is the first element with that `id`, which must be a plain box
  (`contract vocab portal`). With none (another tab), the element waits alive and
  unseen; a muted autoplay video pauses there and plays on when shown (Firefox keeps
  it playing). A box under `display: none` still takes it; on Android that reloads it.
- **The motion** is the destination's: on iOS 18 and later and on Android the detail expands from
  the card (`navigationSource`). Removing the declaration removes the element.
- The clip is `assets/clip.mp4` in the app. The test reads only the count;
  `apps/shared-elements/app.test.mjs` checks one load and advancing `currentTime`.

Each host: [the reference's table](https://exact.expo.dev/reference/developer/a-portal-element-on-each-host.md).
Linux and Windows decode no video.

A custom PiP button can target the same video by its `id`. Gate the button on
`exactPage().pictureInPictureEnabled`. [Video picture in picture](https://exact.expo.dev/reference/developer/run-an-app-from-a-terminal-on-macos.md#video-picture-in-picture)
