Complete reference for all engine events via the onEvent prop.
Overview
MP4E Player uses a single onEvent prop to deliver all engine events. This provides a clean, unified API for integrating with analytics, syncing external UI, or building custom behaviors.
Player is ready for playback. Video metadata is loaded.
playback:loaded
{ duration: number }
-
Video loaded and duration is available.
metadata:loaded
MetadataView
-
The interactive document is loaded and the engine is initialized. Carries the document view, not the document itself: schemaVersion, videoDetails (fps, width, height, durationSeconds), layers (id, name, order and their overlays — each overlay with id, layerId, type, name, overlayCategory, position, size, config, opacity, zIndex), audioTracks, media, thumbnails, objectCount, timeline.mode ("chunked" when the file streams its object tracking — see the timeline:* events — else "full"). Your overrides are already merged in. Objects, variables, rules, scenes and plugins are not part of the view.
Per-stage load timing, emitted once per load after the engine has finished its load work. totalMs is when the player finished its own startup; settledMs is when the engine had finished all of it (null if unknown). Stages: extract, engineLoad, decrypt, jsonParse, setMetadata, diagnostics, bootstrapTick, uiInit — null when a stage did not run. For a document embedded in the file, decrypt covers the whole load (verify, decrypt, parse and apply) and setMetadata is null; for a document you pass as metadata (or one generated for a plain video), setMetadata covers it, including serializing the document, and decrypt is null. jsonParse is always null. setMetadata, decrypt and diagnostics time completed work in both modes.
timeline:entryReady
{ msSinceStart: number }
-
Streamed timeline only (a file exported with streamTimeline): object tracking for the frames at the playhead is loaded, so objects and object-bound overlays can show. Fires once per load, and again after a metadata reload or overrides change (tracking already loaded is kept across an overrides change, so the event can follow without any new fetch). msSinceStart is measured from the start of the chunk fetching; it can arrive before or after metadata:loaded.
Streamed timeline only: after each chunk of object tracking is loaded. covered lists the frame ranges now loaded ([start, end), frames), inFlight the chunks still being fetched, playheadCovered whether the current frame is loaded. The player fetches the chunk at the playhead first (again after every seek), then the chunks ahead of playback.
Streamed timeline only: a chunk of object tracking could not be fetched or used after four attempts, or the server ignores HTTP range requests (then no further chunks are fetched). Playback continues; objects in the frames that chunk covers stay hidden. With enableBlobCache, once the whole file is downloaded the player reads every chunk from it instead, including the failed ones (but not an unsupportedEncoding one). reason is "unsupportedEncoding" when the file stores that chunk in a format this player is too old to read: the player never downloads such a chunk and reports it once per load, right after loading; a newer player reads it.
timeline:inlineChunkFailed
{ error: string }
-
Streamed timeline only: the chunk of object tracking carried inside the file for the first frames could not be used. Playback continues; the player fetches that chunk from the file like the others, and object geometry for those frames appears once it arrives.
{ reason: 'singleMediaElement'; currentTrackId: string | null; time: number }
-
This device will not play the video's alternate audio tracks, so the original audio keeps playing. Fires once. The player's menu then offers subtitles only. Selecting an audio track moves subtitles that are already on to its linked language and never turns them on. A picker of your own should offer subtitles too.
Fires once per init(), when the overlay reveal gate opens and overlays become visible. If none of the four reasons arrive (a source that never decodes and never errors), no event fires until the viewer starts playback. decoded is true for "ready"/"loadeddata" (an actual decoded pixel) and false for "error"/"play" (msSinceInit is just a reveal time) — drop decoded: false samples from time-to-first-pixel metrics.
playback:timeUpdate fires frequently during playback (~60fps). For performance-sensitive operations, consider debouncing or filtering by event name early.
22 console.log('First time seeing:', data.objectLabel);
23 break;
24 }
25 }}
26/>
Object Visibility
object:visible and object:hidden fire when objects enter/leave the video frame based on AI tracking data. Use these for product impression tracking. An object shown inside an image or a video that a replacement zone draws can appear in several zones at once: its object:click and object:hover carry the object as objectId and the appearance as instanceId.
A plugin sent a custom event with mp4e.emit(event, data). pluginId is the sending instance.
plugin:<namespace>:<identifier>:<event>
any
-
The same event under its own name, with the plugin's data as the payload — e.g. plugin:mp4e:search:search:selected.
plugin:init
{ pluginId: string }
-
Plugin iframe initialized.
overlay:presenceChanged
{ overlayIds: string[] }
-
The set of overlays with a live plugin iframe changed — one appeared, was released, or was shown/hidden by the engine — or the size or shown part of a content-sized overlay changed (same payload).
26 // The viewer jumped to an in-video search result: { query?, kind, time }
27 analytics.track('video_search', data.data);
28 }
29 break;
30 }
31 }}
32/>
Plugin Events
Plugins send custom events with mp4e.emit(eventName, data). Each reaches onEvent twice: as plugin:emit with { event, data, pluginId } (pluginId is the sending instance), and under its own name plugin:<namespace>:<identifier>:<eventName> with the data alone — e.g. plugin:mp4e:search:search:selected. This holds for every plugin kind, service plugins included.
While a playback path is active, controls and the progress bar operate in presentation time (position within the path) rather than media time. Authored rules and other plugins keep seeing ordinary media time via currentTime.
Ad Break Events
Fired for every ad break (interstitial), whoever requested it — your page (requestInterstitial), a plugin such as Linear ads, or the video's rules. While a break runs the video waits at its position; a play, pause or seek asked for meanwhile is refused with action:blocked, reason interstitial.
Prop
Type
Default
Description
interstitial:refused
{ reason: string; placement: string | null }
-
A break request was refused. reason: invalid, busy, depth, disabled, initiator, source, placement, template, window, spacing or cap. placement is null for an invalid spec.
interstitial:started
{ breakId: string; placement: string }
-
The break is playing.
interstitial:progress
{ breakId: string; event: string; atSeconds?: number }
-
The ad reached start, firstQuartile, midpoint, thirdQuartile or complete, was skipped (event skip, with atSeconds), or the viewer paused, resumed, muted or unmuted it (pause, resume, mute, unmute).
interstitial:clicked
{ breakId: string }
-
The viewer clicked through.
interstitial:engaged
{ breakId: string; placement: string }
-
The viewer interacted with the ad (the ad's plugin reported it). Once per break; from then on nothing returns the video by itself — the hold has no deadline and a paused ad is not cut off — until the viewer continues or skips, your page calls cancelInterstitial(), or — for a break without a hold — the ad ends.
interstitial:holding
{ breakId: string; placement: string }
-
The ad ended and the break waits on its last frame (a break with hold).
The viewer did something in the ad (orderPlaced, formSubmitted, remindLater, productSaved or clicked), with fixed fields only; declared is what was passed when the break was requested.
The video is back. reason: completed, skipped, returned, maxSeconds, cancelled or error. returned means the ad's card sent the viewer back to the video (after they engaged, or ending the hold with a label); label is the card's own reason, present only then. durationWatched is in seconds. outcomes lists the outcome types the break reported, in order, each once.
Fired when the viewer picks a menu item a plugin contributed at runtime via mp4e.setMenuItems(). What the pick does is the plugin's business — the engine resolves it and hands it back; hosts observe it via onEvent, plugins via mp4e.on('menu:select', …) (delivered only to the contributing plugin). Dismissing the menu afterwards is handled internally between the engine and the controls plugin; no event for it reaches onEvent.
Use the variable:changed event to sync video state with your application. For example, update a cart UI when a "cartTotal" variable changes. Each payload includes an initiator describing what caused the change — see Event Provenance below. A variable that holds embedded media carries its portable media://<id> reference as its value, not a blob URL; resolve it with resolveMediaUrl(url, videoUrl, loadedMedia) from @mp4e/player (also exported by @mp4e/react).
Action events use the action: prefix followed by the action type (e.g. action:seek, action:setVariable). Listen for specific action types or use event.startsWith('action:') to catch all actions. Every executed action also emits after:{actionType} with the fully resolved action payload and its initiator — see Event Provenance below.
Error Events
Prop
Type
Default
Description
state:error
string | null
-
General engine error occurred.
metadata:error
{ message: string }
-
Metadata-specific error.
plugin:error
{ pluginId: string; error: string }
-
Plugin error (non-fatal).
Error events
1<MP4EPlayer
2 src="/video.mp4"
3 onEvent={(event, data) => {
4 switch (event) {
5 case 'state:error':
6 if (data) {
7 console.error('Engine error:', data);
8 errorReporter.capture({ code: 'ENGINE_ERROR', message: data });
Object/overlay display is shown. box is the card's size and placement its top-left and size, in video pixels, when the player sized or placed the card itself. Showing a display that is already open shows it again.
A display closed: its object left the screen, an automatic card closed, hideObjectDisplay was called, or the viewer closed it (its close button, a tap outside it, the pointer leaving it, its timeout). One event per display.
Displays are dynamic UI elements (tooltips, product cards) that appear in response to object interactions. They differ from overlays, which are positioned on the video. A single overlay can trigger different displays based on hover vs click events.
Dialog Events
Dialog events fire when the engine presents or dismisses a dialog (alert, confirm, prompt, or custom modal).
The blob cache transitions through states: idle → downloading (with progress 0-1) → swapping → cached. If the file exceeds the size limit, the state will be skipped. Errors are reported as error.
Remote Navigation Events
Fired when the viewer presses Back on a remote or keyboard and nothing in the player is left to close. Turn navigation on with config.remoteNavigation; see Remote Control Navigation on the Host Configuration page.
Prop
Type
Default
Description
remote:back
undefined
-
Back was pressed with no card, modal or panel open and nothing focused: the player has nothing left to give up, so it is your page's turn (return to a menu, leave the screen). Not fired while navigation is off. During an ad break it fires when the viewer presses Back in the ad.
Tracking Events
Tracking events fire when tracking visualizations (polygons, bounding boxes, mesh, corners) are shown or hidden at runtime.
Available tracking modes include polygon, bbox, corners, mesh, meshUV, amodal, and all. Tracking can target a specific object, a group, or all objects.
Overlay Interactions
When the viewer clicks, points at or double-clicks an overlay, onEvent receives one of these, after the video's own handlers for it have run:
A double-click in the overlay. Two overlay:click events arrive before it.
Hotspots of a group-bound overlay. An overlay bound to an object group is drawn once per object of the group. A click, hover or double-click on one of those instances carries the object as objectId and the instance as instanceId. A click or hover then also arrives as object:click / object:hover_enter / object:hover_leave for that object, right after the overlay's event: the overlay's own handlers run with that object, and so do the object's and its groups'. A double-click on an instance sends no object event.
A double-click also sends two clicks. As in the browser, overlay:dblclick follows two overlay:click events (on a hotspot instance, two object:click too). Handle both only when that is what you want.
Every hover ends. When the overlay, hotspot instance or object under the pointer stops showing (its range ends, a rule hides it, its object leaves the picture), the player ends the hover itself: the …:hover_leave event arrives with the data of its …:hover_enter, and no second leave follows when the pointer moves away.
Blocked objects. While a replacement zone with Block clicks covers an object, clicks and hovers on the object and on the overlays bound to it are refused, and none of these events is sent for them.
Focus and keys stay inside the video
An overlay's focus, blur and key handlers run when remote-control navigation moves into the overlay. They are not sent to onEvent.
Streamed Loading
A video exported with Stream interactive data (faster start on long videos) loads its object tracking while it plays, instead of all at once before it starts. metadata:loaded reports such a file with timeline.mode: 'chunked'. What your application can rely on:
Player version
Streamed files need @mp4e/react 1.5.0 or later (@mp4e/player 2.5.0 or later). Older players block playback of a streamed file, or play it without its object tracking. Exports stream by default, so upgrade the player before serving files exported from the Studio or the API.
The video can start before all of its object tracking has loaded.
Tracking arrives in pieces, starting at the playhead (again after every seek), then the stretch just ahead of playback. timeline:coverage reports each piece.
A frame whose tracking has not arrived yet shows no object geometry: its objects stay hidden until it loads. Nothing is guessed.
timeline:entryReady says the current position is covered, so objects at the playhead can show. It fires once per load, not after seeks; each timeline:coverage carries playheadCovered for the current frame.
With the overrides prop, tracking already loaded is kept across override changes; nothing is fetched again.
Following streamed loading
1<MP4EPlayer
2 src="/streamed-video.mp4"
3 onEvent={(event, data) => {
4 switch (event) {
5 case 'timeline:entryReady':
6 console.log('Tracking at the playhead loaded after', data.msSinceStart, 'ms');
13 console.warn('Some object tracking could not be loaded:', data.error);
14 break;
15 }
16 }}
17/>
Metadata Diagnostics
The engine reports every problem it hits or silently skips in the document it just loaded. The metadata:diagnostics event carries those findings as { findings, source }. It fires after each load that produced at least one finding — source: 'set' for the initial load or setMetadata, source: 'update' on the soft-reload path taken by reloadMetadata or an overrides change (an uninitialised or destroyed engine falls through to a full reinit and reports 'set' instead). A clean document emits nothing. The player also logs the same findings in one collapsed console group on every load that produces findings.
Diagnostics depend on the engine that is actually running. Against an older engine — a video carrying an embedded engine that predates them, say — the player skips the per-load read entirely and stays silent: no event, no log. playerRef.diagnose(metadata) is an explicit call, so it rejects when the engine cannot answer rather than returning an empty array, which would read as “this document is clean”.
Finding shape
Prop
Type
Default
Description
severity
'error' | 'warning' | 'info'
-
error = this part of the document cannot work as written; the engine drops or skips it (a dangling reference, an unparseable condition or variable, missing required plugin config, an inverted frame range). warning = it runs, but probably not as intended, or the engine cannot verify it (an action type no plugin declares, a config value whose type contradicts the schema, a timer target its direction never reaches). info = an observation, no defect (a rule with no actions, a keyframe outside the visible window that still acts as a hold value).
code
string
-
Namespaced, stable identifier for the kind of finding — parse.*, ref.*, type.*, range.*, structure.*, plugin.config.*, template.*, zone.*. Match on this, not on the message. New codes are added over time; existing codes are never renamed or re-meant.
path
string
-
Dotted path to the offending value in the metadata document, with numeric array indexes (e.g. layers.2.overlays.0.onClick.1.sceneId). Stable, and part of the contract alongside code.
message
string
-
Human-readable English explanation of what the engine does with this part of the document. Written for people and may change — never parse it.
entity
{ kind: string; id: string }
-
The nearest owning entity, when there is one — scene, sceneGroup, layer, overlay, variable, rule, objectGroup, or menuItem (the owner of a playerMenuConfig.customItems entry). Omitted for document-level findings.
related
{ kind: string; id: string }[]
-
Other entities the finding refers to, such as the missing target of a dangling reference.
suggestions
string[]
-
Concrete replacements the author probably meant: the closest existing ids for a dangling reference, the permitted values for a bad enum, the known types for an unknown type string. Omitted when nothing sensible exists.
Replacement zones are checked too (a warning):
zone.look.noContent — the zone has lookEnabled on but draws no image or video (a colour, blur or chroma zone), so the look has no effect.
Reacting to diagnostics
1<MP4EPlayer
2 src="/video.mp4"
3 onEvent={(event, data) => {
4 if (event !== 'metadata:diagnostics') return;
5
6 // data.source: 'set' on the initial load, 'update' after a reload or overrides change
12 f.suggestions?.length ? 'did you mean ' + f.suggestions[0] + '?' : '');
13 }
14 }}
15/>
Findings never block playback
Diagnostics are read-only: the engine reports what it would ignore, and plays the video either way. Use them in your own developer tooling — decide for yourself whether an error is worth surfacing to viewers. To check a document before applying it, call playerRef.diagnose(metadata), which returns the same findings without touching player state.
Event Provenance
Action and state events carry an initiator object describing what caused them — the viewer, a metadata rule (and which one), a plugin, your host application, or engine automation. It is present on after:* and action:* payloads, on variable:changed, and on scene transition events. This turns a bare “paused” into “paused by rule quiz_gate when the viewer clicked the quiz overlay” — the difference between playback logging and behavioral analytics.
What caused the action or change. user = direct viewer input (controls, key bindings, menu). rule = a metadata rule fired. plugin = a plugin API call. host = your application called a player method. init = metadata load / variable defaults. system = engine automation (timers, sequences, scene transitions).
id
string
-
The specific source when one exists: the rule ID, plugin ID, or input-binding ID.
event
string
-
For rule initiators, the event that fired the rule (e.g. overlay:click:btn-buy, control:pause).
via
string
-
Qualifier for how it happened: controls, inputBinding, menu, timer, sequence, sceneTransition, gateTimeout, emitEvent, setMetadata.
Attributing playback and state changes
1<MP4EPlayer
2 src="/video.mp4"
3 onEvent={(event, data) => {
4 // Playback attribution: was this pause the viewer, a rule, or a plugin?
5 if (event === 'after:pause') {
6 switch (data.initiator?.type) {
7 case 'user': console.log('Viewer paused'); break;
8 case 'rule': console.log('Paused by rule', data.initiator.id,
9 'on', data.initiator.event); break;
10 case 'plugin': console.log('Paused by plugin', data.initiator.id); break;
11 case 'host': console.log('Paused by your app'); break;
12 }
13 }
14 // Variable provenance: ignore initialization, keep real viewer choices
15 if (event === 'variable:changed' && data.initiator?.type !== 'init') {
16 analytics.track('choice', {
17 variable: data.variableName,
18 value: data.newValue,
19 causedBy: data.initiator?.type,
20 });
21 }
22 }}
23/>
Closed vocabulary
The initiator type is a closed enum — safe to group by in analytics dashboards. Fields that do not apply are omitted rather than null, so check with optional chaining.
Advanced
Wildcard Subscription
The onEvent prop acts as a wildcard subscriber — it receives every event emitted by the engine. The first parameter (event) contains the event name as a string, and the second parameter (data) contains the event payload. This makes it easy to forward all events to an analytics or logging system without listing individual event types.
Wildcard event subscription
1import { MP4EPlayer } from '@mp4e/react';
2
3// Subscribe to ALL events using onEvent
4<MP4EPlayer
5 src="/video.mp4"
6 onEvent={(event, data) => {
7 // 'event' contains the event name (e.g. 'playback:ready')
8 // 'data' contains the event payload
9 console.log(`[${event}]`, data);
10
11 // Forward all events to your analytics or logging system
12 analytics.track('mp4e_event', {
13 eventName: event,
14 payload: data,
15 timestamp: Date.now()
16 });
17 }}
18/>
Event Filtering
Since onEvent fires for every event, use event.startsWith() or a switch statement to filter for the categories you care about. For high-frequency events like playback:timeUpdate, consider early returns to avoid unnecessary processing.