Skip to content

Loading the PJS Library

giannif edited this page Dec 17, 2014 · 10 revisions

Builds

Builds are deployed to http://media.mtvnservices.com/player/js/{version}. They are accessible through http://media.mtvnservices.com/pjs/?v={version}. The /pjs/ route will return the correct build for the correct context (user agent, referrer, etc.).

Loading

The PJS library is loaded just like any other javascript file.

<script src="http://media.mtvnservices.com/pjs/?v=1.0.0"></script>

If you include it in the head, it is considered "blocking" and will be loaded before your page. You can put it in the footer to avoid this.

You can use a callback to know when the PJS library has loaded, this way your script include can be anywhere.

The callback approach can be used like this:

_pjsReady
var _pjsReady = _pjsReady || [];
// you must use push!
_pjsReady.push(function(){
    // fires when the api has loaded,
    // or if the api is already loaded it will fire immediately.

    // now I can create players.
    var player = new PJS.Player(element);
});
Clone this wiki locally