Frameworks
Vega Player is a standard Custom Element, so it works wherever HTML works. Every attribute is also a property that reflects back to the attribute, which is what modern frameworks use when they pass props to custom elements. Values set before the script has loaded are applied when the element upgrades.
import { useEffect, useRef } from 'react';import './vega-player.js';
export function Trailer({ src }) { const ref = useRef(null);
useEffect(() => { const onEnded = () => console.log('ended'); ref.current.addEventListener('vega-player:ended', onEnded); return () => ref.current?.removeEventListener('vega-player:ended', onEnded); }, []);
return <vega-player ref={ref} src={src} color-primary="#ff6a2b" show-playback-rate />;}<script setup>import { onMounted, ref } from 'vue';import './vega-player.js';
const player = ref(null);onMounted(() => { player.value.addEventListener('vega-player:play', () => console.log('play'));});</script>
<template> <vega-player ref="player" src="/video.mp4" :thumbnails="thumbsUrl" show-playback-rate /></template>Tell Vue it is a custom element (in vite.config.js):
vue({ template: { compilerOptions: { isCustomElement: (tag) => tag === 'vega-player' } } })<script> import { onMount } from 'svelte'; import './vega-player.js';
let { src } = $props(); let player;
onMount(() => { player.addEventListener('vega-player:ended', () => console.log('ended')); });</script>
<vega-player bind:this={player} {src} show-playback-rate></vega-player>---const { src } = Astro.props;---<script type="module" src="/vega-player.js"></script><vega-player src={src} thumbnails={`${src}.vtt`}></vega-player><vega-player src="<?= htmlspecialchars($video['url']) ?>" poster="<?= htmlspecialchars($video['poster']) ?>" thumbnails="/thumbs/<?= (int) $video['id'] ?>/thumbnails.vtt"></vega-player>Server-side rendering
Section titled “Server-side rendering”The player renders on the client. During server rendering the tag is output as-is and upgrades as soon as
the script loads; set aspect-ratio so the page reserves the right space in the meantime.