Skip to content

Events and error handling

MKPlayer fires events throughout the player lifecycle — from setup through playback to teardown. You subscribe to events either in the player configuration or dynamically using player.on(). Errors arrive as a specific event type with a structured error object.

You can register event handlers in two ways.

In the player configuration (before the player is created):

const playerConfig = {
key: "YOUR_PLAYER_LICENSE_KEY",
events: {
[mkplayer.MKPlayerEvent.SourceLoaded]: (event) => {
console.log("Source loaded");
},
[mkplayer.MKPlayerEvent.Playing]: (event) => {
console.log("Playback started");
},
[mkplayer.MKPlayerEvent.Error]: (event) => {
console.error("Player error: ", event.code, event.message);
}
}
};

Dynamically at runtime using player.on():

player.on(mkplayer.MKPlayerEvent.Ready, (event) => {
console.log("Player is ready");
});
player.on(mkplayer.MKPlayerEvent.TimeChanged, (event) => {
console.log("Current time: ", event.time);
});

To remove a specific handler:

const handler = (event) => {
console.log("Playing");
};
player.on(mkplayer.MKPlayerEvent.Playing, handler);
// Remove this specific handler later
player.off(mkplayer.MKPlayerEvent.Playing, handler);

To remove all handlers for a given event type:

player.offAll(mkplayer.MKPlayerEvent.Playing);
EventFires when
ReadyThe player has enough data to start playback.
SourceLoadA new source load has been initiated.
SourceLoadedA source has finished loading.
SourceUnloadedThe current source has been unloaded.
PlayThe player enters the play state via a public API call or user interaction. Note: autoplay does not fire this event.
PlayingPlayback has actually started.
PausedThe player enters the paused state.
PlaybackFinishedPlayback of the current video has finished.
TimeChangedThe current playback time has changed.
StallStartedThe player has begun buffering due to an empty buffer.
StallEndedThe player has resumed after buffering.
DestroyThe player instance has been destroyed.
ErrorAn error has occurred during setup or playback.

See the MKPlayerEvent enum in the SDK reference for the full list of events.

All errors arrive on the Error event. The event object implements MKErrorEvent and includes:

PropertyTypeDescription
codestringA structured error code, for example "4-70-1103".
messagestringA human-readable description of the error.
namestringThe name of the error.
troubleShootLinkstringA link to a detailed troubleshooting guide, if available.
dataobjectAdditional error data, if available.
player.on(mkplayer.MKPlayerEvent.Error, (event) => {
console.error(`Error [${event.code}]: ${event.message}`);
if (event.troubleShootLink) {
console.info("Troubleshooting: ", event.troubleShootLink);
}
});
CodeConstantMeaning
4-70-1101PLAYER_SETUP_NO_HTML_ELEMENTThe container element passed to the player is not a valid HTMLElement. Check that the element exists in the DOM before creating the player.
4-70-1102PLAYER_SETUP_MISSING_CONFIGURATIONNo MKPlayerConfig was provided when creating the player instance.
4-70-1103PLAYER_SETUP_LICENSE_ERRORThe player key was not granted playback. Check that your license key is correct.
4-70-1104PLAYER_SETUP_MISSING_DOMAIN_LICENSE_ALLOWLISTThe player build is domain-locked and the current domain is not in the allowlist.
4-70-1105PLAYER_SETUP_MISSING_LICENSE_ALLOWLISTThe current domain has not been added to the license allowlist.
4-70-1113PLAYER_SETUP_UNSUPPORTED_PROTOCOLThe page was loaded using the file:// protocol. Host the page on a web server using http or https.
CodeConstantMeaning
4-71-1201PLAYER_SOURCE_INVALIDThe MKSourceConfig passed to player.load() is invalid. Ensure at least one valid stream URL is present.
4-71-1202PLAYER_SOURCE_MANIFEST_INVALIDThe downloaded manifest could not be parsed.
4-71-1208PLAYER_SOURCE_COULD_NOT_LOAD_MANIFESTThe manifest request failed after retries. By default, manifests are retried 2 times.
CodeConstantMeaning
4-73-1009PLAYER_GENERAL_NETWORK_ERRORThe device is not connected to the internet.
4-73-1401PLAYER_NETWORK_MANIFEST_DOWNLOAD_TIMEOUTThe manifest request timed out after the default 20-second timeout.
4-73-1402PLAYER_NETWORK_SEGMENT_DOWNLOAD_TIMEOUTA segment download timed out.

See DRM protection for the full list of DRM-specific error codes and guidance on resolving them.

© 2026 MediaKind. All rights reserved.