- This guide refers only to KDP version 2.0.2 and above.
- For first time integration, please follow this Playback Guide first.
Introduction
The KDP provides API to its wrapper (JavaScript in most implementations) that enables calling to public KDP methods and registering to events triggered by the KDP that control to KDP behavior and actions. (implemented using the ExternalInterface)
Using the API it is possible to control various application and playback behaviors such as; play, pause, seek (jump to time), open and close windows and more.
Click here for a KDP API implementation example.
Perquisites
- KDP basic usage.
- This article make use of JQuery.
- Suggested: Chromeless KDP.
Registering to Events
To react to the various events, an event listener must be defined and point to a JavaScript function that will handle it.
To define an event listener use the following syntax –
myKdp.addJsListener("event_name","handler_function");
- event_name - is the name of the event to listen to (see table for list of available events).
- Handler_function – is the name of the JavaScript function defined on page that will be called when the event will fire.
It is possible to add event listeners to the KDP only after all of the following conditions are met:
- The KDP has finished initializing and is ready to be used (onKdpReady/onKdpEmpty).
- The externalInterfaceDisabled flashVar is set to 0 (or don't pass this flashVar at all).
- The allowScriptAccess parameter on the Object tag is set to always.
- Both the name and id attributes on the Object tag should be defined with the same value (To be able to access the KDP object in JavaScript).
KDP initialization, identifying the Ready state
There are 2 ways that KDP indicate that initialization has finished and it is ready to be used (Ready State).
- onKdpReady - The KDP was fully initialized and loaded with a valid entry/url and the media was successfully loaded.
- onKdpEmpty - The KDP was fully initialized, but did not load any media (like in a gallery mode where the player is loaded with no content, and wait for user interaction to get the media to load).
Because the KDP isn't ready yet, the ExternalInetrface isn't available so to listen to these events,
pass in the flashVar parameter of the KDP Object tag the name of the JavaScript functions that will be called when this event is dispatched,
like in the following examples;
Using HTML:
<parameter value="emptyF=onKdpReady&readyF=onKdpReady" name="flashVars"/>
Using SWFObject:
//Pass the flashVars to the SWFObject.embedSWF function.
In the above examples, both of the events (emptyF and readyF) will cause the same JavaScript function "onKdpReady" to be triggered.
In the JavaScript the onKdpReady will be defined as follow, providing the KDP element id in the playerId parameter:
alert("player "+playerId+" is ready");
}
Remember to specify the name and id attributes to the same value on the KDP Object tag for the playerId to return the right element id:
HTML:
JavaScript:
//Pass the flashVars to the SWFObject.embedSWF function.
In this stage, the KDP is ready (and ExternalInterface is available).
Now it is possible to register events to it and dispatch events to trigger various commands such as play, pause, seek...
KDP Events And Commands
KDP events are divided into two types –
- Event that provide additional information about the performed action (like the playhead time).
- Simple events with no additional data.
JavaScript functions that are registered to events that carry additional data, require that the data parameter will be defined in the handler function signature, for example, to determine the playhead time position during playback, the playerUpdatePlayhead event must be registered and it’s handler function should define a data object containing the new time position value.
Using Jquery to access the kdp object via JavaScript:
function onKdpReady(playerId){
$("#"+playerId).get(0).addJsListener("playerUpdatePlayhead","updatePlayheadHandler");
}
// function handler for the updatePlayhead event:
function updatePlayheadHandler (playheadValue) {
}
To know when the KDP volume has changed:
function onKdpReady(playerId){
$("#"+playerId).get(0).addJsListener("volumeChange","volumeChangeAlert");
}
// function handler for the volumeChange event:
function volumeChangeAlert(volumeValue)
{
alert("kdp volume is set to : "+ volumeValue);
}
In this case the "volumeChange" event contains the KDP volume value.
Remove an Event Listener (Stop getting event notifications)
To remove the listener of a specific event, use opposite API "removeJsListener":
- event_name - is the name of the event to listen to (see table for list of available events).
Dispatching KDP Events - Calling KDP Methods to perform actions
To command the KDP to perform certain actions, a command event must be dispatched.
To dispatch a command event, use the dispatchKdpEvent("event_name", values);
- event_name - is the name of the event to listen to (see table for list of available events).
- values - (optional) A value to be passed as the action parameter (e.g. the volume level value (0-1) when setting a new volume level).
Examples:
myKdp.dispatchKdpEvent("doPause");
// to mute the volume (set the volume level to 0):
myKdp.dispatchKdpEvent("volumeChange", 0);
Special public functions
In addition to the events, KDP also provide a few specific public functions to ease the integration and use direct method calls instead of dispatching events:
- insertMedia - command the player to play a new media (overrides last entry in case it was playing something).
myKdp.insertMedia(kshow_id:String = "-1", entry_id:String = "-1", auto_play:String = "false", entry_version:String = "-1");- kshow_id - Deprecated (used to load a specific kshowId).
- entry_id - the id of the kaltura entry to load, or a URL to media.
- auto_play - Boolean, if true, media will play immediately. false will make the player wait for user interaction.
- entry_version - specific version id of the entry to load.
- getMediaSeekTime - get the position of the video playhead. A way to ask the KDP for its playhead time value.
alert(myKdp.getMediaSeekTime()); - seekMedia - jump to a specific time.
//seek to the 10th second.
myKdp.seekMedia(10); - stopMedia - stop playback and jump back to start.
myKdp.stopMedia(); - pauseMedia - pause playback.
myKdp.pauseMedia(); - playMedia - start playback.
myKdp.playMedia(); - evaluate - Evaluate variables from the KDP model [more].
//e.g. getting the playing entry id:
alert ("The currently playing entry id is " + kdp.evaluate("{entry.id}"));
KDP Events
The following list of events are available both as public events dispatched by the kdp (to be used when embedded inside another Flash application), and as ExternalInetrface events available for the dispatchKdpEvent and addJsListener methods.
Notifiers (events that notify of a performed action or change)
| Name | Parameters | Description | Comments |
|---|---|---|---|
| playerPaused | player entered pause state | player is paused | |
| playerPlayed | player entered play state | player is playing | |
| playerUpdatePlayhead | notify about the change in playhead time | during playback or seek | |
| playerUpdateNewAsset | playhead reached another media asset (a mix is assembled from a sequence of media assets) | only available when playing mixes (roughcuts) | |
| playerProgress | monitors the download progress of single video streams and images | monitoring of mix download is currently not available via JS | |
| playerPlayEnd | playback ended, if there are post-playback modules like post-roll ad, post-playback modules are now being processed | player is paused | |
| hasOpenedFullScreen | player entered to full-screen mode | ||
| hasCloseFullScreen | player exit full-screen mode | return to normal state | |
| captureThumbnailSuccess | thumbnail was successfully saved | ||
| captureThumbnailFailed | thumbnail failed to save | ||
| endEntrySession | playback session fully ended, including post-playback modules (like post-roll ads) | player is now paused |
Commands (events that will cause an action to be performed)
| Name | Parameters | Description | Comments |
|---|---|---|---|
| doPause | command the player to pause | relevant callback: playerPaused | |
| doPlay | command the player to play | relevant callback: playerPlayed playerPlayed callback will not always be called immediately after doPlay command, for example: when using an ad module, the playerPlayed callback will only be played after the ad finished and the actual video/media started playing |
|
| doSeek | command the playhead to jump to a specific time | relevant callback: playerSeeked | |
| openFullScreen | change to full-screen mode | relevant callback: hasOpenedFullScreen | |
| closeFullScreen | exit from fullscreen mode | relevant callback: hasCloseFullScreen | |
| volumeChange | Number/Float, 0 - 1 | set the player volume level | |
| changeKshow | object that hold the following parameters:
|
set a new media to play | |
| enableGui | Boolean: true or false | set enable / disable state for the player interface (buttons) | |
| captureThumbnail | set the currently presented image as the entry thumbnail | relevant callbacks:
|
|
| gigyaPopup | show the Share screen module (powered by Gigya) | ||
| fastForward | 2, 4, 8 | fast forward playback | set playback speed to 2, 4, 8 times faster than normal playback |
| stopFastForward | stop fast forward and return to normal playback speed | ||
| playerReady | initialize process is complete, player can process commands (register the rest of the commands events after this event), a media was loded and ready to be played | to register to thi event use the readyF flashVar | |
| playerEmpty | initialize process is complete, player can process commands (register the rest of the commands events after this event), no media was loaded | to register to thi event use the emptyF flashVar | |
| closePopup | close the active popup window | ||
| centerPopup | center the active popup window | ||
| showBottomBanner | a bottom banner ad was shown | dispatching this event will cause subtitles to show above banner height | |
| hideBottomBanner | the bottom banner ad was removed | dispatching this event will cause subtitles to show at bottom (above control bar) | |
| showStartScreen | show the on-screen interface defined as the player start state screen on the uiConf | see uiConf guide for more | |
| showEndScreen | show the on-screen interface defined as the end of playback screen on the uiConf | see uiConf guide for more | |
| showPlayScreen | show the on-screen interface defined as the playback screen on the uiConf | see uiConf guide for more | |
| showPauseScreen | show the on-screen interface defined as the paused state screen on the uiConf | see uiConf guide for more | |
| setPlaylistUrl | string: url to the mRss | change the url to the playlist mRss provider |




Comments
I'm slightly confused by
I'm slightly confused by this:
var attributes = { id: "myKdp"; name: "myKdp"; };Is this supposed to be put in the params section instead?
Edit button
Can you add gotoEditorWindow to this list of events? It looks like this is implemented as a direct javascript call to a function called gotoEditorWindow() so you wouldn't register a listener for it, but rather just create a function with that name which accepts entryID as an argument (not sure why works differently that other events). Some more info: http://www.kaltura.org/text-overlays-break-mixes#comment-1455. The function is called when the user presses the Edit button in KDP 2.x, and can be used to derive a URL to the editor for a specific entry.
I think the issue is that
I think the issue is that the "Editor Button" is not a default function of the KDP. It's basically just a custom button that you can create by putting data into the UIConf. So, depending on what you've got in the UIConf, the JS call to open the editor may or may not be "gotoEditorWindow". So it's not an event that is built into the KDP source - hence the reason why it's not documented here...
Confusing I know!
default function of KDP
I see what you mean, but I consider it a default function since it is something that I can add in the Application Studio. I.e. it's just as default as the Play and Stop button, the implementation is just not consistent. There must be a lot of people that are building custom KDPs using Kaltura.com's own tools, adding an Edit button, then wondering why it doesn't do anything. But, maybe I'm misunderstanding something.
BTW, as I was writing this, I jumped into the Application Studio and noticed something I hadn't seen before:
http://www.kaltura.org/sites/default/files/imagepicker/c/chrismillet/Pic...
I wish I'd seen that before... Regardless, I think this should be standardized and documented somewhere.
Agreed... Also that
Agreed... Also that description on the KMC definitely WASN'T there when you originally asked the question... So at least you can rest assure that someone at Kaltura is listening!
Where is the complete External Interface definition?
I'm looking for the list of properties that can be queried via "myKdp.evaluate()"...
Seems like a fairly important set of information to make available on this page, no?
Ryan - You're completely
Ryan -
Since the KDP is dynamic there can be various sets of parameters that can be evaluated through Kdp.evaluate() function;
Please read this document: http://www.kaltura.org/kdp-evaluate-method-retrieving-model-data