Clappr

An extensible media player for the web.

README

Huge changes in the latest version. See 0.4.0 version changelog for more information

jsDelivr hits (npm scoped)


#

Clappr is an extensible media player for the web. Your architecture is projected primarily into plugins, adding low accoupling by design to the project and the possibility to add infinitely features easily.

Clappr uses by default the HTMLVideoElement which guarantees support to many platforms. You have the possibility to extends the default HTML5 playback or the playback interface to create one new media support just like a plugin!

Clappr is a composition of two other projects: @clappr/core and @clappr/plugins.

The @clappr/core contains the basic functionalities from Clappr (plugin architecture, class abstractions, public interfaces, events handlers and etc) and the @clappr/plugins are the repository where the plugins maintained by the Clappr team lives. More info about those projects into your repositories.

All Clappr projects are written in *.js using the latest features of ECMAScript.

Clappr is under development but production-ready. Feel free to open issues and send pull requests.

:triangular_flag_on_post: Table of Contents

:clapper: Usage

Via script tag:


Add the following script on your HTML:
  1. ``` html
  2. <head>
  3.   <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@clappr/player@latest/dist/clappr.min.js"></script>
  4. </head>
  5. ```
Now, create the player:
  1. ``` html
  2. <body>
  3.   <div id="player"></div>
  4.   <script>
  5.     var player = new Clappr.Player({source: "http://your.video/here.mp4", parentId: "#player"});
  6.   </script>
  7. </body>
  8. ```

:video_camera: Demo
Live demo to test, with a possibility to add external plugins.

:books: API Documentation
You can check the current API doc via @clappr/core here.

:hammer_and_wrench: Configuration
You can check the embed parameters supported by @clappr/core here.

:electric_plug: Built-in Plugins
You can check the plugins used on Clappr player via @clappr/plugins here.

:handshake: Third party plugins/integrations

External Plugins


|Plugin|Status|Compatible|URL|
|-----------------------|--------|-------------------------------|--------------------------------------------------------|
|MediaReadyYes
|VideoReadyYes
|ThumbnailsReadyYes
|MarkersReadyYes
|LevelReadyYes
|360ReadyYes
|Chromecast|Yeshttps://github.com/clappr/clappr-chromecast-plugin
|DASHReadyYes
|PlaybackReadyYes
|ClapprReadyYes
|ClapprReadyYes
|PauseReadyYes
|RTMPReadyYes
|Picture-in-PictureReadyYes
|HybridReadyYes
|CommentsReady?
|VoiceReady?
|DashWIPNo
|YoutubeReadyNo
|GoogelReadyYes
|VASTWIPNo
|DynamicReadyYes
|ScrollReadyYes
|PlaybackReadyYes
|FLVReadyYes
|ContextReadyYes

External Integrations


|Integration|Status|Compatible|URL|
|-----------------------|--------|-------------------------------|--------------------------------------------------------|
|P2PReadyYes


:film_strip: Supported Formats

Format         |HLS|MP4|MP3|WEBM| DASH | RTMP | JPG/PNG/GIF | FLV |
IE10           | ✔ | ✔ | ✔ |  ✘ | ✘ | rtmp | ✔ | ✘
IE11           | ✔ | ✔ | ✔ |  ✘ | rtmp | rtmp | ✔ | rtmp
Microsoft Edge | ✔ | ✔ | ? |  ? | rtmp | rtmp | ? | rtmp
Firefox        | ✔ | ✔ | ✔ |  ✔ | rtmp | rtmp | rtmp | rtmp
Chrome         | ✔ | ✔ | ✔ |  ✔ | rtmp | rtmp | ✔ | rtmp
Safari         | ✔ | ✔ | ✔ |  ✘ | rtmp | rtmp | rtmp | rtmp
iPhone         | ✔ | ✔ | ✔ |  ✘ | ✘ | ✘ | ✔ | ✘
iPad           | ✔ | ✔ | ✔ |  ✘ | ✘ | ✘ | ✔ | ✘
Android        | ✔ | ✔ | ✔ |  ✘ | rtmp | rtmp | ✘ | rtmp
WiiU Browser   | ✔ | ✔ | ✘ |  ? | rtmp | rtmp | ✘ | ?
PS4 Browser    | ✔ | ✔ | ✘ |  ? | rtmp | rtmp | ✘ | ?

rtmp means that the support is made by an external plugin.

:play_or_pause_button: About Autoplay
Clappr has no control over autoplay Browser Policy.

Therefore, we're not able to execute play and unmute actions sequentially in every situation. There are a series of scenarios where the Browser blocks these actions based on it’s own policy.

Each browser has their own different restrictions, and the usual behavior is to activate the sound only after an user interaction with the player.

For more infos about auto play video policy, you can read these docs:


:interrobang: FAQ & Troubleshooting

How to write a plugin?

See the wiki for more info.

How can I disable or override a plugin?

Let's say you want to disable or override a plugin.

Disable a plugin

  1. ``` js
  2. // let's disable the loading animation (the 'spinner' plugin)
  3. var player = new Clappr.Player({ ... });
  4. // after attach
  5. player.getPlugin('spinner').disable();
  6. ```

Override a plugin

  1. ``` js
  2. // let's disable the loading animation (the 'spinner' plugin)
  3. export default class NoSpinner extends UIContainerPlugin {
  4.   get name() { return 'spinner' }
  5. }
  6. new Clappr.Player({ plugins: [NoSpinner]})
  7. ```

How can I use clappr with ReactJS?

https://medium.com/@bikegriffith/using-clappr-with-reactjs-14a338e3451f#.9a36w0dpj

How can I use clappr with ionic/angular?

https://github.com/clappr/clappr/issues/933#issuecomment-228540381

How can I Log messages with Clappr?

Add this snippet before you instantiate the player Clappr.Log.setLevel(0)

Common steps to verify issues

Very often people open issues related to stream not working, freezing, glitching, stopping, and so on. You can try the steps below, taking notes about the results:

try to run the same example at CDN
try to run it on hls.js demo page
try to run it on flashls. demo page
try to run on your page the following source: http://www.streambox.fr/playlists/x36xhzz/x36xhzz.m3u8
try different browsers/OS's to see if the problems remain
try to use a tool to check the health of your stream (both input, ie: RTMP, and segmentation, ie: DASH or HLS): like [mediainfo](https://mediaarea.net/MediaInfo) (for instance you could: mediainfo http://www.example.com/my.m3u8, Apple's [mediastreamvalidator](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/UsingHTTPLiveStreaming/UsingHTTPLiveStreaming.html) too, [hls-analyzer](https://github.com/epiclabs-io/hls-analyzer) and etc.

  1. ``` sh
  2. //HLS-Analyzer usage example

  3. pip install m3u8
  4. git clone https://github.com/epiclabs-io/hls-analyzer.git
  5. cd hls-analyzer
  6. python hls-analyzer.py http://www.streambox.fr/playlists/x36xhzz/x36xhzz.m3u8
  7. ```

How to handle player fatal errors?

Player fatal errors can be handled using onError API event.

  1. ``` js
  2. var player = new Clappr.Player({
  3.   parent: '#myplayer',
  4.   source: 'http://path.to/my/video.mp4',
  5.   events: {
  6.     onError: function(e) {
  7.       // Here the code to handle the error
  8.     }
  9.   }
  10. });
  11. ```

Note: the type of error event object depends on the type of the playback component resolved to play the video.

Example

This is a simple example using the no_op playback to display error messages.

You can try the following Javascript code on Clappr demo page:

  1. ``` js
  2. var playerElement = document.getElementById("player-wrapper");

  3. var r = 3; // Retry attempts

  4. var player = new Clappr.Player({
  5.   // source: 'http://clappr.io/highline.mp4',
  6.   source: 'http://clappr.io/bad_highline.mp4',
  7.   disableErrorScreen: true, // Disable the internal error screen plugin
  8.   height: 360,
  9.   width: 640,
  10.   events: {
  11.     onError: function(e) {
  12.       r--;
  13.       var s = player.options.source;
  14.       // Replace previous line by the following line to simulate successful recovery
  15.       // var s = (r > 2) ? player.options.source : 'http://clappr.io/highline.mp4';
  16.       var t = 10;
  17.       var retry = function() {
  18.         if (t === 0) {
  19.           var o = player.options;
  20.           o.source = s;
  21.           player.configure(o);
  22.           return;
  23.         }
  24.         Clappr.$('#retryCounter').text(t);
  25.         t--;
  26.         setTimeout(retry, 1000);
  27.       };
  28.       player.configure({
  29.         autoPlay: true,
  30.         source: 'playback.error',
  31.         playbackNotSupportedMessage: 'Network fatal error.' + ((r > 0)
  32.             ? ' Retrying in <span id="retryCounter"></span> seconds ...'
  33.             : ' All retry attempts failed'),
  34.       });
  35.       if (r > 0) {
  36.         retry();
  37.       }
  38.     }
  39.   }
  40. });

  41. player.attachTo(playerElement);
  42. ```

Another example

This example use a custom error container plugin to display error messages.

You can try the following Javascript code on Clappr demo page:

  1. ``` js
  2. var playerElement = document.getElementById("player-wrapper");

  3. var ErrorPlugin = Clappr.ContainerPlugin.extend({
  4.   name: 'error_plugin',
  5.   background: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAFoBAMAAAA1HFdiAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAG1BMVEX5+fn//wAA//8A/wD/AP//AAAAAP8XFxf///8H5gWfAAAAAWJLR0QIht6VegAAAAd0SU1FB98IBRIsAXmGk48AAAI5SURBVHja7dJBDYBADADBs4AFLGABC1iohbOPhv1BMvu+NLlp10odqTN1pe7Uk5pQ8wMIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECDA/wKWxzM71T7ZZrfltNnppgACBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAL8B+ALjSfYzPnmdzgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNS0wOC0wNVQxODo0NDowMSswMTowMCL95a4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTUtMDgtMDVUMTg6NDQ6MDErMDE6MDBToF0SAAAAAElFTkSuQmCC',
  6.   bindEvents: function() { this.listenTo(this.container, Clappr.Events.CONTAINER_ERROR, this.onError) },
  7.   hide: function() { this._err && this._err.remove() },
  8.   show: function() {
  9.     var $ = Clappr.$
  10.     this.hide();
  11.     var txt = (this.options.errorPlugin && this.options.errorPlugin.text) ? this.options.errorPlugin.text : 'A fatal error occured.';
  12.     this._err = $('<div>')
  13.       .css({
  14.         'position': 'absolute',
  15.         'z-index': '999',
  16.         'width': '100%',
  17.         'height': '100%',
  18.         'background-image': 'url(' + this.background + ')',
  19.         'background-size': 'contain',
  20.         'background-repeat': 'no-repeat',
  21.         'padding-top': '15%',
  22.         'text-align': 'center',
  23.         'font-weight': 'bold',
  24.         'text-shadow': '1px 1px #fff',
  25.       })
  26.       .append($('<h2>')
  27.         .text(txt)
  28.         .css({
  29.           'font-size': '200%',
  30.         }))
  31.       .append($('<p>').html('Retrying in <span class="retry-counter">10</span> seconds ...')
  32.         .css({
  33.           'font-size': '120%',
  34.           'margin': '15px',
  35.         }));
  36.     this.container && this.container.$el.prepend(this._err);
  37.   },
  38.   onError: function(e) {
  39.     if (!this.container) return;
  40.     this.show();
  41.     this.container.getPlugin('click_to_pause').disable();
  42.     var tid, t = 10, retry = function() {
  43.       clearTimeout(tid);
  44.       if (t === 0) {
  45.         this.container.getPlugin('click_to_pause').enable();
  46.         if (this.options.errorPlugin && this.options.errorPlugin.onRetry) {
  47.           this.options.errorPlugin.onRetry(e);
  48.           return;
  49.         } else {
  50.           this.container.stop();
  51.           this.container.play();
  52.           return;
  53.         }
  54.       }
  55.       $('.retry-counter').text(t);
  56.       t--;
  57.       tid = setTimeout(retry, 1000);
  58.     }.bind(this);
  59.     retry();
  60.   }
  61. });

  62. var player = new Clappr.Player({
  63.   disableErrorScreen: true, // Disable the internal error screen plugin
  64.   source: 'http://clappr.io/bad_highline.mp4',
  65.   plugins: [ErrorPlugin],
  66.   errorPlugin: {
  67.     // text: 'My custom error message.',
  68.     onRetry: function(e) {
  69.       // simulate successful recovery
  70.       // or decide here what to do between each retry
  71.       player.configure({
  72.         source: 'http://clappr.io/highline.mp4',
  73.         autoPlay: true,
  74.       });
  75.     }
  76.   },
  77.   height: 360,
  78.   width: 640
  79. });

  80. player.attachTo(playerElement);
  81. ```

:rocket: Companies using Clappr
https://github.com/clappr/clappr/issues/522

:raised_hands: Contributors
This project exists thanks to all the people who contribute.

:star2: Sponsor