npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hasplayer.js

v1.15.1

Published

hasplayer.js is a javascript implementation of a video player based on the W3C premium extensions, i.e. [MSE](https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html) and [EME](https://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted

Downloads

1,109

Readme

hasplayer.js Build Status

hasplayer.js is a javascript implementation of a video player based on the W3C premium extensions, i.e. MSE and EME.

hasplayer.js is an extension of the dash.js project with the aim of supporting additional http adaptive streaming protocols such as Microsoft Smooth Streaming protocol and Apple Http Live Streaming.

If your intent is to use the player code without contributing back to this project, then use the MASTER branch which holds the approved and stable public releases.

If your goal is to improve or extend the code and contribute back to this project, then you should make your changes in, and submit a pull request against, the DEVELOPMENT branch.

Learn more about versions and roadmap on the wiki.

Quick Start

Reference Player

  1. Download 'master', 'development' or latest tagged release.
  2. Extract hasplayer.js and move the entire folder to localhost (or run any http server instance at the root of the hasplayer.js folder).
  3. Open any sample from the samples folder in your MSE capable web browser.

Install Dependencies

  1. install nodejs
  2. install gulp
npm install -g gulp

Build / Run

npm run build

The build task can be configured in order to select supported protocol(s) and to integrate or not EME support. For example:

  1. No hls support, no EME support:
npm run build -- --no-hls --no-protection
  1. No hls support, no MSS support:
npm run build -- --no-hls --no-mss

Demo

A builded version of the hasplayer.js and samples is available at this address:

http://orange-opensource.github.io/hasplayer.js

License

All code in this repository is covered by the BSD-3 license. See LICENSE file for copyright details.

Getting Started

Create a video element somewhere in your html. For our purposes, make sure to set the controls property to true.

<video id="videoPlayer" controls="true"></video>

Add hasplayer.js to the end of the body.

<body>
  ...
  <script src="yourPathToHasplayer/hasplayer.js"></script>
</body>

Now comes the good stuff. We need to create an MediaPlayer. Then we need to initialize it, attach it to our "videoPlayer" and then tell it where to get the video from. We will do this in an anonymous self executing function, that way it will run as soon as the page loads. So, here is how we do it:

(function(){
    var stream = {
        url: "http://playready.directtaps.net/smoothstreaming/SSWSS720H264/SuperSpeedway_720.ism/Manifest"
    };
    var mediaPlayer = new MediaPlayer();
    MediaPlayer.init(document.querySelector("#videoPlayer"));
    MediaPlayer.load(stream);
})();

When it is all done, it should look similar to this:

<!doctype html>
<html>
    <head>
        <title>hasplayer.js Rocks</title>
    </head>
    <body>
        <div>
            <video id="videoPlayer" controls="true"></video>
        </div>
        <script src="yourPathToHasplayer/hasplayer.js"></script>
        <script>
            (function(){
                var stream = {
                    url: "http://playready.directtaps.net/smoothstreaming/SSWSS720H264/SuperSpeedway_720.ism/Manifest"
                };
                var mediaPlayer = new MediaPlayer();
                mediaPlayer.init(document.querySelector("#videoPlayer"));
                mediaPlayer.load(stream);
            })();
        </script>
    </body>
</html>

DRM Video Stream

In the case of protected content, here is an example illustrating setting of the protection data:

    var stream = {
        url: "<manifest_url>",
        protData: {
            "<key_system>": {
                laURL: "<licenser_url>",
                withCredentials: "<license_request_withCredentials_value (true or false)>",
                cdmData: "<CDM_specific_data>", // Supported by PlayReady key system (using MS-prefixed EME API) only
                serverCertificate: "<license_server_certificate (as Base64 string)>"
                audioRobustness: "<audio_robustness_level>" // Considered for Widevine key system only
                videoRobustness: "<video_robustness_level>" // Considered for Widevine key system only
            }
        }
    };
    mediaPlayer.load(stream);

HLS and FairPlay on Safari/OSx

In order to playback HLS protected contents with FairPlay DRM, a specific mode is available which consists in streaming and playing the content directly with the <video> element, and in managing the exchanges between the FairPlay CDM and the licenser using EME. To activate this mode on Safari/OSx you need to explicitely indicate the protocol type, i.e. 'HLS', for the input stream:

    var stream = {
        url: "<manifest_url>",
        protocol= "HLS",
        protData: {
            "com.apple.fps.1_0": {
                laURL: "<licenser_url>",
                withCredentials: "<license_request_withCredentials_value (true or false)>",
                serverCertificate: "<license_server_certificate (as Base64 string)>"
            }
        }
    };
    mediaPlayer.load(stream);

Since native player is used to achieve streaming session, some parts of the MediaPlayer API have no effect (functions relative to streaming and ABR configuration, DVR, trick mode...). However, API for audio and subtitles tracks management is functional.

Events

MediaPlayer offers events to be notified of differents events on video streaming. Those events are, for a part, sent by the HTMLMediaElement (<video>), and for an other part, sent by the MediaPlayer.

function registerMediaPlayerEvents() {
    // MediaPlayer events
    mediaPlayer.addEventListener("error", onError);
    mediaPlayer.addEventListener("warning", onWarning);
    mediaPlayer.addEventListener("cueEnter", onCueEnter);
    mediaPlayer.addEventListener("cueExit", onCueExit);
    mediaPlayer.addEventListener("play_bitrate", onPlayBitrateChanged);
    mediaPlayer.addEventListener("download_bitrate", onDownloadBitrateChanged);
    mediaPlayer.addEventListener("manifestUrlUpdate", onManifestUrlUpdate);
    mediaPlayer.addEventListener("metricAdded", onMetricAdded);
    mediaPlayer.addEventListener("metricChanged", onMetricChanged);
    mediaPlayer.addEventListener("bufferLevel_updated", onBufferLevelUpdated);
    mediaPlayer.addEventListener("state_changed", onStateChanged);
    // <video> element events
    mediaPlayer.addEventListener("loadeddata", onload);
    mediaPlayer.addEventListener("play", onPlay);
    mediaPlayer.addEventListener("pause", onPause);
    mediaPlayer.addEventListener("timeupdate", onTimeUpdate);
    mediaPlayer.addEventListener("volumechange", onVolumeChange);
};

For instance, callback function looks like this :

function onPlayBitrateChanged(e) {
    handlePlayBitrate(e.detail.bitrate, e.detail.time);
};

Documentation

Full API Documentation is available describing MediaPlayer public methods and events.

This API documentation can be generated using following gulp command:

npm run doc

Tested With