skip to content

Feed Video Preload & Downloads

A video feed preloads the next few items, autoplays muted only when visible, reuses a small pool of players and can download for offline viewing. Interviewers probe the data, memory and licence costs.

on this pageshow

questions

5

In a children's educational-video app's vertical feed, why reuse a pool of video players instead of one per clip, and how would you size it?

level: middleimportance: must knowfreq 42%

answer

  1. a player is not a row view
  2. decoders are few and device-specific
  3. playing, next, previous
  4. memory budget over per-player cost
  5. shrink the pool under memory pressure

basics

~20 s

Each player holds a decoder, buffers and a surface, and a phone runs only a few hardware decoders at once, so one per clip exhausts both. Reuse a small pool, typically playing, next and previous, capped by a measured memory budget.

solid answer

~50 s

A player is heavy: it owns a decoder session, usually a hardware decoder of which a device runs only a handful at once (the count varies by model), plus read-ahead memory, decoded frames and a surface to draw into. One player per feed item makes memory grow with scroll depth and ends with a decoder that will not open or the app being killed. Instead I keep a pool and attach a player to whichever cell is on screen, detaching it when the cell is recycled. The size is the smaller of two limits: the video memory budget divided by a measured per-player cost on the weakest supported phone, and the number of decoders that phone runs at once. For a vertical feed that is usually three, for the playing, next and previous clips, and the pool shrinks to one under memory pressure.

code

pseudocode · 18 lines
pseudocode
pool_size = min(video_memory_budget / measured_cost_per_player,
               decoder_limit_for_this_device)

acquire(clip_id):
  player = pool.find(p -> p.clip_id == clip_id)
  if player != none: return player
  player = pool.idle() or pool.farthest_from(visible_clip)
  player.stop()
  player.clear_surface()
  player.load(clip_id)
  return player

release(clip_id):
  player = pool.find(p -> p.clip_id == clip_id)
  if player != none: player.pause(); player.mark_idle()

on memory pressure:   release_all_except(playing_clip)
on app backgrounded:  release_all()

go deeper

for a junior

Recall that a video player is heavy, holding a decoder, buffers and a surface, so a feed reuses a few players instead of creating one per clip.

for a middle

Explain borrowing and returning players as cells recycle, and size the pool as the smaller of a memory budget over a measured per-player cost and the phone's decoder limit.

for a senior

Show the failure modes you have handled: a stale frame in a recycled cell, a decoder that will not open on a cheap phone, shrinking the pool on memory pressure and releasing it in the background.

for a principal

Make pool size a per-device-class setting driven by telemetry on preparation failures and memory kills, rather than one number chosen on a developer's phone.

## Why a player is not like a row view A feed list already **recycles row views**: only the rows near the viewport exist, and a row that scrolls off is rebound to new data. It is tempting to give each row its own **video player** and let recycling handle the rest. That fails, because a player is a far heavier object than a view, and because some of what it holds is a **device resource** with a hard limit rather than ordinary memory. A **player pool** is a small, fixed set of player objects owned by the feed, not by the rows. A row that needs video **borrows** a player, attaches it to its surface, and gives it back when it scrolls away or is recycled. ## What one player costs - **A decoder session.** Video is usually decoded by dedicated hardware. A device can run only a limited number of hardware decoder sessions at once, and that number varies by model and by the video's size. When the limit is reached, opening one more may fail, or the platform may fall back to a slower decoder; either way the clip shows black or stutters. - **Decoded frames.** A 1080 x 1920 frame at 1.5 bytes a pixel (a common 4:2:0 layout) is about 3 MB, and a decoder keeps several in flight. - **Read-ahead memory** for the bytes waiting to be decoded. - **A surface** the frames are drawn into, plus the player's own state and threads. None of these numbers is a platform constant; the honest move is to **measure** a prepared player on the weakest phone the app supports. ## Sizing the pool Size is the smaller of a memory limit and a decoder limit. 1. **Measure** the memory one *prepared* player adds on the weakest supported phone. Assume, for this scenario, 30 MB. 2. **Set a video memory budget** for the feed that leaves room for images, the rest of the app and the system. Assume 90 MB on that phone, giving 90 / 30 = **3** players. 3. **Find the decoder limit** that phone reliably supports at the feed's video size. Assume testing shows 3 concurrent sessions on the weakest phone and more on newer ones. 4. **Take the smaller**: min(3, 3) = **3**. If the decoder test had shown 2, the pool would be 2 even though memory allowed 3. 5. **Assign roles**: the playing clip, the next clip prepared so a swipe starts instantly, and the previous clip kept so a swipe back is instant. | Pool size | What it buys | What it costs | |---|---|---| | 1 | Lowest memory; works on any phone | Every swipe starts the next clip cold | | 2 | Next clip ready; forward swipes instant | Swiping back restarts the previous clip | | 3 | Next and previous ready | Three decoders and three players' memory | | More | Little for a one-at-a-time feed | Runs into the decoder limit on cheaper phones | ## Binding players to recycled cells Reuse brings one classic bug: a recycled cell briefly shows the **previous clip's last frame**. The player or surface still holds a frame from its last clip. The fix has three parts: - Key every player-to-cell binding by the **clip id**, never by row position, and ignore callbacks that arrive for a clip the player no longer holds. - On rebinding, **clear the surface** and show the new clip's poster until the player reports the **first frame** of the new clip. - When the pool is full, take the player **farthest** from the visible clip, stop it and reset its source before loading the new one. ## Under pressure and in the background - On the OS's **memory-pressure signal**, release every player except the one playing; prepared players can be rebuilt from the network or the disk cache. - When the app leaves the foreground, release all players and their decoders. - If preparing a player **fails**, release the farthest one, retry once, and remember a smaller pool for that device for the rest of the session. ## Where this stops Which clip is allowed to play is the autoplay policy question, and how many clips' opening seconds are fetched ahead is the preload question. How one platform's player is created and configured belongs to that platform's media framework. This question keeps why players are pooled, how many, and how they move between cells.

  • A recycled cell briefly shows the wrong clip's frame before the new clip starts; why, and how do you fix it?
    The reused player or its surface still holds the last decoded frame of the clip it played before. On rebinding, clear the surface and show the new clip's poster until the player reports the first frame of the new clip. Key the binding by clip id so a late callback from the old clip is ignored rather than drawn into the new cell.
  • What happens if the pool asks for more players than the phone can decode at once?
    Opening the extra decoder session can fail, or the platform may fall back to a slower decoder, depending on the device; the user sees a black clip or stutter. Because the limit varies by phone, treat a failed preparation as a signal: release the farthest player, retry once, and keep a smaller pool on that device.
  • Why not use a single player for the whole feed?
    One player works and is the right fallback on a low-memory phone, but every swipe then starts the next clip from cold: open the source, create the decoder, fill its read-ahead and draw a first frame. A second, prepared player hides that delay for forward swipes; a third, kept on the previous clip, makes swiping back instant.

A player pool works like the few high chairs in a restaurant: there are only as many as the room can hold, each is carried to whichever table has a toddler right now, and it is wiped clean before the next child sits down.

  • One player per feed item is fine, because off-screen rows are recycled anyway.
  • A player costs about as much memory as the clip's file size.
  • Every phone can run as many hardware video decoders as the app opens.
  • A pool size measured on a flagship phone will hold on every supported phone.
  • A paused player has already given back its decoder and memory.
open as a page

In a children's educational-video app's clip feed, how many upcoming clips would you preload, how much of each, and what cancels that on a flick?

level: middleimportance: must knowfreq 40%

basics

~20 s

Preload the opening seconds of the next two or three clips ahead and one behind, nearest first. A fast flick pauses new preloads and cancels requests for clips leaving that window, keeping bytes already in a capped disk cache.

open as a page

In a children's educational-video app's vertical feed of short clips, when should a clip start playing by itself, and when should it not?

level: juniorimportance: should knowfreq 34%

basics

~20 s

Autoplay only the one clip that is mostly on screen once scrolling settles, muted, and pause it when it leaves. Skip autoplay when a data-saving, battery-saving or reduce-motion setting, or a parent's choice, says no.

open as a page

In a children's educational-video app where parents download whole episodes before a flight, how should the download queue work so episodes finish even if the app is closed?

level: seniorimportance: should knowfreq 36%

basics

~20 s

Persist a queue entry per episode with its chosen storage quality, progress and state; hand transfers to the OS's background-transfer service; resume from bytes on disk; and reconcile on every launch, since a user force-quit can cancel transfers.

open as a page

In a children's educational-video app, a downloaded episode's licence expires during a flight; how should offline licences, renewal and the download cap be designed?

level: seniorimportance: nice to knowfreq 31%

basics

~20 s

Fetch an offline licence with each download, store its expiry, renew near-expiry licences when online and warn parents before trips. A lapsed episode shows the child a friendly 'needs internet' card; deleting one releases its slot under the owner's cap.

open as a page