Before you start
- Your video is ready (
vid_...). See Manage videos. - The Moodle site’s host, for example
moodle.example.com, is a verified domain of the project. See Accounts, projects, API keys and domains. - 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 capabilitymoodle/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
- Make a playback token for the video and your Moodle host, with the cURL call from Create playback tokens on your server.
- Edit the Label, Page or HTML block, open the HTML/source view, and paste:
- Replace
vid_9xR4tLwith your video id andYOUR_PLAYBACK_TOKENwith the real token. - 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.
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:filter plugin’s filter() method):
- 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-tokenscall 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
- Embed a video on any website
- Create playback tokens on your server
- Add segmnt to WordPress: the same two paths, on WordPress.
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=…, theallowlist,referrerpolicy="origin"and the responsive wrapper. GET https://cdn.segmnt.cloud/segmnt-player.js→200;GET /e/{videoId}with no token →403token_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_filtershape, 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.