Examples
Shorts-style feed
A YouTube Shorts-style vertical feed built from playInView and the headless controls.
Everything a Shorts-style feed needs is already in the box: playInView arbitrates which video plays, controls={false} strips the built-in HUD, and the headless controls supply the rest. This is running live - swipe, scroll, or use the arrows. The shorts themselves are fetched a page at a time from JSON, and the feed mixes HLS streams, a live stream and a YouTube upload behind the same controls.
Loading the feed…
How it's built
Feed.vue
<script setup lang="ts">
import { ref, shallowRef, onMounted, type Component } from 'vue'
import Slide from './components/Slide.vue'
import Nav from './components/Nav.vue'
import { registerShortsIcons } from './icons'
import { provideShortsParts } from './parts'
import { useRecycler } from './composables/useRecycler'
import { useShortsFeed } from './composables/useShortsFeed'
const parts = shallowRef<Record<string, Component> | null>(null)
const failed = ref(false)
const scroller = ref<HTMLElement | null>(null)
const stage = ref<HTMLElement | null>(null)
const uiHidden = ref(false)
provideShortsParts(parts)
const { shorts, failed: feedFailed, loadMore, refresh } = useShortsFeed()
const { slots, index, onScroll, go, reset } = useRecycler(scroller, shorts, loadMore)
function refreshFeed(): void {
reset()
refresh()
}
onMounted(async () => {
try {
const [m, vueSigil] = await Promise.all([
import('@munsonlabs/video-player'),
import('@munsonlabs/sigil/vue'),
import('@munsonlabs/video-player/style'),
registerShortsIcons(),
])
parts.value = {
VideoCard: m.VideoCard,
PlayButton: m.PlayButton,
MuteButton: m.MuteButton,
CaptionsButton: m.CaptionsButton,
QualityButton: m.QualityButton,
Scrubber: m.Scrubber,
Buffering: m.Buffering,
Sigil: vueSigil.Sigil,
}
} catch {
failed.value = true
}
})
</script>
<template>
<ClientOnly>
<div class="shorts">
<p v-if="failed" class="shorts__status">Could not load <code>@munsonlabs/video-player</code>.</p>
<p v-else-if="feedFailed" class="shorts__status">Could not load the feed.</p>
<div v-else-if="parts" ref="stage" class="shorts__stage">
<div ref="scroller" class="shorts__scroller" @scroll.passive="onScroll">
<div v-for="(short, slot) in slots" :key="short?.id ?? `empty-${slot}`" class="shorts__slide">
<Slide v-if="short" :short="short" v-model:ui-hidden="uiHidden" />
</div>
</div>
<Nav :stage="stage" :index="index" :count="shorts.length" @go="go" @refresh="refreshFeed" />
</div>
<p v-else class="shorts__status">Loading the feed…</p>
</div>
<template #fallback>
<p class="shorts__status">Loading the feed…</p>
</template>
</ClientOnly>
</template>
<style scoped>
@import './styles/feed.css';
</style>
The feed is a scroll-snap column (scroll-snap-type: y mandatory, with scroll-snap-stop: always so one fling moves one short); everything else falls out of the player's own behaviour:
| Shorts behaviour | What provides it |
|---|---|
| The visible short plays, the rest pause | playInView - and its shared debounce means only one ever wins |
| The first one autoplays on load | playInView fires for whatever is already in view at mount |
| Starts muted, and unmuting sticks | Browser policy for gesture-less playback, then the shared audio preference carries your choice to every later short |
| Tap to pause | The tap event, which fires even with controls={false} |
| Progress bar | Scrubber, restyled to a 3px bar |
| Next and previous shorts are ready before you reach them | lazy={false} plus preload="auto" - all three recycled slides mount a real player that fetches ahead, so the neighbours are buffered before you swipe. playInView still decides which plays |
| Each short loops | The loop prop - no need to wait for the player to mount and call toggleLoop() |
| A long feed stays cheap | Three slides recycle - prev/current/next. The current one is held in the middle and scrollTop is reset to it after each swipe, so the DOM never grows |
| The feed grows as you swipe | useRecycler calls loadMore() two slides before the end; each page is plain JSON under public/shorts/ naming the next, and next: null ends the feed |
| Refresh starts over at the top | The nav's refresh button resets the recycler to slot 0 and empties the list, which makes the recycler ask for page 1 again - a page still in flight from before is ignored. Static JSON brings the same shorts back; a real API would bring new ones |
| A YouTube upload sits in the same feed | VideoCard resolves the URL to its embed adapter; the same headless controls drive the iframe |
| Hold the right edge for 2x | A hold timer bound to the playbackRate prop - works on the YouTube embed too, and is skipped when isLive |
| Captions toggle, clear of the UI | CaptionsButton, which only renders when the source has tracks - the Apple stream declares its subtitles in the manifest. captionLine keeps the cues above the meta row, and a watch on activeCaptionIndex names each track in a toast as you cycle |
| Quality in the rail | QualityButton, which only renders for adaptive sources - so it's there on the HLS shorts and gone on the YouTube embed and the live rendition. Its slot's currentLabel is the caption under the icon. A pick sticks across shorts and reloads on its own, YouTube-style: the player stores the chosen height and each new slide lands on the nearest level that source offers. The slide only watches currentQualityHeight to name the new level in a toast, and stays quiet for Auto's own switches |
| Live badge, no scrubber | isLive on the player handle - the same surface CaptionsButton and MuteButton read from |
| The eye clears the UI | v-show on everything but the eye itself; the top buttons are a flex column so hidden ones leave no gap |
The frame sets
--ml-video-max-width: none, since the player caps itself at 800px by default and a Short is height-led rather than width-led.