Page History: PlayerSDK 2.0 Getting Started
Compare Page Revisions
Page Revision: 2016/11/08 22:34
Embedding the Player
Embedding the Player involves:
loading a JavaScript library from Company Webcast servers
adding a DIV to your DOM that the Javascript library can fill with the Player
initializing the Player from Javascript.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Player SDK Sample Application</title>
</head>
<body>
<div id="playerContainer" style="width:640px;height:360px;"></div>
</body>
</html>
< script type="text/javascript" src="//sdk.companywebcast.com/sdk/player/client.js"></script>
< script type="text/javascript">
var cwcPlayer = cwc.sdk.player.client.createPlayer({
id: 'customer/code'
});
document.getElementById("playerContainer").appendChild(cwcPlayer.element);
</script>
Customizing playback
Players can be configured to start playback from a specific position.
Players can be configured to play a fragment, or a series of fragments, from a single Webcast.
Players can be configured to hide specific Player functionality and UI features.
Player initialization accepts the following parameters:
id
A string. This is the WebcastCode, or WebcastGuid that you have retrieved through other components of the Company Webcast API.
offsets
An array of integers. Expose only parts of the media stream. This is essentially virtual fragment generation. In milliseconds: [start, end, start, end].
start
An integer. In milliseconds, the position from where the Player will commence playback. The start property is applied after any configured offsets are applied.
identificationToken
A string. Allows for Single Signon scenarios.
display
A Bitwise OR. Configures which parts of the Player are visible.
Not setting this property will display all buttons.
Options are:
1
display home button
2
display topics button
< script type="text/javascript">
var cwcPlayer = cwc.sdk.player.client.createPlayer({
id: 'customer/code',
start: 5000,
offsets: [20000, 40000, 50000, 80000],
display: 1 | 2
});
</script>
Methods
An instance of the embedded player has 3 methods.
Available methods:
on
createChat
seek
Media playback jumps to the given position.
Accepts a seek object as its input parameter. The seek object has either the timestamp property, or the walltime property.
Timestamps are milliseconds, expressed as an integer.
< script type="text/javascript">
//Jump to the 5 second position
cwcPlayer.seek({ timestamp: 5000 });
//Jump to whichever position maps to March 1st, 2007 at 13:00 UTC.
cwcPlayer.seek({ walltime: '2007-03-01T13:00:00Z' });
</script>
Event handling
Event listeners can be attached to the embedded player, so events can be received for changes in state and metadata.
Available Events:
resource:create
Fires when a new resource is added to the model. This happens during initialization, when metadata is loaded into the player, and when new resources are added during a live Webcast.
Returns a resourceCreateEvent.
properties of resourceCreateEvent are:
playerId
A string. The id of the player instance that generated the event.
resource
resource.state:change
Fires when a resource activates or de-activates.
Returns a resourceChangeEvent.
properties of resourceChangeEvent are:
playerId
A string. The id of the player instance that generated the event.
resource
isActive
A boolean. If true, the resource is currently active.
event:create
Fires when a new Event is added to the Player model.
Returns a eventCreateEvent.
properties of eventCreateEvent are:
playerId
A string. The id of the player instance that generated the event.
event
An
event. The event that was added to the model.
chat:ready
Fires when chat has successfully initialized, and is ready to be used.
< script type="text/javascript">
cwcPlayer.on('resource:create', function (resourceCreateEvent) {
});
cwcPlayer.on('resource.state:change', function (resourceChangeEvent) {
});
cwcPlayer.on('event:create', function (eventCreateEvent) {
});
</script>
speakerResource
Contains information about a speaker.
speakerResource has the following properties:
id
A string. The id of the resource. These map onto id's that you've retrieved from other components of the Company Webcast API.
type
A string. Contains "speaker".
order
An integer. If applicable, contains a number indicating the position of the resource in a list of resources of the same type.
category
A string. The category of the speaker. This may contain the political party of the speaker, or a company department, for example.
name
A speakerName object.
speakerName has the following properties:
title
A string. The title of the speaker.
first
A string. The first name of the speaker.
middle
A string. The middle name of the speaker.
last
A string. The last name of the speaker.
full
A string. The full name of the speaker.
role
A string. The role of the speaker.
topicResource
Contains information about a topic.
topicResource has the following properties:
id
A string. The id of the resource. These map onto id's that you've retrieved from other components of the Company Webcast API.
type
A string. Contains "topic".
order
An integer. If applicable, contains a number indicating the position of the resource in a list of resources of the same type.
label
A string. Contains the title of the topic.
description
A string. Present if available. Contains a description of the topic.
event
An object that contains a timed occurrence. Events describe activation and de-activation of a
resource.
event has the following properties:
eventData
A string.
id
A string. The id of the resource this event describes.
intent
A string. Contains either "speakers.speaker:activate".
orderNr
An integer. If applicable, contains a number indicating the position of the event in a list of events of the same type.
timestamp
An integer. In milliseconds; describes the playback position where this event activates/de-activates.
Using Chat
Some Webcasts may include Chat functionality. Chat widgets can be embedded using this SDK.
Note that Chat is enabled on a per-Webcast basis, and is only available to customers that have specifically enabled this functionality.
For Webcasts that have Chat enabled, please note that Chats are currently only available when a Webcast is LIVE.
Webcasts either before or after the LIVE phase do not have access to Chat functionality.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Player SDK Sample Application</title>
</head>
<body>
<div id="playerContainer" style="width:640px;height:360px;"></div>
<div id="chatContainer" style="display:none;width:640px;height:360px;"></div>
</body>
</html>
< script type="text/javascript" src="//sdk.companywebcast.com/sdk/player/client.js"></script>
< script type="text/javascript">
var playerContainer = document.getElementById("playerContainer"),
chatContainer = document.getElementById("chatContainer");
var cwcPlayer = cwc.sdk.player.client.createPlayer({
id: 'customer/code'
});
cwcPlayer.on('chat:ready', function () {
chatContainer.style.display = 'block';
});
var chatElement = cwcPlayer.createChat();
playerContainer.appendChild(cwcPlayer.element);
chatContainer.appendChild(chatElement);
</script>