Why embed your own player instead of a YouTube video
Embedding a YouTube video is free and easy, and for plenty of content it is the right call. The customers who come to us for an embeddable player usually want something the YouTube embed does not give them: no suggested videos from other channels at the end, their own brand on the player, a stream that plays only on their site, or a live event that cannot be muted halfway through because of a song in the background.
- Your brand, instead of a platform's logo and recommendations.
- Control over who watches: domain restriction, country rules and tokens.
- Your own analytics, instead of a third party's.
- A player that fits the page, rather than one that looks pasted in.
The trade-off is that you now need two things: a server that produces the stream (an HLS address ending in .m3u8) and a player that plays it. Our guide on hosting videos on your website without YouTube covers the on-demand side. Here we focus on the embed itself, with code you can paste.
Method 1: the iframe embed, for any CMS
Most streaming platforms, ours included, give you an embed code: an iframe that loads their player with your stream inside. It works in WordPress, Wix, Squarespace, Webflow or plain HTML, because all you do is paste it into the page. A current, responsive version looks like this:
<iframe
src="https://player.example.com/embed/YOUR-CHANNEL"
title="Live stream"
style="width:100%; aspect-ratio:16/9; border:0;"
allow="autoplay; fullscreen; picture-in-picture"
allowfullscreen
loading="lazy"></iframe> Four attributes do most of the work. aspect-ratio keeps the player at 16:9 at any width, so it never spills out of the column on a phone, and every current browser supports it. The allow list lets the player go fullscreen, use picture-in-picture and autoplay when muted. loading="lazy" holds the player back until the visitor scrolls near it, which matters on pages with several videos. The title is what screen readers announce, so make it describe the stream.
If your theme or page builder is old
Some builders strip inline styles or still have to serve old browsers. The classic fix is a wrapper whose bottom padding sets the proportion:
<div style="position:relative; padding-bottom:56.25%; height:0; overflow:hidden;">
<iframe
src="https://player.example.com/embed/YOUR-CHANNEL"
title="Live stream"
style="position:absolute; top:0; left:0; width:100%; height:100%; border:0;"
allow="autoplay; fullscreen; picture-in-picture"
allowfullscreen></iframe>
</div> 56.25% is 9 divided by 16. Use 75% for 4:3 video and 177.78% for vertical 9:16.
The limit of an iframe is control. Your page's JavaScript cannot easily talk to the player inside it (pause it, listen for events) unless the player offers an API for that. For most websites it does not matter.
Method 2: hls.js, when you want the player in your own code
If you want to build the player yourself, with your own controls, your own analytics events or your design system, you play the .m3u8 address directly in a video element. Browser support decides how:
- Safari, on Mac and on iPhone, has always played HLS natively.
- Chrome and Edge on desktop began playing HLS natively with versions 141 and 142, in late 2025.
- The rest, including Firefox and older versions, need a JavaScript library. The standard one is hls.js, which is free and open source.
So a plain video tag pointing at the playlist now works in many browsers, but not in all of them yet. The usual pattern loads hls.js wherever the browser supports it and falls back to native playback otherwise. This version also retries on its own while the stream is not live yet. If .m3u8 playlists are new to you, our guide on what an M3U8 file is explains what the player is reading.
<script src="https://cdn.jsdelivr.net/npm/hls.js@1"></script>
<video id="player" controls playsinline
style="width:100%; aspect-ratio:16/9;"></video>
<script>
const video = document.getElementById('player');
const src = 'https://your-server.example.com/live/channel/playlist.m3u8';
function start() {
if (Hls.isSupported()) {
const hls = new Hls({ capLevelToPlayerSize: true });
hls.loadSource(src);
hls.attachMedia(video);
hls.on(Hls.Events.ERROR, (event, data) => {
if (data.fatal) {
hls.destroy();
setTimeout(start, 5000); // not live yet, or the network dropped: retry in 5 s
}
});
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = src; // native HLS (Safari, older iPhones)
}
}
start();
</script> Notes from real deployments:
- hls.js goes first on purpose. Chrome and Edge can play HLS natively now, but routing them through hls.js keeps quality selection and error handling identical in every browser.
- capLevelToPlayerSize stops a small embed from downloading the 1080p version when 480p fills it perfectly. It saves your viewers' data and your monthly transfer.
- CORS. hls.js fetches the playlist and segments with JavaScript, so the streaming server must send CORS headers that allow your domain. If you run your own server (Nginx, MediaMTX), this is the most common reason a stream plays in VLC but not on the page.
- Low latency starts at the source. hls.js only plays with low delay if the stream is LL-HLS. With standard HLS it keeps a normal buffer, which is what you want for stability. To cut the delay, enable low-latency streaming on the channel rather than shrinking the player's buffer.
- Pin the major version (hls.js@1) instead of "latest", so an update never changes your player overnight.
Method 3: a ready-made player
Between pasting an iframe and writing your own player there is a middle ground: a player that already has the controls, the quality menu and the mobile quirks solved.
| Option | Cost | What you get | What you still do |
|---|---|---|---|
| hls.js on its own | Free | The playback engine | Controls, design, analytics |
| Video.js | Free, open source | A complete player with HLS built in and a plugin ecosystem | Hosting, configuration, plugins for ads or analytics |
| Commercial players (JW Player, Bitmovin and others) | Paid license | Ads, DRM, analytics and vendor support | Integration and the license itself |
| Player Advance™ | Included with your XtreamCast channel | A branded player tied to your channel's access controls | Paste the embed code |
Choose by what you actually need. If you need DRM (Widevine, FairPlay, PlayReady), look at a commercial player and a platform built for it: XtreamCast does not offer DRM. If you need a branded player that plays only on your site, the included player covers it; on paid plans it carries your brand, and on the free plan it shows a watermark, which is fine for testing the embed. For on-demand libraries, OnDemand gives every video its own player.
Keep your embed from playing on other sites
An embed code is public. Anyone can open your page source and paste the same iframe on their own site, or copy the .m3u8 address into another player. These are the protections that matter, and how they work on XtreamCast:
- Domain restriction (ShieldPower). The embedded player only plays on the domains you authorize.
- SecureToken. Protects the stream addresses themselves, for HLS, LL-HLS, WebRTC and SRT, so copying a URL is not enough to play it somewhere else.
- Country geoblocking. An allow list or a deny list of countries, useful for content with territorial rights.
- HTTPS end to end, which also prevents the mixed-content error described below.
Logins, ticket sales or single sign-on for your audience live on your own site, which then embeds the player. The security features page lists what each control does, and our guide on live streaming security goes into what each layer stops and what it does not.
Mistakes that break an embed
Autoplay with sound
Browsers block autoplay when the video has sound. If you need the stream to start on its own, start it muted and let the viewer turn the sound on:
<video autoplay muted playsinline controls></video> No playsinline on iPhone
Without playsinline, the iPhone opens the video fullscreen instead of playing it inside the page. Add it every time.
An HTTP stream on an HTTPS page
If your site runs on HTTPS, and it should, browsers block a player or stream loaded over plain HTTP as mixed content. Every address in the embed has to be HTTPS.
An embed anyone can reuse
Premium or private content without domain restriction ends up on someone else's page sooner or later. Turn on ShieldPower and SecureToken before you publish, not after you find the copy.
Too many players loading at once
On a page with several videos, use loading="lazy" on iframes and preload="none" on video elements, so the browser does not download every player before the visitor scrolls. With one or two videos, preload="metadata" is enough to show the duration and a thumbnail.
Nothing to show before the stream starts
Viewers who open the page early should see a poster image or a message, not an error. A poster attribute on the video element, plus the retry loop in the hls.js example, covers both.
Expecting the iframe to do your SEO
Do not count on an iframe for search: engines may or may not associate its content with your page. Describe the stream or the video in the page's own text, because that is what gets found.
If viewers far from your server report slow starts even with all of this in place, the cause may be distance, and our guide on what a video CDN is explains when edge delivery helps.
A branded player that plays only on your site
Player Advance™ embeds your live channel with your brand, domain restriction and SecureToken. Start on the free plan to test the embed on your own page.