Mux Player Rendering
View the MUX documentation regarding their video player component. It will describe where to get access to the player either by CDN or including via NPM along with all the params and events.
Mux assets have a public or a signed playback ID (or, rarely, both). Signed playback IDs need a token on every request. The examples below cover each case; Signed Playback explains the concepts.
Any Video (Recommended)
This one template plays public and signed videos. For a public playback ID, getPlaybackToken() returns null, so the token attributes are left out.
{% set video = entry.video.one() %}
{% if video and video.getPlaybackId() %}
{% set playbackToken = video.getPlaybackToken('v') %}
{% set thumbnailToken = video.isAudioOnly ? null : video.getPlaybackToken('t', {time: 2}) %}
{% set storyboardToken = video.isAudioOnly ? null : video.getPlaybackToken('s') %}
{% if video.securePlayback and not playbackToken %}
{# Signed video but no signing key exists: the player would get a 403 #}
<p>This video is not available right now.</p>
{% else %}
<mux-player
stream-type="on-demand"
primary-color="#ffffff"
metadata-video-id="{{ video.asset_id }}"
metadata-video-title="{{ video.title }}"
playback-id="{{ video.getPlaybackId() }}"
{% if playbackToken %}playback-token="{{ playbackToken }}"{% endif %}
{% if thumbnailToken %}thumbnail-token="{{ thumbnailToken }}"{% endif %}
{% if storyboardToken %}storyboard-token="{{ storyboardToken }}"{% endif %}
></mux-player>
{% endif %}
{% endif %}getPlaybackId()returnsnullwhile the asset is still processing or if it errored, so check it first.<mux-player>needs three tokens for a signed video:playback-tokenfor the stream,thumbnail-tokenfor the poster andstoryboard-tokenfor timeline hover previews. Without the last two, the video plays but the poster and previews fail with403.- Thumbnail modifiers such as
timego into the thumbnail token. The player can't add them to a signed URL itself.
Public Video
No tokens are needed. Only use this for public playback IDs: a signed video rendered this way fails with 403.
{% set video = craft.mux.one() %}
{% if video and video.getPlaybackId() %}
<mux-player
stream-type="on-demand"
playback-id="{{ video.getPlaybackId() }}"
metadata-video-title="{{ video.title }}"
></mux-player>
{% endif %}Signed Video
This assumes you have created a key under Mux → Signed Keys.
{% set video = craft.mux.one() %}
{% if video and video.securePlayback and video.hasSigningKey() %}
<mux-player
stream-type="on-demand"
playback-id="{{ video.getPlaybackId() }}"
playback-token="{{ video.getPlaybackToken('v') }}"
thumbnail-token="{{ video.getPlaybackToken('t') }}"
storyboard-token="{{ video.getPlaybackToken('s') }}"
></mux-player>
{% endif %}Token Options
getPlaybackToken(type, modifiers, expiresIn, policy, keyId). Every argument is optional.
| Argument | Default | Description |
|---|---|---|
type | 'v' | v video, t thumbnail, g gif, s storyboard |
modifiers | {} | Modifiers for that token type, e.g. {time: 2, width: 1280} or {max_resolution: '720p'}. See Modifiers. |
expiresIn | signedTokenLifetime (24 hours) | Minimum lifetime in seconds, capped at maxSignedTokenLifetime |
policy | first playback ID | 'signed' or 'public', to choose a playback ID when the asset has both |
keyId | oldest signing key | ID of a specific key from Mux → Signed Keys |
{# Cap the stream at 720p, valid for at least 6 hours #}
{{ video.getPlaybackToken('v', {max_resolution: '720p'}, 21600) }}
{# Poster from 5 seconds in, 1280 wide #}
{{ video.getPlaybackToken('t', {time: 5, width: 1280}) }}
{# Enforce a specific playback restriction #}
{{ video.getPlaybackToken('v', {playback_restriction_id: 'abc123'}) }}
{# Skip the default restriction for this token #}
{{ video.getPlaybackToken('v', {playback_restriction_id: ''}) }}The default restriction (Mux → Settings → Default Playback Restriction ID) is added automatically; you only pass playback_restriction_id for exceptions. See Playback Restrictions → Twig, which includes a reusable player partial.
Asset with Public and Signed Playback IDs
Pass policy to choose one. Without it, the first playback ID is used.
{# Prefer the public ID; fall back to the signed ID with tokens #}
{% set policy = video.getPlaybackId('public') ? 'public' : 'signed' %}
<mux-player
playback-id="{{ video.getPlaybackId(policy) }}"
{% if policy == 'signed' %}
playback-token="{{ video.getPlaybackToken('v', {}, null, 'signed') }}"
thumbnail-token="{{ video.getPlaybackToken('t', {}, null, 'signed') }}"
storyboard-token="{{ video.getPlaybackToken('s', {}, null, 'signed') }}"
{% endif %}
></mux-player>WARNING
If an asset has a public playback ID, anyone with that ID can watch the full video. See An asset can have both.
Audio-Only Assets
The same player works for audio (video.isAudioOnly). Only a v token is needed: there are no thumbnails or storyboards for audio, so skip those tokens. For videos, use Any Video instead, which adds them.
<mux-player
stream-type="on-demand"
audio
playback-id="{{ video.getPlaybackId() }}"
{% if video.securePlayback %}playback-token="{{ video.getPlaybackToken('v') }}"{% endif %}
></mux-player>Images, Downloads and Captions
These helpers return a ready-to-use URL: signed (?token=…) for signed playback IDs, plain with query parameters for public ones. Each one returns null if the asset has no playback ID, or if it's signed and no signing key exists.
{# Still thumbnail #}
<img src="{{ video.getThumbnailUrl({width: 640, height: 360, fit_mode: 'smartcrop', time: 2}) }}" alt="">
{# Animated preview #}
<img src="{{ video.getAnimatedUrl({width: 320, start: 0, end: 4}) }}" alt="">
{# HLS stream for a custom player, capped at 720p #}
{{ video.getStreamUrl({max_resolution: '720p'}) }}
{# Timeline storyboard #}
{{ video.getStoryboardUrl() }}
{# Captions: one link per text track #}
{% for track in video.tracks|filter(t => t.type == 'text') %}
<track kind="subtitles" srclang="{{ track.language_code }}" label="{{ track.name }}" src="{{ video.getTextTrackUrl(track.id) }}">
{% endfor %}
{# MP4 / M4A download #}
{% for file in video.static_renditions.files ?? [] %}
<a href="{{ video.getStaticRenditionUrl(file.name, video.title ~ '.' ~ file.ext) }}">Download ({{ file.resolution ?? file.name }})</a>
{% endfor %}See Element Properties → Signed Playback Methods for every argument.
Legacy Templates
Templates written for earlier versions keep working:
{% set key = craft.signedKeys.one() %}
{% set videoToken = muxAsset.getSecurePlaybackJWT(key.key_id) %}
{% set thumbToken = muxAsset.getSecurePlaybackJWT(key.key_id, 't') %}
{% set storyboardToken = muxAsset.getSecurePlaybackJWT(key.key_id, 's') %}getSecurePlaybackJWT() now puts its options into the token (they were dropped before 2.8.0), and the key ID is optional. For new templates, use getPlaybackToken() and the URL helpers above. They don't need the key, and they work for public and signed playback IDs.
Craft Variable Helpers
These methods are available on the craft variable (via MuxAssetBehavior) and return rendition metadata useful for building custom download UIs or forms.
muxRenditionOptions()
Returns all available rendition options as an associative array of value => label pairs, ordered for display (Highest first, Audio Only last).
{% set options = craft.muxRenditionOptions() %}
{# Returns: {'highest': 'Highest', '2160p': '2160p', ..., 'audio-only': 'Audio Only'} #}
{% for value, label in options %}
<option value="{{ value }}">{{ label }}</option>
{% endfor %}muxSpecificResolutions()
Returns an array of the specific resolution values (excludes highest and audio-only). Useful for enforcing mutual-exclusivity rules in front-end UI — these values cannot be combined with highest.
{% set specific = craft.muxSpecificResolutions() %}
{# Returns: ['2160p', '1440p', '1080p', '720p', '540p', '480p', '360p', '270p'] #}Signed Keys Deprecated
You no longer need to look up a signing key in templates: getPlaybackToken() and the URL helpers use the oldest key under Mux → Signed Keys automatically, or the key you pass as keyId.
craft.signedKeys, muxAsset.signedKeys and muxAsset.securePlaybackTokens still work but return the full key records, including private keys. Never output them in a page.
To check whether a signed video can be played, use hasSigningKey():
{% if muxAsset.securePlayback and not muxAsset.hasSigningKey() %}
{# Create a key under Mux → Signed Keys #}
{% endif %}