Web video players: sound, mute, fullscreen and autoplay-next
videoautoplayuser-activationfullscreeniosandroidlocalstorage
Browsers allow unmuted playback and fullscreen only while a user gesture is live. Most "the video has no sound on my phone" and "fullscreen does not work" bugs are about losing that gesture or about stored mute state. These are the rules learned building the player for videos.jhampton.io (one thin wrapper, player.js, around a single <video>), and they are Justin's standing rules for any player.
Sound only survives inside the gesture
- A browser grants unmuted
play()only while the click that asked for it is still live (transient activation). A gesture does not survive a navigation, so a video opened by following a link to a watch page always lands muted. That is why the index and the admin play videos in place in an overlay. - Call
mount()synchronously inside the click handler and setvideo.srcbeforeplay()(not<source>children). - Never
await fetch(...)inside the click handler to get the URL: the await spends the gesture. Ship the signed URLs with the list response instead (cost ~6 KB gzipped, worth it). - Chrome and Firefox also have sticky activation, so later plays on the page keep sound; Safari is stricter.
A mute must always be reachable
There are two ways to be silent: video.muted and video.volume === 0. Both must be shown and both must be fixable.
- Never hide the mute toggle at any viewport. "Phones have hardware volume" is half true: hardware keys change the level, they cannot clear a muted flag. Hide the volume slider on small screens if needed; keep the toggle.
- Make the toggle mean sound on/off, not "flip muted": clear the mute and restore volume if it is zero.
- If playback starts silent for any reason, show a persistent toast with the fix attached ("Sound is off, turn sound on"). No timeout on it.
- Real case (2026-08-15): no sound on Justin's Android, but it worked in a private tab, which pointed straight at stored state. A remembered mute plus a hidden mute control at max-width: 560px plus a toggle that never touched volume compounded into permanent silence. Asking "does it behave differently in a private window?" is a great first question.
- Storage keys used: jah-vp-muted, jah-vp-volume (0..1), jah-vp-pos-<slug> for resume position.
iOS audio session
iOS routes inline <video> through the ambient audio session, which the hardware silent switch mutes: picture and no sound, with nothing on screen to explain it. Before play():
if (navigator.audioSession) navigator.audioSession.type = 'playback';
Safari 16.4+, feature-detected, absent elsewhere. It looks like dead code on other browsers; do not remove it.
Fullscreen: touch only
Justin's rule: "The user explicitly took action to watch the video, therefore immersion should be prioritized over control." On touch devices (matchMedia('(hover: none)')), request fullscreen inside the tap. On desktop, do not: fullscreen there is a much bigger mode change than the click that asked for it, and double-click is enough. He accepted that split.
- iPhone has no element fullscreen, only video.webkitEnterFullscreen(), which hands over to Apple's player. Skip it for videos whose rotation is done in CSS (Apple's player would show them sideways); see Rotating video in CSS instead of re-encoding.
- Closing the overlay must exit fullscreen first.
- The same rule applied to a canvas game (Joyride): on coarse pointers the "get in" tap also calls requestFullscreen (hide the button where unsupported, e.g. iPhone Safari).
Autoplay next in a series
- A toggle (
jah-vp-autonext, on by default). Onended, if a next item exists, show "Up next in 5s: Title, cancel"; anyplayorseekingduring the countdown cancels. - Swap the next video into the same
<video>element (load(nextData)re-applies rotation, codec fallback and resume position) rather than mounting a new player. A fresh mount has no gesture behind it, so it could neither re-enter fullscreen on a phone nor be sure of sound on Safari. The element that already played keeps both. - Read per-video state through the current
data, never captured once at mount time. - A server-rendered watch page navigates to the next episode instead (and so loses the gesture); it shows only items listed and playable for this viewer.
- Do not color the "on" state with the theme accent if the accent can match the footage: CRT green vanished against green video and read as disabled.
Testing notes
- Test locally against a copy of the live catalog (
php -Swith a scratch data dir), seek toduration - 0.4and wait forended. - Headless tests need real input events for any gesture-gated behavior (see Headless Chrome testing gotchas), and emulated mobile still uses the desktop autoplay policy.
- See Touch compatibility mouse events (mousemove before click) for why tapping the picture used to do nothing.
See also
- Rotating video in CSS instead of re-encoding
- Encoding phone clips for the web (HEVC remux, H.264 fallback)
- videos.jhampton.io (private video site architecture)
Linked from
- Encoding phone clips for the web (HEVC remux, H.264 fallback)
- Justin's standing rules for anything built for him
- Rotating video in CSS instead of re-encoding
- Serving a phone-friendly Flutter web app from the same URL
- Touch compatibility mouse events (mousemove before click)
- videos.jhampton.io (private video site architecture)