Embed a video anywhere
Three ways to put a hosted video on a page, from no code at all to full control:
| You have | Use | Events from the player |
|---|---|---|
| A site builder, or any page you can paste HTML into | The embed code from the dashboard | No |
A page where you can add a script tag, no build step | The embed code plus the hosted player.v1.js script | Yes |
| A site built with a bundler (Vite, webpack, esbuild) | The transcodely-player element from @transcodely/sdk | Yes |
On WordPress, see the WordPress quickstart. In React, see the React quickstart.
The quick path: paste the embed code
- Upload the video in the dashboard under Videos and wait until it is
ready. - Open the video. On its Overview tab, the Sharing card sets who can watch: Public or Unlisted (the default). A Private video has no embed code; see Private videos below.
- In the same card, choose the Embed code tab and press Copy.
- Paste it into your page’s HTML, or into your site builder’s custom HTML or embed block.
The code looks like this. It scales to the width of whatever it is placed in, at 16:9:
<div style="position:relative;padding-top:56.25%"><iframe src="https://play.transcodely.com/v/vid_a1b2c3d4e5f6g7" title="Lesson 1" loading="lazy" style="position:absolute;inset:0;width:100%;height:100%;border:0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe></div>The same code is on the video object as embed_code, and the bare player link as embed_url, once the video is ready and not private.
Some site builders remove script tags from pasted code, or run it in a sandboxed frame. The iframe still plays there; only the player events in the next section are unavailable.
Listen to the player on a plain page
Load the hosted script after the embed code and attach it to the iframe:
<div style="position:relative;padding-top:56.25%"><iframe src="https://play.transcodely.com/v/vid_a1b2c3d4e5f6g7" title="Lesson 1" loading="lazy" style="position:absolute;inset:0;width:100%;height:100%;border:0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe></div>
<script src="https://play.transcodely.com/player.v1.js"></script>
<script>
const iframe = document.querySelector('iframe[src^="https://play.transcodely.com/v/"]');
const player = new Transcodely.Player(iframe);
player.on('progress', ({ percent }) => {
console.log('played', Math.round(percent * 100) + '%');
});
player.on('completed', () => console.log('lesson complete'));
</script>percent in progress is the share of the video actually played: seeking ahead does not add to it. completed fires once per page load when that share reaches the threshold, 0.9 by default. The script also has methods (play(), pause(), setCurrentTime(seconds), …) and an ES module at player.v1.mjs; Course Progress lists them all.
Use the element on a site with a bundler
npm install @transcodely/sdk<transcodely-player video-id="vid_a1b2c3d4e5f6g7" title="Lesson 1"></transcodely-player>
<script type="module">
// Defines <transcodely-player>. Bundle this with the rest of your scripts.
import "@transcodely/sdk/player/element";
const el = document.querySelector("transcodely-player");
el.addEventListener("progress", (e) => console.log("played", e.detail.percent));
el.addEventListener("completed", () => console.log("lesson complete"));
</script>The element creates the same iframe and sends the same events as DOM events, with the payload in event.detail. Attributes: video-id or src, token, token-url, autoplay (always starts muted), muted, loop, start (seconds), complete-at and title. Methods: play(), pause(), seek(seconds). Importing the module on a server does nothing, so it is safe in server-rendered apps. The Vue and SvelteKit quickstarts show it in those frameworks.
Private videos
A private video plays only with a playback token, which your server signs for one viewer. A site builder cannot sign one, so on a site builder use Unlisted, or the WordPress plugin on WordPress. On your own site, give the element a token-url on your server that answers with {"token": "ptk_…"}:
<transcodely-player video-id="vid_a1b2c3d4e5f6g7" token-url="/api/playback-token?video=vid_a1b2c3d4e5f6g7"></transcodely-player>Protected Playback shows that endpoint in several languages.
What can go wrong
- There is no Embed code tab: the video is not
readyyet, or it is Private. - The player does not load on your site but plays on the share link: your app limits Allowed embed domains (on the app’s page in the dashboard) and your site’s host is not on the list. Add it, with
*.for subdomains. - No events arrive: the builder removed your
scripttag, or the script ran before the iframe was on the page. Construct the player after the iframe.
Next steps
- Your First Video on Your Site: the whole no-code path from sign-up, with where to paste in WordPress and site builders.
- Course Progress: completion, resume, and progress per viewer on your server.
- Protected Playback: tokens, allowed domains, overlays.
- Playback & embeds: the embed fields on the video object.