Files
shaka-player/docs/tutorials/config.md
T
Joey Parrish c8e80cb58d Tutorials and other doc revisions
- Update tutorial link in README
 - Fix python version in README
 - Move jsdoc conf to docs/ folder
 - Add API docs main page
 - Change style of inline code blocks
 - Don't repeat tutorial title in jsdoc template
   - (makes it easier to read tutorials on github as MD)
 - Add tutorials for:
   - Welcome to Shaka
   - Basic Usage
   - Debugging
   - Configuration
   - Networking and Buffering Configuration
   - DRM Configuration
   - License Server Authentication
   - Plugins
 - Tutorials still to come:
   - License Headers and Track Restrictions
   - Special Considerations for Live
   - v2 Upgrade Guide

Change-Id: I16401c216cf4023d9097750ac7f6090c68bf3c9b
2016-04-06 19:17:51 +00:00

2.7 KiB

Configuration

The goal of this tutorial is to introduce Shaka's configuration system and the concepts on which it is built. More detail can be found in the API docs.

Shaka's Player object has a hierarchical configuration. The overall player config contains sub-configs for various parts of the system, such as manifests, streaming, and DRM.

To see the current config, you can use player.getConfiguration(). If you run this without setting anything first, you get the default configuration.

Player also has a configure() method that takes a plain, anonymous object as an argument. Any fields you leave out of the config object will retain their existing values, and any fields you explicitly set as undefined will be reverted to their default value.

You can use the code from {@tutorial basic-usage} and try these examples in the JS console:

player.getConfiguration();

=> Object
     abrManager: SimpleAbrManager
     drm: Object
       advanced: Object
       clearKeys: Object
       retryParameters: Object
         backoffFactor: 2
         baseDelay: 1000
         fuzzFactor: 0.5
         maxAttempts: 1
         timeout: 0
       servers: Object
     enableAdaptation: true
     manifest: Object
       dash: Object
       retryParameters: Object
     preferredAudioLanguage: ""
     preferredTextLanguage: ""
     streaming: Object
       bufferBehind: 30
       bufferingGoal: 30
       rebufferingGoal: 15
       retryParameters: Object


// set audio language preference to Canadian French:
player.configure({ preferredAudioLanguage: 'fr-CA' });

// set text language preference to Greek and buffering goal to 2 minutes:
player.configure({
  preferredTextLanguage: 'el',
  streaming: {
    bufferingGoal: 120
  }
});

// check audio language preference, which is still Canadian French:
player.getConfiguration().preferredAudioLanguage

// check buffering goal, which is 2 minutes:
player.getConfiguration().streaming.bufferingGoal

// check rebuffering goal, which is still the default of 15 seconds:
player.getConfiguration().streaming.rebufferingGoal

// set the rebuffering goal to 2 seconds and revert buffering goal to default:
player.configure({
  streaming: {
    bufferingGoal: undefined,
    rebufferingGoal: 2
  }
});

Some of these fields have immediate effects (such as language-related settings, networking settings, and buffering settings) while some will not have any effect until the next call to load() (such as DRM and manifest settings).

Detailed API Docs

For more detail on individual configuration options, please see the API docs for {@link shakaExtern.PlayerConfiguration} and {@link shaka.Player#configure}.

Continue the Tutorials

Next, check out {@tutorial network-and-buffering-config}.