Examples: Advanced Browser API

From DevWiki

Revision as of 07:15, 8 December 2010 by Riegersn (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
/* Advanced JS Controller Demo
 * For JS API version >= 7.0 (Boxee Box, Boxee Client version >= 1.0)
 *
 * Something new not seen in previous javascript api versions is the executeJS()
 * function. This gets a pointer to the currently active (fullscreen) flash object.
 * example: document.player.pause() == widget.executeJS('this.pause()')
 * See API documentation for more information.
 * 
 */
 
// this source will autoplay if we append the autostart param before it loads
boxee.rewriteSrc = function(src) {
   return src + '?autostart=1';
}
 
// set the api min version to 7.0, for default browser settings
boxee.apiMinVersion = 7.0;
 
// add the 'switch to fullscreen' button to the boxee OSD
playerState.canSetFullScreen = true;
 
/* boxee osd volume is always enabled as it now controls the system volume.
 * with this in mind, we want to max the flash volume as soon as the function
 * is available. We use an interval in this example, but you can do this however
 * is easiest for you.
 */
setVol = setInterval(function(){
   if (browser.execute('typeof document.player.setVolume') == 'function') {
      browser.execute('document.player.setVolume(1)');
      clearInterval(setVol);
   }
},1000);
 
// callback executed just before the Boxee OSD is made visible
boxee.onUpdateState = function() {
 
   // enable pause/play controls in OSD
   playerState.canPause = true;
 
   // enable seek controls in OSD
   playerState.canSeek = true;
 
   // set the current time
   playerState.time = parseInt(boxee.getActiveWidget().executeJS('this.getPosition()'));
 
   // set the current duration
   playerState.duration = parseInt(boxee.getActiveWidget().executeJS('this.getDuration()'));
 
   // add a custom button the the Boxee OSD
   playerState.ext0 = {
      thumb: "http://dir.boxee.tv/apps/common/icons/icons_hd.png",
      text: "Toggle HD",
      enabled: true
   };
}
 
// callback executed when a custom OSD button is clicked
boxee.onActivateExt = function(ext) {
   if (ext == 0) {
 
      // check if player is currently in hd
      var hd_on = boxee.getActiveWidget().executeJS('this.isHD()')
 
      if (hd_on == 'true') {
         // hd is on, set quality to 480
         boxee.getActiveWidget().executeJS('this.setPlaybackQuality("480p")');
         boxee.showNotification("Setting playback quality to SD...", ".", 3);
      }
      else {
         // hd is off, set quality back to 720
         boxee.getActiveWidget().executeJS('this.setPlaybackQuality("720p")');
         boxee.showNotification("Setting playback quality to HD...", ".", 3);
      }
   }
}
 
// callback function executed when user presses play on osd/remote
boxee.onPlay = function() {
   boxee.getActiveWidget().executeJS('this.playVideo()');
}
 
// callback function executed when user presses pause on osd/remote
boxee.onPause = function() {
   boxee.getActiveWidget().executeJS('this.pauseVideo()');
}
 
// callback function executed when user presses small skip on osd/remote
boxee.onSkip = function() {
   boxee.getActiveWidget().executeJS('this.seekVideo(15)');
}
 
// callback function executed when user presses big skip on osd/remote
boxee.onBigSkip = function() {
   boxee.getActiveWidget().executeJS('this.seekVideo(600)');
}
 
// callback function executed when user presses small back on osd/remote
boxee.onBack = function() {
   boxee.getActiveWidget().executeJS('this.seekVideo(-10)');
}
 
// callback function executed when user presses big back on osd/remote
boxee.onBigBack = function() {
   boxee.getActiveWidget().executeJS('this.seekVideo(-600)');
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox