Vue quickstart
Play a hosted video in a Vue 3 app with the transcodely-player custom element. This uses @transcodely/sdk 0.3.28 or later and needs no Vue plugin.
The quick path: install the SDK, tell Vue the tag is a custom element, import the element once, and use the tag.
1. Install
npm install @transcodely/sdk2. Tell Vue it is a custom element
Without this, Vue tries to resolve transcodely-player as a Vue component and warns that it cannot.
// vite.config.js
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
export default defineConfig({
plugins: [
vue({
template: { compilerOptions: { isCustomElement: (tag) => tag === "transcodely-player" } },
}),
],
});In Nuxt, the same option goes in nuxt.config.ts under vue: { compilerOptions: { isCustomElement } }.
3. Use the element
<!-- src/components/LessonPlayer.vue -->
<script setup lang="ts">
import "@transcodely/sdk/player/element";
defineProps<{ videoId: string }>();
function onProgress(e: CustomEvent<{ seconds: number; percent: number }>) {
console.log(`played ${Math.round(e.detail.percent * 100)}%`);
}
function onCompleted(e: CustomEvent<{ percent: number; previously: boolean }>) {
if (!e.detail.previously) console.log("lesson complete");
}
</script>
<template>
<transcodely-player
:video-id="videoId"
title="Lesson"
@progress="onProgress"
@completed="onCompleted"
/>
</template>Render <LessonPlayer video-id="vid_a1b2c3d4e5f6g7" /> with the id of a ready, public or unlisted video. Importing the element module defines the tag in the browser and does nothing during server rendering, so it is safe in Nuxt too.
Events arrive as DOM events with the payload in event.detail: ready, play, pause, ended, seeked, timeupdate, progress, completed and error. In progress, percent is the share of the video actually played, from 0 to 1; seeking ahead does not add to it. completed fires once per page load when that share reaches the threshold, 0.9 by default.
Methods. Put a ref on the element and call play(), pause() or seek(seconds) on it.
4. Private videos
A private video needs a playback token, signed on your server for one viewer. Never sign it in the browser. Point the element at an endpoint of yours that answers {"token": "ptk_…"}; it fetches a token before loading and a fresh one when the token expires:
<transcodely-player
:video-id="videoId"
:token-url="`/api/playback-token?video=${videoId}`"
/>The endpoint is a few lines on any server: see the React quickstart for one in Node.js, and Protected Playback for others. The same server is where uploads go: Browser Uploads has the framework-free uploader for Vue.
What can go wrong
- “Failed to resolve component: transcodely-player”: the
isCustomElementoption is missing. - The element renders but nothing plays: the video is not
ready, or it isprivateand has notoken-url. - The player does not load on your domain: your app limits Allowed embed domains and this host is not on the list.
Next steps
- Embed a video anywhere: every attribute of the element.
- Course Progress: completion, resume and progress per viewer.
- SvelteKit quickstart.