Skip to content
Embed anywhere

Embed a video anywhere

Three ways to put a hosted video on a page, from no code at all to full control:

You haveUseEvents from the player
A site builder, or any page you can paste HTML intoThe embed code from the dashboardNo
A page where you can add a script tag, no build stepThe embed code plus the hosted player.v1.js scriptYes
A site built with a bundler (Vite, webpack, esbuild)The transcodely-player element from @transcodely/sdkYes

On WordPress, see the WordPress quickstart. In React, see the React quickstart.

The quick path: paste the embed code

  1. Upload the video in the dashboard under Videos and wait until it is ready.
  2. 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.
  3. In the same card, choose the Embed code tab and press Copy.
  4. 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 ready yet, 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 script tag, or the script ran before the iframe was on the page. Construct the player after the iframe.

Next steps

Run this against your own file

A free account runs standard-quality encodes up to 2 minutes, one at a time (a longer upload is shortened to its first 2 minutes), so the Quickstart runs with nothing set up but an API key.