Skip to main content

View a Stream

Play video streams using manifest URLs.

What is a Manifest Player?​

A Manifest Player plays video streams using manifest URLs (HLS .m3u8, FLV .flv, or DASH .mpd) rather than connecting directly to a WebRTC call. This is commonly used for:

  • Transcoded broadcasts with multiple quality levels
  • Archived/recorded streams (VOD - Video on Demand)
  • CDN-delivered content
  • Scenarios where ultra-low latency isn't required

A Manifest Player plays video streams using a manifest URL (HLS .m3u8, FLV .flv, or DASH .mpd) rather than connecting directly to a WebRTC call. This is commonly used for:

  • Transcoded broadcasts with multiple quality levels
  • Archived/recorded streams (VOD)
  • CDN-delivered content
  • Scenarios where ultra-low latency isn't required

Codec Support and the Snapshot Fallback​

All live browser formats are encoded as H.264 video with AAC audio — there are no VP9 or AV1 live renditions. Every mainstream browser plays H.264, so this rarely matters in practice, but on a browser or device without H.264 support the player has no playable format.

When that happens the player degrades gracefully and automatically: it emits noDrivers, and shows the stream's live snapshot image as a poster, refreshed on the manifest polling interval — so the viewer still sees a periodically-updating picture of the live stream. This requires nothing from your client code:

  • The manifest carries a jpeg format (formats.jpeg.encodings[] at several resolutions) and a previewImg URL; the player picks the best fit and sets it as the video poster (displayPoster option, on by default).
  • The images come from the platform's snapshot service, so they are only available while the stream is live and producing snapshots.

Subscribe to noDrivers and the manifest event (see Player Events & Liveness) if you want to detect this state and adjust your UI.

Each tab below hands the player a manifestUrl. Get it from the stream-detail response: the manifestUrl field is a complete URL ending in <streamId>.json — treat it as opaque and pass it to the playback SDK verbatim, never constructing or modifying it yourself. The same response also carries vfManifestUrl, the video-foundation manifest for that stream; this guide uses manifestUrl only. See Manifests.

This guide demonstrates how to play a livestream using a manifest URL with the @video/video-client-core library and vanilla JavaScript (no framework required).

The manifest player application consists of three main files:

  1. manifest-player.html - HTML structure and script imports
  2. player-utils.js - Utility functions for creating player UI and handling controls
  3. manifest-player.js - Main application logic for loading and controlling the player

Prerequisites​

Before you begin, you'll need:

  • Manifest URL: A URL pointing to your stream manifest (HLS, FLV, DASH, or Native Frame JSON format)

In a production application, you would typically receive the manifest URL from your backend API or video management system.

For more information, see What are manifests?.

HTML​

First, create an HTML file that loads the video-client-core library and your JavaScript modules.

  • videoContainer: Will be populated with video player and controls
<!--
Native Frame Manifest Player - Vanilla JavaScript Implementation

This HTML file demonstrates how to play a livestream using a manifest URL
with the @video/video-client-core library and vanilla JavaScript (no framework required).

A Manifest Player plays video streams using manifest URLs (HLS .m3u8, FLV .flv, or DASH .mpd)
rather than connecting directly to a WebRTC call. This is commonly used for:
- Transcoded broadcasts with multiple quality levels
- Archived/recorded streams (VOD - Video on Demand)
- CDN-delivered content
- Scenarios where ultra-low latency isn't required

The manifest player allows viewers to:
- Play/pause video
- Control volume and muting
- Automatically handle adaptive bitrate streaming
- Play recorded or live streams

Required Setup:
1. Obtain a manifest URL from your Native Frame backend or CDN
2. Load the video-client-core library via CDN
3. Include the necessary JavaScript modules
-->

<!doctype html>
<html>
<head>
<!--
Import Map Configuration

This configures module resolution for ES modules. The "vdc-cdn" alias
points to the video-client-core library hosted on the Native Frame CDN.

You can update the version number in the URL to use a different version
of the library. Check https://cdn.nativeframe.com/ for available versions.
-->

<script type="importmap">
{
"imports": {
"vdc-cdn": "https://cdn.nativeframe.com/video-client-core-13.2.0.js"
}
}
</script>
<!-- << imports -->
<!--
JavaScript Module Imports

These modules must be loaded in order:
1. player-utils.js - Provides helper functions for creating the player UI
2. manifest-player.js - Main application logic for loading and controlling the player

-->
<script type="module" src="/js/player-utils.js"></script>
<script type="module" src="/js/manifest-player.js"></script>
</head>
<body>
<!--
Player UI Structure

The page consists of a single container element:
- videoContainer: Will be populated with the video player and playback controls

The video element and controls are dynamically created and injected by
the player-utils.js module.
-->
<div>
<!-- Video player and controls will be injected here -->
<div id="videoContainer"></div>
</div>
</body>
</html>

Using JavaScript Modules​

The import map tells the browser where to find the vdc-cdn module. You can update the version number in the URL to use different versions of the video-client-core library.

These modules must be loaded as ES modules (type="module") and in this order:

  1. player-utils.js - Provides UI helper functions
  2. manifest-player.js - Contains main application logic
<!--
Import Map Configuration

This configures module resolution for ES modules. The "vdc-cdn" alias
points to the video-client-core library hosted on the Native Frame CDN.

You can update the version number in the URL to use a different version
of the library. Check https://cdn.nativeframe.com/ for available versions.
-->

<script type="importmap">
{
"imports": {
"vdc-cdn": "https://cdn.nativeframe.com/video-client-core-13.2.0.js"
}
}
</script>
<!--
JavaScript Module Imports

These modules must be loaded in order:
1. player-utils.js - Provides helper functions for creating the player UI
2. manifest-player.js - Main application logic for loading and controlling the player

-->
<script type="module" src="/js/player-utils.js"></script>
<script type="module" src="/js/manifest-player.js"></script>

JavaScript​

Player Utils​

This module provides utility functions for creating and managing the player UI.

/**
* Player Utilities Module
*
* This module provides utility functions for creating and managing manifest player UI.
* It handles:
* - Creating video elements and playback controls
* - Appending player UI to the DOM
* - Attaching event handlers for player controls
* - Removing event handlers on cleanup
*
* Key Concepts:
* - Player: The video player instance that manages playback of manifest streams
* - Video Element: The HTML <video> tag where the stream is displayed
* - Playback Controls: Buttons and inputs for play/pause, mute, and volume control
*/

// Player state change events that drive the controls' render(). Shared by
// attachPlayerClickHandlers (to subscribe) and removePlayerClickHandlers (to
// unsubscribe the same handler) so the two lists can never drift apart.
const PLAYER_CONTROL_EVENTS = ["paused", "playing", "muted", "unmuted", "volume"];

// Tracks the {player, render} pair registered for each control id, so
// removePlayerClickHandlers(id) can unsubscribe render from the player events
// it was subscribed to in attachPlayerClickHandlers, even though it only
// receives the id.
const playerControlListeners = new Map();

/**
* Attach Event Handlers to Player Controls
*
* Sets up click and change event handlers for all player UI controls.
* This enables users to:
* - Play/pause video playback
* - Mute/unmute audio
* - Adjust volume level
*
* @param {Player} player - The player instance to control
* @param {string} id - Unique identifier for the video element and its controls
*
* The player object provides these key properties and the events that change them:
* - paused: Boolean indicating if video is paused ("paused" / "playing" events)
* - muted: true, false, or "forced" when the browser's autoplay policy muted it ("muted" / "unmuted" events)
* - volume: Number (0-1) representing volume level ("volume" event)
*/
function attachPlayerClickHandlers(player, id) {
const playBtn = document.getElementById(`playBtn-${id}`);
const muteBtn = document.getElementById(`muteBtn-${id}`);
const volume = document.getElementById(`volume-${id}`);

/**
* Redraw the Controls from Player State
*
* The controls never set their own text from a click. They read the player's
* current state, so they stay correct when playback changes for any other
* reason: a refused autoplay, a driver failover, a quality switch that pauses
* and resumes, or another control on the page.
*/
function render() {
playBtn.textContent = player.paused ? "Play" : "Pause";
// player.muted is true, false, or "forced" (the browser's autoplay policy muted the player)
muteBtn.textContent = player.muted ? "Unmute" : "Mute";
// The slider is 0-100; the player's volume is 0-1
volume.value = String(Math.round(player.volume * 100));
}

/**
* Toggle Play/Pause
*
* A play() the browser refuses resolves without throwing and leaves the
* player paused, so the label is driven by the "paused" / "playing" events
* wired up below, not by this click.
*/
async function togglePlay() {
if (player.paused) {
await player.play();
} else {
await player.pause();
}
}

/**
* Toggle Mute/Unmute
*
* When player.muted is "forced", this click is the user gesture the browser
* needs before audio can start; unmute() returns the player to unmuted.
*/
async function toggleMute() {
if (player.muted) {
await player.unmute();
} else {
await player.mute();
}
}

/**
* Handle Volume Change
*
* Converts the slider's 0-100 range to the player's 0-1 range.
* Setting volume to 0 mutes the player; raising it again restores audio.
*
* @param {Event} ev - Change event from the volume slider
*/
async function handleVolume(ev) {
const volumeValue = Number(ev.target.value);
await player.setVolume(volumeValue / 100);
if (volumeValue === 0) {
await player.mute();
} else if (player.muted) {
await player.unmute();
}
}

/**
* Wire Up Event Listeners
*
* Clicks send commands to the player; player events redraw the controls.
* The initial render() reflects the player's actual starting state instead
* of assuming autoplay succeeded.
*/
playBtn.onclick = togglePlay;
muteBtn.onclick = toggleMute;
volume.onchange = handleVolume;

for (const event of PLAYER_CONTROL_EVENTS) {
player.on(event, render);
}
render();

// Recorded so removePlayerClickHandlers(id) can unsubscribe this exact
// render closure from this exact player before it drops references to it.
playerControlListeners.set(id, { player, render });
}
/**
* Remove Event Listeners from Player Controls
*
* Cleans up event listeners when the player is disposed.
* This prevents memory leaks and ensures proper resource cleanup.
*
* @param {string} id - Unique identifier for the video element and its controls
*
* Important: Always call this function before disposing of a player to
* properly clean up event handlers and prevent memory leaks.
*/
function removePlayerClickHandlers(id) {
// Unsubscribe render from the player events it was subscribed to in
// attachPlayerClickHandlers, so dispose() doesn't leak the closure (and
// everything it captures: playBtn, muteBtn, volume, and the player itself).
const listeners = playerControlListeners.get(id);
if (listeners) {
const { player, render } = listeners;
for (const event of PLAYER_CONTROL_EVENTS) {
player.off(event, render);
}
playerControlListeners.delete(id);
}

// Remove event listeners from all control elements
document.getElementById(`playBtn-${id}`).removeAllListeners();
document.getElementById(`muteBtn-${id}`).removeAllListeners();
document.getElementById(`volume-${id}`).removeAllListeners();
}
/**
* Generate HTML for Video Player and Controls
*
* Creates the HTML structure for the video element and playback controls.
* This includes:
* - Video element for displaying the stream
* - Play/pause toggle button
* - Mute/unmute toggle button
* - Volume slider control
*
* @param {string} id - Unique identifier for the video element and its controls
* @returns {string} HTML string containing the player UI structure
*
* The generated HTML will be injected into the videoContainer div.
* Each control element is given a unique ID based on the provided id parameter,
* allowing multiple players on the same page.
*/
function createVideoElement(id) {
return `
<div id="video-wrapper-${id}">
<!-- Video element where the stream will be displayed -->
<video
width="100%"
height="100%"
id="${id}"
>
</video>

<!-- Play/pause toggle button -->
<button id="playBtn-${id}"></button>

<!-- Mute/unmute toggle button -->
<button id="muteBtn-${id}"></button>

<!-- Volume control slider -->
<div class="volume-container">
<label for="volume-${id}">Volume: </label>
<input type="range" id="volume-${id}" min="0" max="100" value="50" />
</div>
</div>
`;
}

/**
* Append Video Player to DOM
*
* Injects the player UI into the page and returns a reference to the video element.
* This function:
* 1. Finds the video container div
* 2. Inserts the player HTML
* 3. Returns the video element for player attachment
*
* @param {string} id - Unique identifier for the video element
* @returns {HTMLVideoElement} Reference to the video element
*
* The video element is returned so the Player can be attached to it using
* player.attachTo(videoElement).
*/
function appendVideoElement(id) {
// Find the container where we'll inject the player UI
const videoContainer = document.getElementById("videoContainer");

// Insert the player HTML into the container
videoContainer.insertAdjacentHTML("beforeend", createVideoElement(id));

// Return reference to the video element
return document.getElementById(id);
}

/**
* Export Utility Functions
*
* These functions are used by the main manifest-player.js module to
* create and manage the player UI.
*/
export { attachPlayerClickHandlers, removePlayerClickHandlers, appendVideoElement };

Main Application Logic (manifest-player.js)​

Manifest URL Configuration​

The manifest URL points to the stream you want to play. This can be:

  • HLS manifest (.m3u8) - Most common for live and VOD streaming
  • FLV manifest (.flv) - Used for Flash-based streaming
  • DASH manifest (.mpd) - Alternative adaptive streaming format
  • Native Frame JSON manifest (.json) - Contains multiple format options

In a production application, you would typically:

  • Fetch this URL from your backend API
  • Receive it from a webhook when transcoding starts
  • Get it from your video management system
  • Pass it as a URL parameter or configuration
/**
* Native Frame Manifest Player - Main Application
*
* This is the main application file for the manifest player. It handles:
* - Loading and playing video streams from manifest URLs
* - Creating and managing the player UI
* - Handling playback controls
* - Resource cleanup
*
* Flow:
* 1. Page loads → init() is called
* 2. Player is requested with the manifest URL
* 3. Video element and controls are created and added to the DOM
* 4. Player is attached to the video element
* 5. User can control playback via UI buttons
* 6. Resources are cleaned up when page is hidden
*
* Manifest Player vs WebRTC Player:
* - Manifest players use HLS/FLV/DASH URLs for transcoded streams
* - WebRTC players connect directly to live calls for ultra-low latency
* - Public manifests need no credential; a private stream passes `auth: authClient` to requestPlayer
* - Manifest players support adaptive bitrate streaming
*/

import { requestPlayer } from 'vdc-cdn';
import { attachPlayerClickHandlers, removePlayerClickHandlers, appendVideoElement } from './player-utils.js';

/**
* Manifest URL Configuration
*
* The manifest URL points to the stream you want to play. This can be:
* - HLS manifest (.m3u8) - Most common for live and VOD streaming
* - FLV manifest (.flv) - Used for Flash-based streaming
* - DASH manifest (.mpd) - Alternative adaptive streaming format
* - Native Frame JSON manifest (.json) - Contains multiple format options
*
* In a production application, you would typically:
* - Fetch this URL from your backend API
* - Receive it from a webhook when transcoding starts
* - Get it from your video management system
* - Pass it as a URL parameter or configuration
*
* For more information, see:
* https://docs.nativeframe.com/concepts/manifests
*/
const manifestUrl = "https://manifests.example.com/manifest/api/v1/live/your-stream-id.json";

/**
* Application State
*
* The player variable maintains the player instance throughout the application lifecycle.
* It is initialized to null and populated during init().
*/
let player = null;

/**
* Initialize the Manifest Player
*
* This is the main initialization function that sets up the player.
* It runs when the page loads and performs these steps:
*
* 1. Requests a player instance with the manifest URL
* 2. Creates video element and controls in the DOM
* 3. Attaches the player to the video element
* 4. Sets up event handlers for playback controls
* 5. Registers cleanup handler for page visibility changes
*
* Player Options:
* - autoPlay: true - Automatically starts playing when loaded
* - muted: false - Audio is enabled by default (set to true for autoplay in some browsers)
*
* After init() completes, the video will start playing automatically and
* users can control playback via the play/pause, mute, and volume controls.
*/
async function init() {
// Request a player instance for the manifest URL
// The player automatically handles:
// - Loading the manifest
// - Selecting the appropriate playback technology (HLS.js, mpegts.js, native)
// - Adaptive bitrate streaming
// - Buffering and playback
player = await requestPlayer(manifestUrl, { autoPlay: true, muted: false });

// Create and append the video element with controls to the DOM
const video = appendVideoElement("manifest-player");

// Attach the player to the video element
// This connects the player's media stream to the video tag for display
player.attachTo(video);

// Set up event handlers for playback controls (play, mute, volume)
attachPlayerClickHandlers(player, "manifest-player");

// Register cleanup handler for when the page is hidden
document.addEventListener("visibilitychange", dispose);
}

/**
* Clean Up Player Resources
*
* Disposes of the player and removes event listeners when the page is hidden.
* This should be called to:
* - Release video resources
* - Stop network connections
* - Free up memory
*
* Important: Always dispose of player resources when done to prevent:
* - Memory leaks
* - Continued network usage
* - Background playback when page is not visible
*
* This function is triggered automatically by the visibilitychange event
* when the user navigates away or hides the page.
*/
function dispose() {
if (document.hidden) {
// Dispose of the player (stops playback and releases resources)
player?.dispose();
player = null;

// Remove event handlers from control elements
removePlayerClickHandlers("manifest-player");

// Remove the visibility change listener
document.removeEventListener("visibilitychange", dispose);
}
}

/**
* Application Entry Point
*
* This runs when the page finishes loading. It calls init() to set up
* the player and start playback.
*/
window.onload = async () => {
await init();
};

Full Code​

<!--
Native Frame Manifest Player - Vanilla JavaScript Implementation

This HTML file demonstrates how to play a livestream using a manifest URL
with the @video/video-client-core library and vanilla JavaScript (no framework required).

A Manifest Player plays video streams using manifest URLs (HLS .m3u8, FLV .flv, or DASH .mpd)
rather than connecting directly to a WebRTC call. This is commonly used for:
- Transcoded broadcasts with multiple quality levels
- Archived/recorded streams (VOD - Video on Demand)
- CDN-delivered content
- Scenarios where ultra-low latency isn't required

The manifest player allows viewers to:
- Play/pause video
- Control volume and muting
- Automatically handle adaptive bitrate streaming
- Play recorded or live streams

Required Setup:
1. Obtain a manifest URL from your Native Frame backend or CDN
2. Load the video-client-core library via CDN
3. Include the necessary JavaScript modules
-->

<!doctype html>
<html>
<head>
<!--
Import Map Configuration

This configures module resolution for ES modules. The "vdc-cdn" alias
points to the video-client-core library hosted on the Native Frame CDN.

You can update the version number in the URL to use a different version
of the library. Check https://cdn.nativeframe.com/ for available versions.
-->

<script type="importmap">
{
"imports": {
"vdc-cdn": "https://cdn.nativeframe.com/video-client-core-13.2.0.js"
}
}
</script>
<!-- << imports -->
<!--
JavaScript Module Imports

These modules must be loaded in order:
1. player-utils.js - Provides helper functions for creating the player UI
2. manifest-player.js - Main application logic for loading and controlling the player

-->
<script type="module" src="/js/player-utils.js"></script>
<script type="module" src="/js/manifest-player.js"></script>
</head>
<body>
<!--
Player UI Structure

The page consists of a single container element:
- videoContainer: Will be populated with the video player and playback controls

The video element and controls are dynamically created and injected by
the player-utils.js module.
-->
<div>
<!-- Video player and controls will be injected here -->
<div id="videoContainer"></div>
</div>
</body>
</html>
/**
* Player Utilities Module
*
* This module provides utility functions for creating and managing manifest player UI.
* It handles:
* - Creating video elements and playback controls
* - Appending player UI to the DOM
* - Attaching event handlers for player controls
* - Removing event handlers on cleanup
*
* Key Concepts:
* - Player: The video player instance that manages playback of manifest streams
* - Video Element: The HTML <video> tag where the stream is displayed
* - Playback Controls: Buttons and inputs for play/pause, mute, and volume control
*/

// Player state change events that drive the controls' render(). Shared by
// attachPlayerClickHandlers (to subscribe) and removePlayerClickHandlers (to
// unsubscribe the same handler) so the two lists can never drift apart.
const PLAYER_CONTROL_EVENTS = ["paused", "playing", "muted", "unmuted", "volume"];

// Tracks the {player, render} pair registered for each control id, so
// removePlayerClickHandlers(id) can unsubscribe render from the player events
// it was subscribed to in attachPlayerClickHandlers, even though it only
// receives the id.
const playerControlListeners = new Map();

/**
* Attach Event Handlers to Player Controls
*
* Sets up click and change event handlers for all player UI controls.
* This enables users to:
* - Play/pause video playback
* - Mute/unmute audio
* - Adjust volume level
*
* @param {Player} player - The player instance to control
* @param {string} id - Unique identifier for the video element and its controls
*
* The player object provides these key properties and the events that change them:
* - paused: Boolean indicating if video is paused ("paused" / "playing" events)
* - muted: true, false, or "forced" when the browser's autoplay policy muted it ("muted" / "unmuted" events)
* - volume: Number (0-1) representing volume level ("volume" event)
*/
function attachPlayerClickHandlers(player, id) {
const playBtn = document.getElementById(`playBtn-${id}`);
const muteBtn = document.getElementById(`muteBtn-${id}`);
const volume = document.getElementById(`volume-${id}`);

/**
* Redraw the Controls from Player State
*
* The controls never set their own text from a click. They read the player's
* current state, so they stay correct when playback changes for any other
* reason: a refused autoplay, a driver failover, a quality switch that pauses
* and resumes, or another control on the page.
*/
function render() {
playBtn.textContent = player.paused ? "Play" : "Pause";
// player.muted is true, false, or "forced" (the browser's autoplay policy muted the player)
muteBtn.textContent = player.muted ? "Unmute" : "Mute";
// The slider is 0-100; the player's volume is 0-1
volume.value = String(Math.round(player.volume * 100));
}

/**
* Toggle Play/Pause
*
* A play() the browser refuses resolves without throwing and leaves the
* player paused, so the label is driven by the "paused" / "playing" events
* wired up below, not by this click.
*/
async function togglePlay() {
if (player.paused) {
await player.play();
} else {
await player.pause();
}
}

/**
* Toggle Mute/Unmute
*
* When player.muted is "forced", this click is the user gesture the browser
* needs before audio can start; unmute() returns the player to unmuted.
*/
async function toggleMute() {
if (player.muted) {
await player.unmute();
} else {
await player.mute();
}
}

/**
* Handle Volume Change
*
* Converts the slider's 0-100 range to the player's 0-1 range.
* Setting volume to 0 mutes the player; raising it again restores audio.
*
* @param {Event} ev - Change event from the volume slider
*/
async function handleVolume(ev) {
const volumeValue = Number(ev.target.value);
await player.setVolume(volumeValue / 100);
if (volumeValue === 0) {
await player.mute();
} else if (player.muted) {
await player.unmute();
}
}

/**
* Wire Up Event Listeners
*
* Clicks send commands to the player; player events redraw the controls.
* The initial render() reflects the player's actual starting state instead
* of assuming autoplay succeeded.
*/
playBtn.onclick = togglePlay;
muteBtn.onclick = toggleMute;
volume.onchange = handleVolume;

for (const event of PLAYER_CONTROL_EVENTS) {
player.on(event, render);
}
render();

// Recorded so removePlayerClickHandlers(id) can unsubscribe this exact
// render closure from this exact player before it drops references to it.
playerControlListeners.set(id, { player, render });
}
/**
* Remove Event Listeners from Player Controls
*
* Cleans up event listeners when the player is disposed.
* This prevents memory leaks and ensures proper resource cleanup.
*
* @param {string} id - Unique identifier for the video element and its controls
*
* Important: Always call this function before disposing of a player to
* properly clean up event handlers and prevent memory leaks.
*/
function removePlayerClickHandlers(id) {
// Unsubscribe render from the player events it was subscribed to in
// attachPlayerClickHandlers, so dispose() doesn't leak the closure (and
// everything it captures: playBtn, muteBtn, volume, and the player itself).
const listeners = playerControlListeners.get(id);
if (listeners) {
const { player, render } = listeners;
for (const event of PLAYER_CONTROL_EVENTS) {
player.off(event, render);
}
playerControlListeners.delete(id);
}

// Remove event listeners from all control elements
document.getElementById(`playBtn-${id}`).removeAllListeners();
document.getElementById(`muteBtn-${id}`).removeAllListeners();
document.getElementById(`volume-${id}`).removeAllListeners();
}
/**
* Generate HTML for Video Player and Controls
*
* Creates the HTML structure for the video element and playback controls.
* This includes:
* - Video element for displaying the stream
* - Play/pause toggle button
* - Mute/unmute toggle button
* - Volume slider control
*
* @param {string} id - Unique identifier for the video element and its controls
* @returns {string} HTML string containing the player UI structure
*
* The generated HTML will be injected into the videoContainer div.
* Each control element is given a unique ID based on the provided id parameter,
* allowing multiple players on the same page.
*/
function createVideoElement(id) {
return `
<div id="video-wrapper-${id}">
<!-- Video element where the stream will be displayed -->
<video
width="100%"
height="100%"
id="${id}"
>
</video>

<!-- Play/pause toggle button -->
<button id="playBtn-${id}"></button>

<!-- Mute/unmute toggle button -->
<button id="muteBtn-${id}"></button>

<!-- Volume control slider -->
<div class="volume-container">
<label for="volume-${id}">Volume: </label>
<input type="range" id="volume-${id}" min="0" max="100" value="50" />
</div>
</div>
`;
}

/**
* Append Video Player to DOM
*
* Injects the player UI into the page and returns a reference to the video element.
* This function:
* 1. Finds the video container div
* 2. Inserts the player HTML
* 3. Returns the video element for player attachment
*
* @param {string} id - Unique identifier for the video element
* @returns {HTMLVideoElement} Reference to the video element
*
* The video element is returned so the Player can be attached to it using
* player.attachTo(videoElement).
*/
function appendVideoElement(id) {
// Find the container where we'll inject the player UI
const videoContainer = document.getElementById("videoContainer");

// Insert the player HTML into the container
videoContainer.insertAdjacentHTML("beforeend", createVideoElement(id));

// Return reference to the video element
return document.getElementById(id);
}

/**
* Export Utility Functions
*
* These functions are used by the main manifest-player.js module to
* create and manage the player UI.
*/
export { attachPlayerClickHandlers, removePlayerClickHandlers, appendVideoElement };
/**
* Native Frame Manifest Player - Main Application
*
* This is the main application file for the manifest player. It handles:
* - Loading and playing video streams from manifest URLs
* - Creating and managing the player UI
* - Handling playback controls
* - Resource cleanup
*
* Flow:
* 1. Page loads → init() is called
* 2. Player is requested with the manifest URL
* 3. Video element and controls are created and added to the DOM
* 4. Player is attached to the video element
* 5. User can control playback via UI buttons
* 6. Resources are cleaned up when page is hidden
*
* Manifest Player vs WebRTC Player:
* - Manifest players use HLS/FLV/DASH URLs for transcoded streams
* - WebRTC players connect directly to live calls for ultra-low latency
* - Public manifests need no credential; a private stream passes `auth: authClient` to requestPlayer
* - Manifest players support adaptive bitrate streaming
*/

import { requestPlayer } from 'vdc-cdn';
import { attachPlayerClickHandlers, removePlayerClickHandlers, appendVideoElement } from './player-utils.js';

/**
* Manifest URL Configuration
*
* The manifest URL points to the stream you want to play. This can be:
* - HLS manifest (.m3u8) - Most common for live and VOD streaming
* - FLV manifest (.flv) - Used for Flash-based streaming
* - DASH manifest (.mpd) - Alternative adaptive streaming format
* - Native Frame JSON manifest (.json) - Contains multiple format options
*
* In a production application, you would typically:
* - Fetch this URL from your backend API
* - Receive it from a webhook when transcoding starts
* - Get it from your video management system
* - Pass it as a URL parameter or configuration
*
* For more information, see:
* https://docs.nativeframe.com/concepts/manifests
*/
const manifestUrl = "https://manifests.example.com/manifest/api/v1/live/your-stream-id.json";

/**
* Application State
*
* The player variable maintains the player instance throughout the application lifecycle.
* It is initialized to null and populated during init().
*/
let player = null;

/**
* Initialize the Manifest Player
*
* This is the main initialization function that sets up the player.
* It runs when the page loads and performs these steps:
*
* 1. Requests a player instance with the manifest URL
* 2. Creates video element and controls in the DOM
* 3. Attaches the player to the video element
* 4. Sets up event handlers for playback controls
* 5. Registers cleanup handler for page visibility changes
*
* Player Options:
* - autoPlay: true - Automatically starts playing when loaded
* - muted: false - Audio is enabled by default (set to true for autoplay in some browsers)
*
* After init() completes, the video will start playing automatically and
* users can control playback via the play/pause, mute, and volume controls.
*/
async function init() {
// Request a player instance for the manifest URL
// The player automatically handles:
// - Loading the manifest
// - Selecting the appropriate playback technology (HLS.js, mpegts.js, native)
// - Adaptive bitrate streaming
// - Buffering and playback
player = await requestPlayer(manifestUrl, { autoPlay: true, muted: false });

// Create and append the video element with controls to the DOM
const video = appendVideoElement("manifest-player");

// Attach the player to the video element
// This connects the player's media stream to the video tag for display
player.attachTo(video);

// Set up event handlers for playback controls (play, mute, volume)
attachPlayerClickHandlers(player, "manifest-player");

// Register cleanup handler for when the page is hidden
document.addEventListener("visibilitychange", dispose);
}

/**
* Clean Up Player Resources
*
* Disposes of the player and removes event listeners when the page is hidden.
* This should be called to:
* - Release video resources
* - Stop network connections
* - Free up memory
*
* Important: Always dispose of player resources when done to prevent:
* - Memory leaks
* - Continued network usage
* - Background playback when page is not visible
*
* This function is triggered automatically by the visibilitychange event
* when the user navigates away or hides the page.
*/
function dispose() {
if (document.hidden) {
// Dispose of the player (stops playback and releases resources)
player?.dispose();
player = null;

// Remove event handlers from control elements
removePlayerClickHandlers("manifest-player");

// Remove the visibility change listener
document.removeEventListener("visibilitychange", dispose);
}
}

/**
* Application Entry Point
*
* This runs when the page finishes loading. It calls init() to set up
* the player and start playback.
*/
window.onload = async () => {
await init();
};

Key Concepts​

Player​

The Player instance manages video playback:

  • Loads and parses manifest files
  • Handles adaptive bitrate streaming (automatically switches quality based on network conditions)
  • Provides playback control methods (play(), pause(), mute(), unmute())
  • Manages audio and video state

Manifest URL​

A manifest file contains information about available video streams:

  • HLS (.m3u8): Apple's HTTP Live Streaming format, widely supported
  • DASH (.mpd): MPEG-DASH format, ISO standard for adaptive streaming
  • FLV (.flv): Flash Video format, used for low-latency streaming
  • JSON: Native Frame's multi-format manifest containing all available options

Adaptive Bitrate Streaming​

The player automatically adjusts video quality based on:

  • Available bandwidth
  • Device capabilities
  • Buffer health
  • Network conditions

This ensures smooth playback with minimal buffering.

Player Properties​

Key properties for controlling playback:

  • localVideoPaused: Check if video is paused
  • localAudioMuted: Check if audio is muted
  • localAudioVolume: Get/set volume (0-1 range)

Manifest Player vs WebRTC Player​

FeatureManifest PlayerWebRTC Player
ConnectionHLS/FLV/DASH URLsDirect to live calls
AuthenticationNone for a public manifest; a private stream passes auth: authClient (contexts manifest / manifest-headers)Required
Adaptive BitrateSupportedN/A
LatencyHigher (3-30 seconds)Ultra-low (sub-second)
Best ForVOD, CDN-delivered contentReal-time interaction

A public manifest plays with no credential. For a private stream, pass auth: authClient in the requestPlayer options — the auth client attaches your token to the manifest request (manifest context) or to its request headers (manifest-headers context), and the same option covers the WebRTC driver. See Private Viewer for the full pattern.

Next Steps​

To learn more about the video-client-core library and advanced features: