Media Svelte
Svelte 5 video player, image components, and infinite media feeds for Rixl, with typed props, callbacks, and player context.
Svelte 5 video player, image components, and infinite media feeds for Rixl. @rixl/media-svelte provides typed props, callbacks, bindable feed mute state, and player context using the shared Rixl media UI.
What you get
- Adaptive HLS playback, captions, quality selection, fullscreen, and picture-in-picture.
- Images with lazy loading and ThumbHash placeholders when available.
- Vertical media feeds with pagination, looping, and automatic advancement.
- Svelte 5 callbacks, snippets for video children, and
bind:mutedon feeds. - Included player styles, with no Tailwind CSS setup.
Install
npm install @rixl/media-svelteRequires Svelte 5 or later. Core and Lit are included as dependencies. The published components are compiled for the browser.
Quick start
Connect on mount and render media after the connection succeeds:
<script lang="ts">
import {onMount} from "svelte";
import {connect} from "@rixl/media-svelte/core";
import {Video} from "@rixl/media-svelte/video";
let ready = $state(false);
let error = $state("");
onMount(() => {
connect({baseUrl: "https://api.rixl.com", apiKey: "YOUR_PUBLIC_API_KEY"})
.then(() => { ready = true; })
.catch(() => { error = "Unable to connect to Rixl."; });
});
</script>
{#if error}
<p role="alert">{error}</p>
{:else if ready}
<Video id="YOUR_VIDEO_ID" muted={true} style="display:block;width:100%;aspect-ratio:16/9" />
{:else}
<p role="status">Loading media…</p>
{/if}
Use credentials intended for browser access. Reuse the shared client if your application already connects through @rixl/sdk.
SvelteKit
The current package ships browser-compiled components. Render them in a client-rendered SvelteKit route:
// src/routes/media/+page.ts
export const ssr = false;Place the quick-start component in that route's +page.svelte. This disables server rendering for that route. Other routes can retain their normal rendering configuration. Import pure helpers from /core when you need shared calculations in server code.
Images and feeds
Use these components after your application connects:
<script lang="ts">
import {Image} from "@rixl/media-svelte/image";
import {Feed} from "@rixl/media-svelte/feed";
let muted = $state(true);
</script>
<Image id="YOUR_IMAGE_ID" alt="Mountain lake at sunrise" style="display:block;aspect-ratio:16/9;width:100%" />
<Feed feedId="YOUR_FEED_ID" bind:muted style="display:block;height:36rem" />Production components request media by id or feedId through the SDK.
Callbacks and player context
Video supports callbacks such as onPlay, onPause, onEnded, onPausedChange, onLoadingChange, and onError. State callbacks receive booleans:
<Video id="YOUR_VIDEO_ID" onPausedChange={(paused) => console.log(paused)} /><VideoPlayer> shares one player scope with sibling controls. Call getPlayerId() or getOptionalPlayerId() from /video during component initialization, and use /core for playback actions and state. A component instance exposes its underlying Lit element.
Styling and imports
Player styles are included inside shadow DOM. Use class and style to size the host. Give images and videos a height or aspect ratio, and feeds a height; host CSS does not select internal controls.
| Import | Exports |
|---|---|
@rixl/media-svelte/image | Image, props, and instance types |
@rixl/media-svelte/video | Video, VideoPlayer, types, and player-context functions |
@rixl/media-svelte/feed | Feed, props, and instance types |
@rixl/media-svelte/core | Headless APIs, stores, utilities, and types |
@rixl/media-svelte | Components and Core exports |
An image-only subpath import excludes video, feed, and HLS code. See the Svelte guide for more.