Skip to content

Advanced Embed

If you need full control over your media embed then you can use our embed library. You get full access to our setup options listed below and can use them to create a custom player that fits your needs.

Embed Library

The primary way of using the player is via installing the package from NPM. You can install the package using the following command:

Terminal window
npm install @mediamanager.io/embed

And then in your component:

import @mediamanager.io/embed

Otherwise you can link to the assets directly from the CDN:

<script type="module" src="https://embedv3.mediamanager.io/player.js"></script>

Basic Usage

You can create a player by using the media-manager-player element. The bare minimum require is to provide a media token which can be found on the media page.

<div>
<media-manager-player
token="107ad830-768b-4724-8649-607e2965f9d4"
></media-manager-player>
</div>

Basic use (React)

If you are using React you can use the following code to create a player. Please note that you will need to ensure player is only loaded once the component has mounted on the client.

"use client";
import React, { useEffect } from "react";
export default function Home() {
useEffect(() => {
import("@mediamanager.io/embed");
});
return (
<div>
<media-manager-player token="66f56f08-18d3-4cd0-9cff-967bbe8ca6b7"></media-manager-player>
</div>
);
}

Setup Options

If you want more control over your player you can use the included setup options to customise the appearance or behavior. Below are the full list of options and their default values.

They can be added to the element as you would any other attribute:

<div>
<media-manager-player
token="107ad830-768b-4724-8649-607e2965f9d4"
canFloat="false"
showControls="false"
></media-manager-player>
</div>
OptionType and Default ValueNotes
tokenstring, noneThe only required option. Your media token.
islikeliveboolean, falseChanges the player appearance and behavior to simulate a live broadcast.
showcontrolsboolean, trueWhether to display the video controls (control bar and display icons).
showdescriptionboolean, trueWhether to display the description of your video inside your player.
showbrandlogoboolean, trueWhether to display your brand logo in the player control bar.
showpictureinpicturecontrolsboolean, trueAdds a Picture in Picture icon and right click menu options to supported desktop browsers only.
showplaybackratecontrolsboolean, trueWhether to display a settings menu to adjust playback speed.
showsharingbuttonsboolean, falseWhen true displays a share button on the player for Twitter, Facebook, LinkedIn and Email.
showtitleboolean, trueWhether to display the title of your video inside your player.
shouldautostartboolean, falseWhether the player will attempt to begin playback automatically when a page is loaded.
isdownloadableboolean, trueWhen true will respect the download status of a video and show a download icon if enabled. Can be set to false to ignore the parent video records state.
canbecastboolean, trueCasting enables a viewer to use Google Cast or Apple AirPlay technologies to stream video and audio content to a compatible TV or sound system. By enabling the casting feature for a player, a viewer can tap an icon in the control bar to stream your content on a cast-compatible device. If no compatible device is detected by the player, no cast icon appears.
canfloatboolean, trueKeeps the player visible when the original player location is scrolled out of view by minimizing it to a corner of the screen. On devices in portrait orientation, the player becomes fixed to the top of the page using its original dimensions. When floating, the viewer can drag the player to reposition it.
ismutedboolean, falseConfigures if the player should be initially muted during playback.
skiprecapboolean, trueWhether to display the skip recap buttons if configured on the video.
skipintroboolean, trueWhether to display the skip intro buttons if configured on the video.
skiptonumber, 0The number of seconds at which to start video playback
aspectratiostring, 16/9Maintains proportions when width is a percentage. Will not be used if the player is a static size.
heightstring, noneThe desired height of your video player (in pixels). Should be omitted when aspectRatio is configured.
widthstring, 100%The desired width of your video player (in pixels or percentage).
overridedescriptionstring, nonePass a string to override the video description as configured within Media Manager. Can be used in conjunction with displayDescription to display a custom video description.
overridetitlestring, nonePass a string to override the video title as configured within Media Manager. Can be used in conjunction with displayTitle to display a custom video title.
overridethumbnailstring, nonePass a URL of a publicly accessible image as a string to override the video thumbnail as configured within Media Manager.
custombuttonimagestring, noneSet a custom image for the button
custombuttontitlestring, noneSet the button title, will override the value in Media Manager.
custombuttonurlstring, noneSet the button URL, will override the value in Media Manager.
showcustombuttonstring, trueIf you have provided a custom button but need to manually override it, use this option.

Example Video Embed with Options

<div>
<media-manager-player
token="d0e2f9d8-27ba-4823-99e0-8f6651d25b31"
showcontrols="true"
canfloat="true"
></media-manager-player>
</div>

Player Events

The player will emit events that you can listen to and respond to. These events are emitted on the player element and can be listened to using the addEventListener method.

const mediaManagerPlayer = document.querySelector("media-manager-player");
// listen to an event from the component
mediaManagerPlayer?.addEventListener("timeupdate", (time) => {
console.log("timer update", time.timeStamp);
});

If you have multiple players on the page you can do either of these:

  1. Pass an id to the player and use getElementById or similar.
<media-manager-player id="my-player-id"></media-manager-player>
<script>
const player = document.getElementById("my-player-id");
</script>
  1. Use the token attribute directly
<media-manager-player
token="107ad830-768b-4724-8649-607e2965f9d4"
></media-manager-player>
<script>
const player = document.querySelector(
'media-manager-player[token="107ad830-768b-4724-8649-607e2965f9d4"]',
);
</script>

Available Events

Version 3 of the MediaManager player is a wrapper of media-chrome and mux-video, which itself is an augmentation of the HTML <video> element. As such, it emits all the events that the <video> element does.

const mediaElementEvents = [
"abort",
"canplay",
"canplaythrough",
"durationchange",
"emptied",
"ended",
"error",
"loadeddata",
"loadedmetadata",
"loadstart",
"pause",
"play",
"playing",
"progress",
"ratechange",
"seeked",
"seeking",
"stalled",
"suspend",
"timeupdate",
"volumechange",
"waiting",
];
mediaElementEvents.forEach((event) => {
mediaManagerPlayer.addEventListener(event, (event) => {
console.log(event.type);
});
});

Direct Player Interaction

It is also possible to directly interact with the player. In the example below we are adding our own button outside the player which will play/pause the media when clicked.

<button id="embed-control" type="button">Play/Pause</button>
<script>
document.addEventListener('DOMContentLoaded', () => {
const playPauseButton = document.getElementById(
"embed-control-playpause",
);
playPauseButton.addEventListener("click", function () {
const isPaused = mediaManagerPlayer.shadowRoot
.querySelector("media-controller")
.hasAttribute("mediapaused");
if (isPaused) {
mediaManagerPlayer.dispatchEvent(new CustomEvent("play"));
}
if (!isPaused) {
mediaManagerPlayer.dispatchEvent(new CustomEvent("pause"));
}
});
});
</script>
</div>

Available events you can hook into are listed below

OptionNotes
playplays the video
pausepauses the video
muteturns sound off
seekseeks to a different part of the video, see example below
getchapterssends an event which, if the video has chapters, will return the chapters in the chaptersupdated event. See example below.

Seek Example

mediaManagerPlayer.dispatchEvent(
new CustomEvent("seek", { detail: { timestamp: 300 } }),
);

Get chapters example

const getChaptersButton = document.querySelector("button.get-chapters");
getChaptersButton.addEventListener("click", function () {
mediaManagerPlayer.dispatchEvent(new CustomEvent("getchapters"));
});
mediaManagerPlayer.addEventListener("chaptersupdated", (event) => {
console.log(event.detail); // will return the chapters if they exist
});

Getting the duration of play

To get the duration of play, you can get this from the mediatime attribute:

mediaManagerPlayer.getAttribute("mediatime");

Create a button using the <slot> element

You can also use the <slot> element to create a button inside the player instead of using the options.

<media-manager-player>
<button slot="about-button">Click me</button>
</media-manager-player>