Videos
One component, one provider
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";
<Video
src={url}
width={960}
height={540}
/>
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") → trueYouTube
YouTube
YouTube
YouTube
—
—
—
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"