Skip to main content

Using the hosted player

Using the hosted player

The AntCDN player can handle interactivity for you. It reads questions out of the video, opens the connection for answers, and draws the question overlay over the picture.

Turn it on

Add interactive=1 to the player URL:

<iframe
src="https://player.antcdn.net/v1/{edgeId}/master.m3u8?interactive=1"
allow="autoplay; fullscreen"
frameborder="0"
></iframe>

edgeId is the playback id returned when you create the stream. It is not the same as streamId, which you use on the API. The player resolves one to the other, so the embed only needs the edge id.

interactive=true works as well. Any other value, or leaving it out, keeps the player exactly as it is today. Nothing connects and no overlay is drawn.

ParameterValuesDefaultMeaning
interactive1, trueoffTurn interactivity on.
interactiveOverlay0, falseonTurn off the built in question overlay and draw your own.

What the overlay does

Questions stack up from the bottom left of the picture, newest nearest the bottom. Older questions move up, fade, and are removed. The overlay covers the lower half of the player at most, so it stays out of the way of the picture.

A viewer picks an option, or writes an answer if the question allows it. Results appear once they have answered, and again for everyone when the question closes. Results are deliberately hidden from a viewer who has not answered yet, because showing a running tally to someone still making up their mind turns a question into a poll of the majority.

A closed question shows its final result for a few seconds and then clears itself.

Listening from your page

The player runs in an iframe, so it reports what is happening to the page around it with postMessage. This uses the same channel the playback events already use.

Every message is a JSON string shaped like this:

{ "type": "player-ant", "event": "interactive:question", "detail": { } }
eventdetailSent when
interactive:questionThe questionPlayback reaches the point the question was asked
interactive:tallyRunning resultsVotes come in
interactive:closedFinal resultsThe host closes the question
interactive:count{ viewerCount }The audience size changes
interactive:error{ code, message }The server rejects something
window.addEventListener('message', (event) => {
let message;
try {
message = JSON.parse(event.data);
} catch {
return;
}
if (message.type !== 'player-ant') return;
switch (message.event) {
case 'interactive:question':
showPoll(message.detail);
break;
case 'interactive:closed':
showFinalResult(message.detail);
break;
}
});

Caution

Check event.origin against the player origin before trusting a message. Any page can post to your window.

Answering from your page

Send a vote back the same way. This lets you draw your own question interface while the player keeps the connection, so you do not open a second one.

playerIframe.contentWindow.postMessage(
JSON.stringify({
type: 'player-ant',
action: 'vote',
questionId: 'lsq_71c4a9',
optionIndex: 1,
text: 'optional written answer',
}),
'https://player.antcdn.net',
);

optionIndex is the option the viewer picked. Use -1 to send a written answer without picking one.

Drawing your own interface? Turn ours off with interactiveOverlay=0, so the two do not both appear over the same question:

https://player.antcdn.net/v1/{edgeId}/master.m3u8?interactive=1&interactiveOverlay=0

Interactivity keeps working. The player still reads questions out of the video and still relays them to your page. It just draws nothing itself.

When to use the SDK instead

Use the Player SDK when you want:

  • your own question interface rather than ours,
  • interactivity in a player that is not the AntCDN player,
  • to replay questions over a recording.

The hosted player and the SDK deliver the same events, in the same order, with the same timing. Moving from one to the other does not change what your code receives.