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
The Shaka Player is a JavaScript library which implements a DASH client.
It relies on HTML5 video, MediaSource Extensions, and Encrypted Media
Extensions for playback.
A generic DASH client can be difficult to implement, and the DASH standard does
not always align well with the new browser APIs that DASH clients are built on.
Our goal is to reduce this friction and make it easier to adopt these emerging
web standards for streaming, without falling back to plugins.
We support both ISO BMFF (MP4) and WebM files (even in the same manifest),
WebVTT for subtitles and captions, both clear and encrypted content, and
multiple audio and subtitle languages (even in the same manifest).
And best of all, it's free!
Dependencies
Most of the tools you need to work on the Shaka Player are included in the
sources, including the Closure Compiler, gjslint, JSDoc, and
Jasmine.
Mailing list
We have a public mailing list for discussion and announcements. To receive
notifications about new versions, please join the list. You can also use the
list to ask questions or discuss Shaka Player development.
Documentation
We have detailed documentation which is generated from the sources using JSDoc.
A pre-rendered version of this documentation is available on the web at
http://shaka-player-demo.appspot.com/docs/index.html . This will be updated
with each release, but you can generate the same docs yourself at any time:
./build/docs.sh
If you are new to the project, we recommend you start by browsing the docs,
in particular the tutorials. This landing page is very brief, and only
covers the most basic information about the project.
Getting Sources
Up-to-date sources can be obtained from http://github.com/google/shaka-player .
Building
The development process is documented in more detail in our generated docs,
but in short, you can build the library by running:
./build/all.sh
Running
The library comes with a test app that can be used to tinker with all of the
library's basic functionality. The test app (index.html and app.js in the
sources) is meant to be used by making the source folder available to a local
web server and pointing your browser at it.
A hosted version of the test app is also available at
http://shaka-player-demo.appspot.com/ for your convenience.
Updating
Simply pull new sources from github and enjoy!
git pull --rebase
Design Overview
The main entities you care about are shaka.player.Player,
shaka.player.DashVideoSource, and shaka.player.DrmSchemeInfo.
In short, you construct a player and give it a <video> tag, then you
construct a DASH video source and give it a manifest URL and an optional DRM
callback. Your DRM callback returns DrmSchemeInfo objects to describe your
DRM setup. You load this video source into the player to begin playback.
The player handles high-level playback and DRM, while the video source deals
with streaming and all of the low-level parts of adaptive playback. The DRM
scheme info is an explicit set of parameters for DRM, and contains everything
the library can't glean from a DASH manifest.
More detailed information and walkthroughs with fully-functional sample code
can be found in the tutorials.
Contributing
If you have improvements or fixes, we would love to have your contributions.
Please read CONTRIBUTIONS.md for more information on the process we would like
contributors to follow.