Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vlitejs

vlitejs5.5kMIT7.3.1

vLitejs is a fast and lightweight Javascript library for customizing video and audio player in Javascript with a minimalist theme (HTML5, Youtube, Vimeo, Dailymotion)

video, audio, html5, youtube, vimeo, dailymotion, player, youtube api, vimeo api, pip, picture-in-picture, subtitle, cast, chromecast, airplay, monetization, ima-sdk, sticky, volume bar, hotkeys

readme

vLitejs

GitHub Workflow Status (branch) jsDelivr

vLitejs logo

vlitejs (pronounced /viːlaɪt/) is a fast and lightweight JavaScript library for customizing video and audio player. Written in native JavaScript without dependency, it is built around an API of providers and plugins to extend these capabilities and keep the core with the minimal functionalities.

HTML5 video and audio players are automatically included. Other providers like Youtube or Vimeo can be loaded on demand with the Provider API. Plugins uses the same logic and can be loaded on demand by the Plugin API. Others providers and plugins can be created and loaded by the library.

Why vLitejs?

  • If you are concerned about your app's loading performance, this library makes sense as it is extremely lightweight compared to the competition (only 6 KB).
  • It is quite rare to need to be compatible with HTML5, Youtube, Vimeo and Dailymotion at the same time. The library contains by default only HTML5 capabilities and exposed the Provider API to extend capabilities with other providers.
  • If you need specific behaviors, the plugin API allows to extends the library capabilities.
  • If you need to create a video or audio player with a custom skin harmonized for all web browsers.

Sizes of the vlitejs bundle compared to the competition:

| | vlitejs | plyr | video.js | | ------------ | :-------: | :----: | :--------: | | Uncompressed | 68 KB | 299 KB | 2100 KB | | Compressed | 27 KB | 110 KB | 560 KB | | Gzip | 6 KB | 32 KB | 159 KB |

Note vlitejs 5.0.1, plyr 3.7.8, videojs 8.3.0


Features

  • Video & audio - HTML5 video, HTML5 audio, Youtube, Vimeo, Dailymotion.
  • Customization - Choose the control elements you want to display.
  • No dependency - Written in native Javascript without any framework.
  • Fullscreen - Supports native fullscreen API.
  • Provider API - Use the available providers or create your own.
  • Plugin API - Use the available plugins or create your own.
  • Streaming - Support HLS.js streaming playback.
  • Sticky - Support for sticky.
  • Events - Standardized events for all web browsers, providers and plugins.
  • Autoload API - Youtube, Vimeo and Dailymotion API are automatically loaded by their provider.
  • Subtitles - Supports multiple subtitle tracks (VTT).
  • Picture-in-Picture - Supports Picture-in-Picture API.
  • Cast - Supports for Google Cast API.
  • AirPlay - Supports for Apple AirPlay API.
  • Monetization - Supports for Google IMA SDK.
  • Hotkeys - Supports for hotkeys to add keyboard shortcuts.
  • Playsinline - Supports the playsinline attribute.
  • SVG icons - SVG are inlined into the library, no sprites to includes.
  • Accessibility - W3C and A11Y valid.

Image of vLitejs

:sparkles: You can support this project with GitHub Sponsors! ♡

Playground

If you're interested in playing around with vLitejs, you can use the online code playgrounds on Glitch:

Examples

The project includes several examples of vlitejs implementation in the directory examples. Run the following commands to build the assets for the examples:

npm run build && npm run build:example

Installation

Warning vlitejs@6 is ESM and uses the Node.js package exports.

NPM

NPM is the recommended installation method. Install vlitejs in your project with the following command:

npm install vlitejs --save-dev
yarn add vlitejs --dev

Note Minimum supported Node.js version is 16.20.0.

CDN

You can also download it and include it with a script tag as an ESM.

<link href="https://cdn.jsdelivr.net/npm/vlitejs@6/dist/vlite.css" rel="stylesheet" crossorigin />
<script type="module">
  import Vlitejs from 'https://cdn.jsdelivr.net/npm/vlitejs@6';
</script>

Note You can browse the source of the NPM package at jsdelivr.com/package/npm/vlitejs.

How it works

HTML

HTML5 video

<video id="player" src="<path_to_video_mp4>"></video>

HTML5 audio

<audio id="player" src="<path_to_audio_mp3>"></audio>

Youtube

<div id="player" data-youtube-id="<video_id>"></div>

Vimeo

<div id="player" data-vimeo-id="<video_id>"></div>

Dailymotion

<div id="player" data-dailymotion-id="<video_id>"></div>

Initialization

Import vlitejs styleheet and the JavaScript library as an ES6 modules.

import 'vlitejs/vlite.css';
import Vlitejs from 'vlitejs';

The vlitejs constructor accepts the following parameters:

Arguments Type Default Description
selector String|HTMLElement null Unique CSS selector string or HTMLElement to target the player
config Object {} Player configuration (optional)

Initialize the player with a CSS selector string.

new Vlitejs('#player');

Or, initialize the player with an HTMLElement.

new Vlitejs(document.querySelector('#player'));

Configuration

The second arguments of the contructor is an optional object with the following parameters:

Arguments Type Default Description
options Object {} Player options
onReady Function|null null Callback function executed when the player is ready
provider String 'html5' Player provider
plugins Array [] Player plugins
new Vlitejs('#player', {
  options: {},
  onReady: function (player) {},
  provider: 'html5',
  plugins: []
});

Options

The player controls can be customized with the following parameters:

Options Type Default Description
controls¹ ² Boolean true Display the control bar of the video
autoplay Boolean false Enable the autoplay of the media
playPause Boolean true Display the play/pause button on the control bar
progressBar Boolean true Display the progress bar on the control bar
time Boolean true Display the time information on the control bar
volume Boolean true Display the volume button on the control bar
fullscreen¹ ⁴ Boolean true Display the fullscreen button on the control bar
poster¹ String|null null Customize the video poster url
bigPlay¹ Boolean true Display the big play button on the poster video
playsinline¹ Boolean true Add the playsinline attribute to the video
loop Boolean false Whether to loop the current media
muted¹ Boolean false Whether to mute the current media
autoHide¹ Boolean false Auto hide the control bar in the event of inactivity
autoHideDelay¹ Integer 3000 Auto hide delay in millisecond
providerParams³ Object {} Overrides the player parameters of the provider

Note

The autoplay parameter automatically activates the muted option because the API can only be initiated by a user gesture (see Autoplay policy changes).

Example of customization for the autoHide and the poster options.

new Vlitejs('#player', {
  options: {
    autoHide: true,
    poster: '/path/to/poster.jpg'
  }
});

Player ready

The callback function onReady is automatically executed when the player is ready. The HTML5 video and audio listen to the canplay|loadedmetadata event. The Youtube, Vimeo and Dailymotion provider listen to the onready event returned by their API.

The function exposes the player parameter as the player instance. You can use it to interact with the player instance and the player methods.

Example of a player muted when ready:

new Vlitejs('#player', {
  onReady: function (player) {
    player.mute();
  }
});

Note The onReady function can also be written with an arrow function.

Events

vlitejs exposes the following native Event on the .v-vlite element. Events are standardized for all providers. Each plugin has its own events which are detailed in their dedicated documentation.

Event Type Description
play Sent when the playback state is no longer paused, after the play method or the autoplay
pause Sent when the playback state is changed to paused
progress Sent periodically to inform interested parties of progress downloading the media.
timeupdate Sent when the currentTime of the media has changed
volumechange Sent when audio volume changes
enterfullscreen¹ Sent when the video switches to fullscreen mode
exitfullscreen¹ Sent when the video exits fullscreen mode
ended Sent when playback completes

Note > ¹ Video only.

Example of a listener when the media triggers a play event.

new Vlitejs('#player', {
  onReady: (player) => {
    player.on('play', () => {
      // The video starts playing
    });
  }
});

Methods

The player instance exposes the following methods, accessible when the player is ready.

Method Parameters Promise Description
play() - - Start the playback
pause() - - Pause the playback
setVolume(volume) Number - Set the volume between 0 and 1
getVolume() - Promise Get the volume
getCurrentTime() - Promise Get the current time
getDuration() - Promise Get the duration
mute() - - Mute the volume
unMute() - - Unmute the volume
seekTo(time) Number - Seek to a current time in seconds
requestFullscreen() - - Request the fullscreen
exitFullscreen() - - Exit the fullscreen
getInstance() - - Get the player instance
loading() Boolean - Set the loading status
on(event, function) String, Function - Add an event listener
off(event, function) String, Function - Remove an event listener
destroy() - - Destroy the player

Example of media duration recovery.

new Vlitejs('#player', {
  onReady: (player) => {
    player.getDuration().then((duration) => {
      // The duration is available in the "duration" parameter
    });
  }
});

Custom CSS properties

The player exposes some custom CSS properties, locally scopped under the .v-vlite selector. You can use them to customize the design.

Name Value Description
--vlite-colorPrimary #ff7f15 Primary color
--vlite-transition 0.25s ease Transition
--vlite-controlBarHeight 50px Control bar height
--vlite-controlBarHorizontalPadding 10px Control bar horizontal padding
--vlite-controlBarBackground linear-gradient(to top, #000 -50%, transparent) Control bar background
--vlite-controlsColor #fff|#000 Controls color (video|audio)
--vlite-controlsOpacity 0.9 Controls opacity
--vlite-progressBarHeight 5px Progress bar height
--vlite-progressBarBackground rgba(0 0 0 / 25%) Progress bar background

Contributors

Many thanks to Victor Schirm for the vlitejs logo.

License

vlitejs is licensed under the MIT License.

Created with ♡ by @yoriiis.

changelog

CHANGELOG

7.3.1

Fixes

  • Prevent vertical scroll page on the volume hotkeys by @rtritto (#168)

7.3.0

Updates

7.2.1

Fixes

  • Update loader overlay to make the control bar accessible during loading by @rtritto (#155)

7.2.0

Fixes

Updates

  • Remove useless v-fullscreenButtonDisplay class and add v-fullscreen as a state class by @rtritto (#156)
  • Use abstract annotation in Player.ts by @rtritto (#157)

7.1.0

New features

  • Add options to customize the shortcuts value of volume and seek by @rtritto (#152)

7.0.0

⚠️ Breaking changes

  • Updates Node.js (#146)
    • Minimum supported Node.js version is 20.18.0
    • Updates other packages
    • Migrate ESLint/Prettier to Biome

New features

  • Add the volume bar plugin (#90)
  • Add the sticky plugin (#99)

6.0.5

Fixes

  • Fix poster display after the first playback, isPaused is reset on media end (#144)

6.0.4

Fixes

  • Fix duration when preload is disabled (#136)

6.0.3

Fixes

  • Fix Firefox progress bar height (#129)
  • Add Youtube origin parameter (#130)

6.0.2

Fixes

  • Increase progress bar height (#119)
  • Fix preload on html5 provider (#118)

6.0.1

Fixes

  • Added initial aria-label for bigPlay component (#115)

6.0.0

⚠️ Breaking changes

This package is now pure ESM. Please read Sindre Sorhus ESM note for more information

  • Migrate to ESM with package exports and rollup (#100)

5.0.2

Updates

  • Add funding key in package.json (31313e2)

5.0.1

Fixes

Updates

  • Update sticky plugin providers (f142964)

5.0.0

⚠️ Breaking changes

  • Minimum supported Node.js version is 16.20.0 (#97)
  • Update HTML (#99)
    • Remove vlite-js CSS classe
    • Remove v-controlButton on v-bigPlay
    • Add nested container v-container for sticky compatibility
  • Add css file for PIP plugin (#90)

New features

  • Add the volume bar plugin (#90)
  • Add the sticky plugin (#99)

Updates

  • Increase or decrease the volume by 0.1 and fix the round
  • Update README.md (#95, #96)
  • New directory structure (#98)

Removes

  • Remove animation on volume button (#90)

Fixes

  • Fix Dailymotion volume (#90)

4.2.0

New features

  • Add the Google IMA SDK plugin (#77)
  • Add the AirPlay plugin (#82)

Updates

  • Enable playsinline by default (f142964)
  • Call Vlitejs onReady function before the plugins onReady functions (7620e16)
  • Use native aspect-ratio for player responsive (b9816bc)
  • Disable fullscreen on iPhone (not supported yet) (49c9567)

4.1.2

Fixes

  • Fix multiple cast instance (#76)

4.1.1

Fixes

  • Fix default values for Cast plugin options (e0e492e)

4.1.0

New features

  • Add the Dailymotion provider (#73)
  • Add the Cast plugin (#72)

Fixes

  • Fix Youtube seekTo method conflicting with unstarted and unmuted video (#75)

4.0.7

Fixes

  • Fix progress bar height (#71)

4.0.6

Updates

  • Update environment (#67)

4.0.5

Fixes

  • Fix HTML5 event ready when the video is already loaded (#62)

New features

  • Add the autoHideDelay option (#63)

4.0.4

Optimize accessibility (#58)

Updates

  • Move keydown event to the player element instead of document
  • Player has the focus after the big play button click and after the subtitle button (inside the list) click
  • Add focus on first subtitle button when the subtitle menu is opened
  • Remove keydown restriction on specific tags (#57)
  • Limit keydown actions when the player or children's player has the focus
  • Refacto onKeyDown function by categories
  • Replace querySelector by cached elements
  • Refacto subtitle click event and use validateTarget for event delegation

Fixes

  • Fix auto hide broken with isPaused
  • Prevent focus to be captured by the iframe
  • Fix Youtube progress bar updates on tabulation navigation

4.0.3

Fixes

  • Fix provider queue by (#52)
  • Add new issue templates (#56)
  • Fix conflicts between native keyboard shortcuts and HTML form elements (#57 by @bfiessinger)

4.0.2

Fixes

  • Fix README issues (#43)
  • Fix mute option not transferred to the player (#48)
  • Fix play not triggered without the poster (#49)

4.0.1

Fixes

  • Fixed the default parameters and fix the selector HTMLDivElement (#43, #47)

4.0.0

⚠ Breaking changes

  • Rename window.vlitejs to window.Vlitejs to make sure the constructor name starts with a capital
  • Remove nativeControlsForTouch option
  • Remove data-options HTML attributes in favor of options from the JS constructor
  • Supports the latest 2 browsers versions with .browserslistrc
  • Remove the dist directory from GitHub, only available for NPM and CDN

New features

  • New design and new icons
  • Add Vimeo provider
  • Add Audio HTML5 provider
  • Add subtitle plugin
  • Add Picture-in-Picture plugin
  • Add a provider API to allow extension of current providers
  • Add a plugin API to allow extension of current plugins
  • Add sample-provider.js and sample-plugin.js for guidelines
  • Add multiple native Event fired on media actions (play, pause, etc.)
  • Add A11Y compatibility (<button>, <input type="range">, aria-*, :focus-visible)
  • Add the volume up/down shortcuts
  • Update HTML attributes from options and vice versa (autoplay, playsinline, muted, loop)

Updates

  • Convert to Typescript
  • Replace Travis by GitHub Action
  • Update to webpack v5
  • Update Babel config and .browserslistrc
  • Move formatVideoTime, checkSupportFullScreen, isTouch to utils
  • Split code into components (loader, overlay, big-play, poster, control-bar)
  • Remove MkDocs and docs directory, all docs are available in README files in the repository

Fixes

  • Fix the loop and muted attributes

3.0.4

Updates

  • Update dependencies

3.0.3

Fixes

  • Fixed strict node engine version break with different node version (#7)

3.0.2

Updates

  • Update docs and add .eslintignore

3.0.1

Updates

  • Update engines in package.json (node and npm)

3.0.0

New features

  • Add all sources of the vLitejs project, including:
    • CSS
    • JS
    • Documentation with MkDocs build
    • Webpack configuration
    • Examples
  • New folder structure
  • Add ESLint with Standard JS on the project with associated npm scripts
  • Add StyleLint configuration on the project with associated npm scripts
  • Add Babel configuration on the project
  • Add postCSS configuration on the project
  • Add browserslistrc files for browsers support
  • Add Travis builds: stylelint, eslint and mkdocs build
  • Add JSDoc configuration file and all code comments
  • Add Material for MkDocs to build the documentation website
  • Add Webpack configuration
  • Add ./examples folder with vLitejs examples
  • Add .github folder with ISSUE_TEMPLATE and PULL_REQUEST_TEMPLATE
  • Add ./dist folder with vLitejs assets
  • Add CHANGELOG file
  • Add .editorconfig file

Removed

  • Remove specific build file for html5 player only or youtube player only. We keep only one bundle compatible with html5 and youtube

Updates

  • Rename the export of the vLite constructor tovlitejs
  • Rename timeline option to progressBar
  • Rename callback option to onReady
  • Rename CSS class prefixes from .vl- to .v-
  • Rename all CSS class with FUN methodology

Fixes

  • Fix autoplay option that does not work with browser policy without user gesture. Muted option is forced to solved the problem.

2.0.1

New features

  • Add playsinline support
  • Add fast-forward on the video (+ or - 10s) only on no touch devices

Updates

  • Optimize unBindEvents function

Fixes

  • Fix bug with native control for touch devices

2.0.0

New features

  • Add prefix .vl- before all CSS classes use by vlitejs to prevent conflicts
  • Add keyboard shortcut (spacebar) to control the video
  • Add option autoHide to hide the control bar if the user is inactive
  • Add loader linked to seeking and seeked events

1.1.2

New features

  • Add progress bar hover and transition

Fixes

  • Prevent click catch by Youtube iframe which block player click

1.1.1

New features

  • Add UMD compatibility
  • Add package on npm

1.1.0

New features

  • First release of vLitejs
  • Update README