Giter Site home page Giter Site logo

joaopaulovieira / clappr-media-control-plugin Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 1.0 29.68 MB

Base media control plugin + media control components to create beautiful experiences of video consumption on Clappr.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 93.14% HTML 2.38% CSS 0.36% Shell 0.33% SCSS 3.79%
clappr media-control video-player video-controls video-consumption media-player clappr-plugin clappr-plugins clappr-player

clappr-media-control-plugin's Introduction

npm bundle size PRs Welcome Travis (.com) Coveralls github

Clappr Media Control plugin


Demo

https://joaopaulovieira.github.io/clappr-media-control-plugin/

Features

โœจ Simple structure

With a structure with few abstractions (layers, sections, and elements), understanding how to build a media control is easier and helps to achieve the wanted experience in the video consumption.

๐Ÿ“ฑ/๐Ÿ’ป/๐Ÿ–ฅ๏ธ Responsive by default

Using flexbox, all components are positioned to ensure the best use in a wide range of video consumption environments.

๐Ÿ”Œ Add more components using Clappr plugin architecture

The architecture of the media control was built to facilitate the addition of new elements in the interface via plugins of the category MediaControlComponents, following the extensibility mindset of Clappr. (More info about MediaControlComponents here.)

๐Ÿงฐ Highly customizable

It's possible to configure from the number of layers/sections, to how the sections within a specific layer (or an element within a specific section) should be positioned! With this level of customization, it is possible to create an infinite range of interfaces. See examples of interfaces here.

๐ŸŽฌ Minimal configuration for standard use

Don't want to customize anything to have a functional media control? Just load the media control plugin and the main components and that's it! You will have a media control just like the gif of illustration.

Structure

Thinking of a minimalist architecture that needs to supports a high degree of customization, the entire structure of media control is summarized with three concepts: Layers, Sections, and Elements (MediaControlComponents).

Layers

One layer holds all the space available in the Clappr core element, making this entire area available to be subdivided into sections. A layer can also have only one section.

Sections

Represents a portion of a layer. Sections can be varied in size and be oriented on the X or Y axis of a layer. Sections are also the area where media control elements are to be rendered.

Elements (MediaControlComponents)

They are Clappr core plugins that extend from a base class created to standardize the creation of components for media control. These elements can only be rendered within a section.

Media Control Components

This base class has getters and behaviors that were designed to facilitate the configuration and creation of components for the media control.

There are getters that must be overwritten for the correct component configuration. It's them:

MediaControlComponentPlugin.layer

It must return the id of the layer to which the section that the plugin has to be rendered belongs.

MediaControlComponentPlugin.section

It must return the id of the section that the plugin has to be rendered.

MediaControlComponentPlugin.position

It should return the id of the position that the plugin has to be rendered within the wanted section. In horizontal sections, the order of position will be from left to right and in vertical sections, the order will be from top to bottom.

There are getters that can be overwritten but are not mandatory. It's them:

MediaControlComponentPlugin.separator

Returns false by default. If it's overwritten to return the value true, it will cause the plugin to be rendered at the opposite point from the starting position and causing all rendered plugins after it to follow the same rendering order.

You can see all MediaControlComponentPlugin code here.

Usage

Before starting the plugin, you need to get it. The two most used ways of doing this are:

Loading as an external script from any npm.js public CDN (like JSDelivr):

https://cdn.jsdelivr.net/npm/@joaopaulo.vieira/clappr-media-control-plugin@latest/dist/clappr-media-control-plugin.min.js

or as an npm package:

# Using yarn
yarn add @joaopaulo.vieira/clappr-media-control-plugin

# Using npm
npm i @joaopaulo.vieira/clappr-media-control-plugin

Then just add MainPlugin and the other media control components into the list of plugins of your player instance:

var player = new Clappr.Player({
  source: 'http://your.video/here.mp4',
  plugins: [
    MediaControl.MainPlugin,
    MediaControl.PlayPauseButtonPlugin,
    MediaControl.VolumePlugin,
    MediaControl.FullscreenButtonPlugin,
    MediaControl.SeekBarPlugin,
    MediaControl.TimeIndicatorPlugin,
    ]
});

In this project, the order of loading plugins in Clappr does not matter as both MediaControlPlugin and MediaControlComponentPlugin have mechanisms to guarantee the rendering of all elements.

Configuration

For specific component configs, check this table.

The options for the plugin go in the mediaControl property as shown below:

var player = new Clappr.Player({
  source: 'http://your.video/here.mp4',
  plugins: [MediaControl.MainPlugin],
  mediaControl: {
    disableBeforeVideoStarts: false,
    layersQuantity: 1,
    layersConfig: [
      {
        id: 1,
        sectionsQuantity: 1,
        flexDirection: 'column',
        sectionsConfig: [
          {
            id: 1,
            separator: true,
            height: '100%',
            width: '100%',
            alignItems: 'stretch',
            justifyContent: 'flex-start',
            flexGrow: 0,
          }
        ]
      }
    ]
  }
});

disableBeforeVideoStarts {Boolean}

Sets whether the media control is visible before the media even starts to play.

layersQuantity {Integer}

Defines the number of layers that will be created in the media control.

layersConfig {Array}

An array where each item is an object representing one layer config. One layer config item can have id, sectionsQuantity, flexDirection and sectionsConfig attributes.

layersConfig[n].id {Integer}

Identifies the layer that will use the configs belonging to the same scope as this config.

layersConfig[n].sectionsQuantity {Integer}

Defines the number of sections that will be created in the selected layer via the attribute id.

layersConfig[n].flexDirection {String}

Defines the orientation of the sections created within a layer. It uses the flex-direction property as a basis, and can only receive the same values that this property supports.

layersConfig[n].sectionsConfig {Array}

An array where each item is an object representing one section config. One section config item can have id, separator, height, width, alignItems, justifyContent and flexGrow attributes.

layersConfig[n].sectionsConfig[n].id {Integer}

Identifies the section that will use the configs belonging to the same scope as this config.

layersConfig[n].sectionsConfig[n].separator {Integer}

Sets the configured section to be positioned at the opposite end of the starting position of a section.

layersConfig[n].sectionsConfig[n].height {String}

Specifies the height of the selected section. It uses the height property as a basis, and can only receive the same values that this property supports.

layersConfig[n].sectionsConfig[n].width {String}

Sets the width of the selected section. It uses the width property as a basis, and can only receive the same values that this property supports.

layersConfig[n].sectionsConfig[n].alignItems {String}

Align elements on the cross axis inside of the selected section. It uses the align-items property as a basis, and can only receive the same values that this property supports.

layersConfig[n].sectionsConfig[n].justifyContent {String}

Align elements along the main axis inside of the selected section. It uses the justify-content property as a basis, and can only receive the same values that this property supports.

layersConfig[n].sectionsConfig[n].flexGrow {Integer}

Defines the growth factor of the selected section inside one layer. It uses the flex-grow property as a basis, and can only receive the same values that this property supports.

Examples

Example 1:

    Configs:
    DOM tree:
    UI:

Example 2:

    Configs:
    DOM tree:
    UI:

Example 3:

    Configs:
    DOM tree:
    UI:

Example 4:

    Configs:
    DOM tree:
    UI:

Advanced Usage

It is also possible to import only the structure of the media control without any default components, giving you the possibility to create all the components of a media control the way you want and avoiding importing unnecessary code for your purposes!

For this, there is a bundle that has only the main media control plugin and the base class for creating components. You can download directly via a public CDN that exposes npm.js packages:

https://cdn.jsdelivr.net/npm/@joaopaulo.vieira/clappr-media-control-plugin@latest/dist/light-clappr-media-control-plugin.min.js

Or install via npm package:

# Using yarn
yarn add @joaopaulo.vieira/clappr-media-control-plugin

# Using npm
npm i @joaopaulo.vieira/clappr-media-control-plugin

and when importing, use the path that leads directly to this bundle:

import { MainPlugin, BaseComponentPlugin } from '@joaopaulo.vieira/clappr-media-control-plugin/dist/light-clappr-media-control-plugin'

Development

Install dependencies: npm install

Run: npm start

Test: npm test

Lint: npm run lint

Build: npm run build

Minified version: npm run release

clappr-media-control-plugin's People

Contributors

joaopaulovieira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

myjeffxie

clappr-media-control-plugin's Issues

fullscreen icon does not change

hi,
After clicking on fullscreen icon to be in fullscreen, icon change to be back on window mode... but when I'm back in window mode in clicking on escape key, icon doesn't change again, so it stays with icon to switch in window mode

image

so it should change

thanks
Nico

feature requests

hi,

That would be great to introduce text like in old clappr

  • when stream is live : Live
  • when dvr : Back to live
    With progress bar colored (blue/red).

Maybe icons (play/stop, volume...) could be smaller/thiner and on the same layer than progress bar to limit space taken on the player (more like it was in old clappr)

thanks
nico

Play button is not available on large screens

I integrated this plugin with clappr on a web video streaming project. However, If I load the page on a large screen, if I stop the video, there is no button to play it again unless I refresh the page

FullscreenButtonPlugin - fullscreenComponent not visible on IOS Devices

Im not sure if this is a bug or like its intended to be.

When i build a custom UI with a "FullscreenButtonPlugin" its visible in normal Browsers and disappears in mobile Browsers on my IOS Devices. Tested in Safari and Chrome.

All other Components of the Player config are there like "seekBarComponent" and "playPauseComponent" and so on. Only the "fullscreenComponent" is missing. The default UI of Clappr shows this feature in his controls.

I tried to use this, because Clappr default UI lacks in support for touch events on the SeekbarComponent. To bad that this issue blocks me so far.

Issue:

  • fullscreenComponent not visible on IOS Devices

wanted behavior:

  • fullscreenComponent is visible on IOS devices like in Browsers on Desktop

But besides this issue... great plugin for Clappr!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.