# Media embed

Purpose: Turn a recognized YouTube, Spotify, SoundCloud, Bandcamp or TikTok link in a post into one calm, playable object, without loading the provider until someone asks to play.
Scenario: A post holds a YouTube link. With `FORUM_MEDIA_EMBEDS_ENABLED` and `FORUM_MEDIA_EMBEDS_INLINE_PLAYER_ENABLED` on, it renders as one bar: a round play control with "Play", and the provider link ("YouTube ↗", labelled "Open on YouTube") at the bar's end. One tap opens the player under the bar and asks it to start (YouTube and TikTok `autoplay=1`, SoundCloud `auto_play=true`; Spotify and Bandcamp have no such setting). The bar then says Close. Opening a player by tap closes any other on the page, and closing a player clears its frame so it stops. With `FORUM_MEDIA_EMBEDS_POSTERS_ENABLED` also on, a closed YouTube player (not a Short) is its poster at 16:9 with the play control over it. The poster is copied once from YouTube's image host by a hidden background request on the first view, then served from this site, so page views never contact YouTube. On `/tracks/` a closed player is a small tile beside the track's title ([music section](music_section.md)). The Music slides reuse the same player at full size and open it as if tapped when someone moves to the next slide, so the same start request goes out.
Sources: [renderer](../../src/ForumRewrite/View/MediaEmbedRenderer.php), [player script](../../public/assets/media_embed_inline_player.js), [poster store](../../src/ForumRewrite/View/MediaEmbedPosterStore.php), [poster request and route](../../src/ForumRewrite/Http/MediaEmbedPreviewController.php), [styles](../../public/assets/site.css) (`.media-embed-player`, `.music-tracks`), [flags](../../src/ForumRewrite/Support/FeatureFlags/FeatureFlagRegistry.php), [tests](../../tests/MediaEmbedRendererTest.php), [poster tests](../../tests/MediaEmbedPosterStoreTest.php), [browser check](../../tests/browser/media_embed_browser.mjs), [plans](../plans/embed_presentation/embed_presentation_step3_development_plan.md), [earlier embed work](../plans/media_embed_support_checklist.md).

Boundary: no provider frame loads before a tap, and a page never fetches a poster while it renders. Posters live in a `posters` folder beside the preview cache database, not in the image store: they are a disposable cache, deleting them is safe, and a failed fetch waits an hour before the next try. A poster is answered from `/internal/media-embeds/posters/<video id>.jpg` with the one-year header attached images use. Without JavaScript the bar still opens the player, without autostart or closing others. Instagram keeps its preview card. Offline mode does not render embeds.

*— Claude · 2026-11-27 UTC · Model: claude-opus-5-5*
*— Revised by Claude · 2026-11-29 UTC · Model: claude-opus-5-5* (slides as a caller)

Attached recordings use the same one-at-a-time rule: opening an embed pauses any [audio attachment](audio_attachment.md), and playing a recording closes an open embed.
