Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

videojs-contrib-dash

videojs37.5kApache-2.05.1.1

A Video.js source-handler providing MPEG-DASH playback.

MPEG-DASH, dash, dash.js, dashjs, playready, video.js, videojs, videojs-plugin, widevine

readme

video.js MPEG-DASH Source Handler

Build Status Greenkeeper badge Slack Status

NPM

A video.js source handler for supporting MPEG-DASH playback through a video.js player on browsers with support for Media Source Extensions.

Supported Dash.js version: 4.x

Maintenance Status: Stable

Drop by our slack channel (#playback) on the Video.js slack.

Table of Contents generated with DocToc

Getting Started

Download Dash.js and videojs-contrib-dash. Include them both in your web page along with video.js:

<video id=example-video width=600 height=300 class="video-js vjs-default-skin" controls></video>
<script src="video.js"></script>

<!-- Dash.js -->
<script src="dash.all.min.js"></script>

<!-- videojs-contrib-dash script -->
<script src="videojs-dash.min.js"></script>

<script>
var player = videojs('example-video');

player.ready(function() {
  player.src({
    src: 'https://example.com/dash.mpd',
    type: 'application/dash+xml'
  });

  player.play();
});
</script>

Checkout our live example if you're having trouble.

Protected Content

If the browser supports Encrypted Media Extensions and includes a Content Decryption Module for one of the protection schemes in the dash manifest, video.js will be able to playback protected content.

For most protection schemes, the license server information (URL & init data) is included inside the manifest. The notable exception to this is Widevine-Modular (WV). To playback WV content, you must provide the URL to a Widevine license server proxy.

For this purpose, videojs-contrib-dash adds support for a "keySystemOptions" array to the object when using the player.src() function:

player.src({
  src: 'http://example.com/my/manifest.mpd',
  type: 'application/dash+xml',
  keySystemOptions: [
    {
      name: 'com.widevine.alpha',
      options: {
        serverURL: 'http://m.widevine.com/proxy'
      }
    }
  ]
});

You may also manipulate the source object by registering a function to the updatesource hook. Your function should take a source object as an argument and should return a source object.

var updateSourceData = function(source) {
  source.keySystemOptions = [{
    name: 'com.widevine.alpha',
    options: {
      serverURL:'https://example.com/anotherlicense'
    }
  }];
  return source;
};

videojs.Html5DashJS.hook('updatesource', updateSourceData);

Captions

As of `video.js@5.14, native captions are no longer supported on any browser besides Safari. Dash can handle captions referenced embedded vtt files, embedded captions in the manifest, and with fragmented text streaming. It is impossible to use video.js captions when dash.js is using fragmented text captions, so the user must disable native captions when usingvideojs-contrib-dash`.

videojs('example-video', {
  html5: {
    nativeCaptions: false
  }
});

A warning will be logged if this setting is not applied.

Using TTML Captions

TTML captions require special rendering by dash.js. To enable this rendering, you must set option useTTML to true, like so:

videojs('example-video', {
  html5: {
    dash: {
      useTTML: true
    }
  }
});

This option is not true by default because it will also render CEA608 captions in the same method, and there may be some errors in their display. However, it does enable styling captions via the captions settings dialog.

Multi-Language Labels

When labels in a playlist file are in multiple languages, the 2-character language code should be used if it exists; this allows the player to auto-select the appropriate label.

Passing options to Dash.js

It is possible to pass options to Dash.js during initialiation of video.js. All methods in the Dash.js#MediaPlayer docs are supported.

To set these options, pass the exact function name with a scalar or array value to call the correpsonding MediaPlayer function.

For example:

var player = videojs('example-video', {
  html5: {
    dash: {
      setLimitBitrateByPortal: true,
      setMaxAllowedBitrateFor: ['video', 2000]
    }
  }
});

A warning will be logged if the configuration property is not found.

Deprecation Warning

Previously the set prefix was expected to be omitted. This has been deprecated and will be removed in a future version.

Initialization Hook

Sometimes you may need to extend Dash.js, or have access to the Dash.js MediaPlayer before it is initialized. For these cases, you can register a function to the beforeinitialize hook, which will be called just before the Dash.js MediaPlayer is initialized.

Your function should have two parameters:

  1. The video.js Player instance
  2. The Dash.js MediaPlayer instance
var myCustomCallback = function(player, mediaPlayer) {
  // Log MediaPlayer messages through video.js
  if (videojs && videojs.log) {
    mediaPlayer.getDebug().setLogToBrowserConsole(false);
    mediaPlayer.on('log', function(event) {
      videojs.log(event.message);
    });
  }
};

videojs.Html5DashJS.hook('beforeinitialize', myCustomCallback);

changelog

5.1.1 (2021-11-30)

Bug Fixes

5.1.0 (2021-09-17)

Features

Bug Fixes

Chores

  • add example that uses TTML subtitles (#368) (563aac6)
  • don't run tests on version (6b15e7e)

5.0.0 (2021-06-25)

Features

Chores

  • skip require in vjsverify (10488f6)

Documentation

BREAKING CHANGES

  • no longer able to be required in nodejs.
  • update to DASH.js 4.0

4.1.0 (2021-02-18)

Bug Fixes

4.0.1 (2021-02-18)

Bug Fixes

  • rollup plugins should be dev dependencies (#352) (9d09a60)

Chores

4.0.0 (2020-11-05)

Features

CHANGELOG

3.0.0 (2020-10-26)

  • BREAKING CHANGE: Update Dash.js to 3.1.3 (major version 3)

2.11.0 (2019-03-08)

  • Fix bug where VTT captions wouldn't show
  • Support for human-readable track labels

2.10.1 (2018-12-18)

  • Change main to be dist/videojs-dash.cjs.js
  • Reformat test code
  • Add v7 to list of supported video.js dependencies

2.10.0 (2018-07-30)

  • Cleanup of event addition and removal on dispose to not bork on source change
  • Use MPD type and duration to determine if we should report live status
  • Add error handler for new mssError in dash.js 2.6.8
  • Pass through text track kind to dash.js

2.9.3 (2018-04-12)

  • Retrigger dash.js errors on video.js

2.9.2 (2017-10-11)

  • Depend on either Video.js 5.x or 6.x

2.9.1 (2017-06-15)

  • Fix text tracks in IE

2.9.0 (2017-05-11)

  • Load text tracks from dashjs into video.js

2.8.2 (2017-04-26)

  • Show role in audio track label

2.8.1 (2017-02-09)

  • Call update source hook in canHandleSource

2.8.0 (2017-02-02)

  • Add support for multiple audio tracks
  • Introduce videojs 6 forward compatibility while maintaining backward compatibility

2.7.1 (2017-02-02)

  • Allow dash config object to accept setters with multiple args

2.7.0 (2017-01-30)

  • Support all dash.js configuration options

2.6.1 (2017-01-05)

  • Fixed Live display for live streams

2.6.0 (2016-12-12)

  • Added initialization and update source hooks.

2.5.2 (2016-11-22)

  • Don't pass empty object for key systems.

2.5.1 (2016-09-09)

  • Skip source if requestMediaKeySystemAccess isn't present for key system

2.5.0 (2016-08-24)

  • Expose mediaPlayer on player

2.4.0 (2016-07-07)

  • ES6 rewrite
  • Allow to pass option to limit bitrate by portal size

2.3.0 (2016-05-10)

  • Add a hook before dash.js media player initialization

2.2.0 (2016-05-04)

  • Added browserify support
  • Remove manifest parsing

2.1.0 (2016-03-08)

  • Update project to support dash.js 2.0
  • Update deprecated laURL to utilize new serverURL
  • Add canPlayType

2.0.0 (2015-10-16)

  • Update project to be compatible with video.js 5.0