Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

vlitejs/vlite

Repository files navigation

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 theProvider API. Plugins uses the same logic and can be loaded on demand by thePlugin 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 thevlitejs bundle compared to the competition:

vlitejsplyrvideo.js
Uncompressed68 KB299 KB2100 KB
Compressed27 KB110 KB560 KB
Gzip6 KB32 KB159 KB

Notevlitejs 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 theplaysinline attribute.
  • SVG icons - SVG are inlined into the library, no sprites to includes.
  • Accessibility - W3C and A11Y valid.

Image of vLitejs

✨ You can support this project withGitHub Sponsors! ♡

Playground

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

Examples

The project includes several examples ofvlitejs implementation in the directoryexamples. 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 theNode.js packageexports.

NPM

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

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

Note Minimum supportedNode.js version is16.20.0.

CDN

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

<linkhref="https://cdn.jsdelivr.net/npm/vlitejs@6/dist/vlite.css"rel="stylesheet"crossorigin/><scripttype="module">importVlitejsfrom'https://cdn.jsdelivr.net/npm/vlitejs@6';</script>

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

How it works

HTML

HTML5 video

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

HTML5 audio

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

Youtube

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

Vimeo

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

Dailymotion

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

Initialization

Importvlitejs styleheet and the JavaScript library as an ES6 modules.

import'vlitejs/vlite.css';importVlitejsfrom'vlitejs';

Thevlitejs constructor accepts the following parameters:

ArgumentsTypeDefaultDescription
selectorString|HTMLElementnullUnique CSS selector string orHTMLElement to target the player
configObject{}Player configuration (optional)

Initialize the player with a CSS selector string.

newVlitejs('#player');

Or, initialize the player with anHTMLElement.

newVlitejs(document.querySelector('#player'));

Configuration

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

ArgumentsTypeDefaultDescription
optionsObject{}Player options
onReadyFunction|nullnullCallback function executed when theplayer is ready
providerString'html5'Player provider
pluginsArray[]Player plugins
newVlitejs('#player',{options:{},onReady:function(player){},provider:'html5',plugins:[]});

Options

The player controls can be customized with the following parameters:

OptionsTypeDefaultDescription
controls¹ ²BooleantrueDisplay the control bar of the video
autoplayBooleanfalseEnable the autoplay of the media
playPauseBooleantrueDisplay the play/pause button on the control bar
progressBarBooleantrueDisplay the progress bar on the control bar
timeBooleantrueDisplay the time information on the control bar
volumeBooleantrueDisplay the volume button on the control bar
fullscreen¹ ⁴BooleantrueDisplay the fullscreen button on the control bar
poster¹String|nullnullCustomize the video poster url
bigPlay¹BooleantrueDisplay the big play button on the poster video
playsinline¹BooleantrueAdd theplaysinline attribute to the video
loopBooleanfalseWhether to loop the current media
muted¹BooleanfalseWhether to mute the current media
autoHide¹BooleanfalseAuto hide the control bar in the event of inactivity
autoHideDelay¹Integer3000Auto hide delay in millisecond
providerParams³Object{}Overrides the player parameters of the provider

Note

Theautoplay parameter automatically activates themuted option because the API can only be initiated by a user gesture (seeAutoplay policy changes).

Example of customization for theautoHide and theposter options.

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

Player ready

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

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

Example of a playermuted when ready:

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

Note TheonReady function can also be written with an arrow function.

Events

vlitejs exposes the following nativeEvent 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 TypeDescription
playSent when the playback state is no longer paused, after the play method or the autoplay
pauseSent when the playback state is changed to paused
progressSent periodically to inform interested parties of progress downloading the media.
timeupdateSent when thecurrentTime of the media has changed
volumechangeSent when audio volume changes
enterfullscreen¹Sent when the video switches to fullscreen mode
exitfullscreen¹Sent when the video exits fullscreen mode
endedSent when playback completes

Note >¹ Video only.

Example of a listener when the media triggers aplay event.

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

Methods

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

MethodParametersPromiseDescription
play()--Start the playback
pause()--Pause the playback
setVolume(volume)Number-Set the volume between 0 and 1
getVolume()-PromiseGet the volume
getCurrentTime()-PromiseGet the current time
getDuration()-PromiseGet 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 mediaduration recovery.

newVlitejs('#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.

NameValueDescription
--vlite-colorPrimary#ff7f15Primary color
--vlite-transition0.25s easeTransition
--vlite-controlBarHeight50pxControl bar height
--vlite-controlBarHorizontalPadding10pxControl bar horizontal padding
--vlite-controlBarBackgroundlinear-gradient(to top, #000 -50%, transparent)Control bar background
--vlite-controlsColor#fff|#000Controls color (video|audio)
--vlite-controlsOpacity0.9Controls opacity
--vlite-progressBarHeight5pxProgress bar height
--vlite-progressBarBackgroundrgba(0 0 0 / 25%)Progress bar background

Contributors

Many thanks toVictor Schirm for thevlitejs logo.

License

vlitejs is licensed under theMIT License.

Created with ♡ by@yoriiis.


[8]ページ先頭

©2009-2025 Movatter.jp