What is shaka-player?
Shaka Player is an open-source JavaScript library for adaptive media streaming. It supports DASH and HLS formats and provides a wide range of features for media playback, including DRM support, offline storage, and live streaming.
What are shaka-player's main functionalities?
Basic Playback
This code demonstrates how to set up basic video playback using Shaka Player. It initializes the player with a video element and loads a DASH manifest.
const video = document.getElementById('video');
const player = new shaka.Player(video);
player.load('https://example.com/manifest.mpd').then(function() {
console.log('The video has now been loaded!');
}).catch(function(error) {
console.error('Error loading video', error);
});
DRM Support
This code demonstrates how to configure Shaka Player to support DRM (Digital Rights Management). It sets up license servers for Widevine and PlayReady and loads a DASH manifest.
const video = document.getElementById('video');
const player = new shaka.Player(video);
player.configure({
drm: {
servers: {
'com.widevine.alpha': 'https://example.com/widevine_license',
'com.microsoft.playready': 'https://example.com/playready_license'
}
}
});
player.load('https://example.com/manifest.mpd').then(function() {
console.log('The video with DRM has now been loaded!');
}).catch(function(error) {
console.error('Error loading video with DRM', error);
});
Offline Storage
This code demonstrates how to use Shaka Player's offline storage feature. It initializes the storage module and stores a DASH manifest for offline playback.
const video = document.getElementById('video');
const player = new shaka.Player(video);
const storage = new shaka.offline.Storage(player);
storage.store('https://example.com/manifest.mpd').then(function(content) {
console.log('The content has been stored offline!', content);
}).catch(function(error) {
console.error('Error storing content offline', error);
});
Live Streaming
This code demonstrates how to set up live streaming using Shaka Player. It initializes the player with a video element and loads a live DASH manifest.
const video = document.getElementById('video');
const player = new shaka.Player(video);
player.load('https://example.com/live.mpd').then(function() {
console.log('The live stream has now been loaded!');
}).catch(function(error) {
console.error('Error loading live stream', error);
});
Other packages similar to shaka-player
video.js
Video.js is a popular open-source HTML5 video player that supports a wide range of video formats and provides a plugin architecture for extending its functionality. Compared to Shaka Player, Video.js has a larger community and more plugins available, but it does not natively support DASH or HLS streaming.
hls.js
Hls.js is a JavaScript library that brings HLS (HTTP Live Streaming) to browsers with support for MSE (Media Source Extensions). It is specifically designed for HLS streaming, whereas Shaka Player supports both DASH and HLS. Hls.js is a good choice if you only need HLS support.
dash.js
Dash.js is an open-source reference client for the playback of MPEG-DASH content. It is maintained by the DASH Industry Forum and provides extensive support for DASH streaming. Compared to Shaka Player, Dash.js is more focused on DASH and may not have as many features for HLS or DRM.
Shaka Player is a JavaScript library for adaptive video streaming.
It plays DASH content without browser plugins using
MediaSource Extensions and Encrypted Media Extensions.
We are currently testing on the latest stable releases of Chrome, Firefox, and
Edge, as well as IE 11 and Safari 9. We test using both Widevine and PlayReady,
but any browser-supported DRM system available through EME should work.
Our main goal is to make it as easy as possible to stream adaptive bitrate
video using modern browser technologies. We try to keep the library light and
simple, and it has no third-party dependencies. Everything you need to build
and deploy is in the sources.
We support both ISO BMFF (MP4) and WebM content (even in the same
manifest), WebVTT for subtitles and captions, both clear and encrypted content,
and multilingual content. And best of all, it's free!
Important Links
Compiled Mode
Shaka Player is meant to be deployed after being compiled. The tools you need
to compile the sources and documentation are included in the sources:
Closure Compiler, Closure Linter, and JSDoc.
If you installed Shaka Player via npm, the sources have already been compiled
for you.
In order to build, you simply need python v2.7 (for the build scripts) and
JRE 7+ (for the compiler). Just run ./build/all.py
and look for the output
in dist/shaka-player.compiled.js
. The output can be included directly in a
<script>
tag or loaded via a number of JavaScript module loaders.
To build the documentation, you will also need nodejs. Just run
./build/docs.py
and look for the output in docs/api/
.
Uncompiled Mode
Shaka Player can also be run in uncompiled mode. This is very useful for
development purposes.
To load the library without compiling, you will need to generate a Closure
"deps file" by running ./build/gendeps.py
. Then, you'll need to bootstrap
your application with three <script>
tags:
<script src="third_party/closure/goog/base.js"></script>
<script src="dist/deps.js"></script>
<script src="shaka-player.uncompiled.js"></script>
If you installed Shaka Player via npm, the deps file has already been generated
for you.
Testing
You will need a few third-party dependencies to run automated tests. These
dependencies are managed through npm
and Shaka's package.json
. If you
cloned Shaka from github, simply run npm install
from your git working
directory to install these dependencies locally.
Run the tests in your platform's browsers using ./build/test.py
. If you are
familiar with the karma test runner, you can pass additional arguments
to karma from build/test.py
. For example:
./build/test.py --browsers Opera
Or:
./build/test.py --browsers Chrome,Firefox --reporters coverage
You can skip slow-running integration tests with --quick
.
Contributing
If you have improvements or fixes, we would love to have your contributions.
Please read CONTRIBUTING.md for more information on the process we would like
contributors to follow.