Skip to main content
Put a segmnt video in a Moodle course: in a Label on the course page, in a Page or Book chapter, or in an HTML block. Moodle is PHP on your server, so it can also make a fresh playback token on every page load — the same job the WordPress plugin does there. Moodle treats pasted iframes carefully. An administrator can always paste an iframe. A teacher can only save iframe code when the site allows it. Section 2 shows the two switches an admin can set.

Before you start

  1. Your video is ready (vid_...). See Manage videos.
  2. The Moodle site’s host, for example moodle.example.com, is a verified domain of the project. See Accounts, projects, API keys and domains.
  3. A playback API key (sk_...) is stored on the Moodle server, ready for the token step. Create a playback key in the segmnt dashboard; it can only make playback tokens.

1. Let iframes into course content

By default, Moodle cleans the HTML that teachers save, and an iframe is often removed. An administrator can change this in two ways. Pick one. Option A: allow embed tags site-wide. In Site administration → Security → Site policies, turn on Allow EMBED and OBJECT tags. This lets authors paste third-party embed code anywhere. It is the broad switch: check it fits your site’s rules first. Option B: trust a teacher role instead. Give the teacher role the capability moodle/site:trustcontent. Users with that capability keep their iframe code; everyone else stays cleaned. This is the narrower switch. Test with the same role that will add the videos in real courses. If the iframe still disappears, paste it again with an administrator account.
Moodle’s editor may also tidy pasted code. If the iframe code vanishes while you type, use the editor’s HTML / source view (</> in the toolbar) to paste the block.

2. Add the video to a course page

  1. Make a playback token for the video and your Moodle host, with the cURL call from Create playback tokens on your server.
  2. Edit the Label, Page or HTML block, open the HTML/source view, and paste:
  1. Replace vid_9xR4tL with your video id and YOUR_PLAYBACK_TOKEN with the real token.
  2. Save and view the page as a student would. The video plays only on the verified host, so a look at the page as a real user is the check that matters.
This hand-made token is good for a short test. It stops working when it expires (4 hours by default). A real course page needs a fresh token on every page load — the next section.

3. A fresh token on every page load

For a page students open every day, do not paste one token. Let the Moodle server mint a new one each time it builds the page. The recommended way is a small text filter plugin: it replaces a short placeholder in any course text with the finished iframe. The placeholder in the teacher’s text:
The filter (the shape of a Moodle filter plugin’s filter() method):
Notes on this sample:
  • The API key lives in the plugin’s admin settings (a site administrator pastes it once, like the WordPress plugin does), never in a course page or a code comment in a lesson.
  • The domain comes from the server (wwwroot), not from the page, so a page author cannot pick another domain.
  • The HTTP call is the same POST .../playback-tokens call shown in Create playback tokens on your server. That route, its answer shape (token, expiresAt, embedUrl) and the key rules are covered by the API tests.
Caching. Moodle caches the output of text filters, and your host may cache whole pages. A cached page serves an old token, and the video stops when the token expires. Before you rely on the filter in a live course, check the caching section of the Moodle filter plugin documentation and keep any page-cache lifetime under about 4 hours, as in the WordPress guide.
Building the filter plugin takes care. If your course count is small, the hand-made token in section 2, renewed by an editor, can be enough to start.

Common problems

Where to go next

Tested against the current release

Checked on 24 Oct 2026:
  • The embed block is the same markup the dashboard’s Copy code box builds: /e/{videoId}?token=…, the allow list, referrerpolicy="origin" and the responsive wrapper.
  • GET https://cdn.segmnt.cloud/segmnt-player.js → 200; GET /e/{videoId} with no token → 403 token_missing (checked on the TEST deploy).
  • The filter’s HTTP call is the same playback-tokens request as the cURL example, which the API tests cover.
  • Unverified: the filter class itself has not run on a Moodle install — the TEST environment has no Moodle site yet. The Moodle-specific parts (plugin settings, the moodle_text_filter shape, filter output caching) follow the Moodle filter plugin documentation. Verify section 1 and 2 on your Moodle site before a live course, and treat section 3 as a starting point, not a finished plugin.