Showcase
Video
Drop a YouTube URL, get an embed. Auto-detected, privacy-preserving, zero JavaScript required from your bundle.
YouTube embed, auto-detected
The component inspects the URL, extracts the video ID, and switches to a privacy-preserving youtube-nocookie embed automatically. No provider config needed — paste, render, ship.
example.tsx
import { Video, isYouTubeUrl, getYouTubeId } from "swift-rust";
const url = "https://youtu.be/rTJzsHwpZko?si=dyq6s5btq7MnASdS";
// Responsive: a fixed-ratio wrapper, video fills 100%.
<div className="aspect-video w-full">
<Video src={url} aspectRatio="16 / 9" className="h-full w-full rounded-xl" />
</div>
isYouTubeUrl(url); // → true
getYouTubeId(url); // → "rTJzsHwpZko"Auto-detection in action
The same isYouTubeUrl helper that powers the Video component is exported from swift-rust. Try a few URLs against the live detector:
YouTube
isYouTubeUrl("https://youtu.be/rTJzsHwpZko?si=dyq6s5btq7MnASdS") → truehttps://youtu.be/rTJzsHwpZko?si=dyq6s5btq7MnASdSYouTubehttps://www.youtube.com/watch?v=rTJzsHwpZkoYouTubehttps://www.youtube.com/embed/rTJzsHwpZkoYouTubehttps://www.youtube.com/shorts/rTJzsHwpZkoYouTubehttps://example.com/clip.mp4—https://vimeo.com/76979871—not-a-url—Helper functions
Need to know what kind of URL you have, or build an embed URL yourself? These utilities are exported from swift-rust.
helpers.ts
import {
isYouTubeUrl,
getYouTubeId,
detectProvider,
getYouTubeEmbedUrl,
} from "swift-rust";
const url = "https://youtu.be/rTJzsHwpZko?si=dyq6s5btq7MnASdS";
isYouTubeUrl(url); // → true
getYouTubeId(url); // → "rTJzsHwpZko"
detectProvider(url); // → "youtube"
getYouTubeEmbedUrl("rTJzsHwpZko", { autoPlay: true, mute: true });
// → "https://www.youtube-nocookie.com/embed/rTJzsHwpZko?autoplay=1&mute=1"