A few things people build with it:
- Collect and save quiz results and display aggregated response rates to viewers
- Build a shoppable video where tapping on products adds them to a shopping cart without interrupting the video experience — see how
- Survey viewers through an interactive video
How it works
The Realtime Player API is fully compatible with the popular Player.js library, so we recommend using it to listen for events and call methods on an Adventr player. The Adventr API extends the Player.js spec with additional events unique to interactive videos.
The Adventr player sends events via window.postMessage. You can add listeners for these manually, or for Player.js-compatible events, using the player.on() method.
choice
Fires when someone chooses a video or link in the Adventr player. The message sent to your window looks like:
{
"context": "adventr",
"version": "0.1",
"event": "choice",
"value": {
"type": "clip",
"id": "option2",
"label": "label string"
}
}Add a listener for that event:
window.addEventListener("message", (event) => {
let received;
try { received = JSON.parse(event.data); }
catch (e) { received = { event: event.data }; }
if (received.context === "adventr" && received.event === "choice") {
// do something cool with received.value
}
}, false);getCurrentClip()
Obtain details about the current clip and its possible choices.
const adventrPlayer = document.getElementById("adventrPlayer");
adventrPlayer.contentWindow.postMessage(JSON.stringify({
context: "adventr", version: "4.0.0", method: "getCurrentClip"
}), "*");choose(choiceID)
Select a currently available choice — the same as if the viewer had clicked or spoken it.
adventrPlayer.contentWindow.postMessage(JSON.stringify({
context: "adventr", version: "4.0.0", method: "choose", value: "overlay_1"
}), "*");getAllVariables()
Obtain the value of every variable in the Adventr. Handy for reading current values during playback if you’re using Smart Merge or Conditional / Change Variables.
[
{ "name": "var1", "type": "boolean", "value": true },
{ "name": "var2", "type": "number", "value": 12.2 }
]getVariable(variable_name)
Check a single variable by name.
{ "name": "var2", "type": "number", "value": 12.2 }Using Player.js for additional events and methods
The methods and events below can be used directly via window.postMessage, formatted to the Player.js spec — or more easily through the Player.js library itself.
<script src="//cdn.embed.ly/player-0.1.0.min.js"></script>
<iframe src="https://player.adventr.io/video?link=..." id="adventrPlayer"></iframe>
const player = new playerjs.Player("adventrPlayer");
player.on("ready", () => {
player.on("play", () => console.log("play"));
player.mute();
});Player.js methods
Player.js events
Fired when the media is ready to receive commands.
Fires while the media is loading additional content.
Fires periodically during playback.
Note: Adventr does not support the getLoop or setLoop methods from Player.js — these don’t apply to an interactive experience like Adventr.