-
Notifications
You must be signed in to change notification settings - Fork 0
Loading the PJS Library
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.).
The PJS library must be loaded at runtime, and not compiled in to your project, since the user agent and context are used to determine the appropriate build (e.g. mobile doesn't get flash).
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:
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);
});
Once you've loaded the script see Creating Players.