New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vimeoplaylist

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimeoplaylist

Create endless video playlists with the Vimeo Player API, with

  • 2.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

📼 Vimeo Playlist

A pure JavaScript library to create a continous playlist of Vimeo Videos.

Simply define your markup and playlist template, pass an array of Vimeo IDs, profit 💵 💵 💵.

Demo Playlist→


Contents

  1. 📌 Features
  2. 🎯 Quickstart
  3. 🧬 Options
  4. 🤖 Commands
  5. 🕹️ Usage
  6. 📅 Todos

📌 Features

  • Builds a playlist of Vimeo Videos from an array of Vimeo IDs
  • Uses the Vimeo Player API
  • UI consists of Video Player, Playlist items (optional), Playlist controls (optional).
  • Super flexible - UI conforms to your structre / markup / selectors.
  • Playlist items authored via custom template (default included).
  • Supports continuous autoplay.
  • Customizable controls for navigation, play/pause, etc. Includes arrow key nav
  • Offers Fullscreen API control for Video player.
  • Supports Vimeo API options like width, color, player controls, muted, title
  • Hybrid NPM module, works with import and require

📦 Dependencies

  • @vimeo/player

🎯 Quickstart

1. Install from NPM

npm i vimeoplaylist

2. Define Markup

Create locations for Player, Nav and Playlist

<!-- Player -->
<div class="player">
  <div id="js-vp-player" class="player__vid"></div>
</div>

<!-- Playlist Nav -->
<nav class="playlist-nav">
  <button id="js-vp-prev" class="playlist-nav__prev"><i>←</i> Prev</button>
  <button id="js-vp-next" class="playlist-nav__next">Next <i>→</i></button>
</nav>

<!-- Playlist -->
<div id="js-vp-playlist" class="playlist"></div>
3. Create Playlist Item Template

Playlist items show info about the tracks (Ie: title, thumbnail, duraction, user, etc). Create a custom template literal (probaly as an external file) to display the info you'd like. The data paramater can access all video / user data returned by Vimeo respoinse object.

Full list of available properties here.

/**
 * Playlist Item Template
 * Each is item is wrapped in <article='plist-item'></article>
 * @param {obj} data - response object of video info from vimeo promise
 * @return {string} returns template literal
 */

// import included time formater util 
import {formatTime}  from 'vimeoplaylist'

export default function playlistTmpl(data) {
  let timeDuration = formatTime(data.duration)

  return `
    <a class="plist-item__link" data-vimeo-id="${data.id}" tabindex="0">
      <figure class="plist-item__thumb">
          <img class="plist-item__thumb-img" src="${data.thumbnail_large}"/>
      </figure>
      <div class="plist-item__main">
        <span class="plist-item__title">${data.title}</span>
        <span class="plist-item__user">${data.user_name}</span>
        <span class="plist-item__time-dur">${timeDuration}</span>
      </div>
    </a>
  `
}
4. Setup JS

Initizale the plugin on the defined selector, passing in options for our playlist template and playlist ids. (Complete list of Options found here )

import VimeoPlaylist from 'vimeoplaylist'

// Provide custom template for playist items
import playlistTmpl from './plist.tmpl'

// Plugin Options
let options = {
  hasPlaylist: true,
  playlistTmpl: playlistTmpl,
  playlist: [
    { "id": "288588748" },
    { "id": "328536852" },
    { "id": "281449879" }
  ]
}

// Create instance on id #js-player
let playlist = new VimeoPlaylist('js-vp-player', options)

// Init
playlist.init()
5. Provide Styles

Style as desired. While the core lib doesn't include styles, see the repo's demo project for styles that you can clone as a starting point.


🧬 Options

The options param supports the following properties:

OptionTypeDescriptionDefault
hasPlaylistBooleanMake false if you need endless vids, but not playlist uitrue
playlistOutputStringid or class to output playlist#js-vp-playlist
playlistNavPrevString / Element IDid of Prev nav element#js-vp-prev
playlistNavNextString / Element IDid of Next element#js-vp-next
playlistArray of Objectsplaylist as array of objects { "id" : }[]
playlistTemplateHTML Template LiteralTemplate for playlist ItemsTemplate found at plist.tmpl.js
supportsKeyNavBooleanEnables next/prev key navtrue
widthNumberVideo width in px900
titleBooleanShow video titlefalse
mutedBooleanMute vidsfalse
controlsBooleanShow player controlstrue
autoplayBooleanAutoplay vids (required for continuous playlist vids)true
fullScreenToggleBooleanClicking Enter triggers fullscreen vidfalse
colorString (3 or 6 digit hex value)Player ui color#7B8EF9
fullscreenToggleString / Element IDid of fullscreen video toggle control#js-vp-fstoggle
fullscreenToggleKeyCodeString / Element IDfull screen toggle keycodeDigit1

🤖 Project Commands

Install Project Deps

npm i

Build

npm run build

Builds src with microbundle to the various common js patterns.

Run Dev

npm run dev

Dev has microbundle begin watching / building the files, while also running the demo project via Parcel, which imports from the local src directory.

Run Demo

npm run demo:start

Runs the demo project via Parcel.

Lint

npm run lint


🕹️ Usage

Playlist Content

Playlists are created from Vimeo IDs.

Vimeo IDs can be provided to the playlist option directly, as an Array of objects, or as an external JSON file.

Creating playlist of Vimeo Ids
import VimeoPlaylist form 'vimeoplaylist'

// Plugin Options (with internal data array)
let options = {
  playlist: [
    { "id": "288588748" },
    { "id": "328536852" },
    { "id": "281449879" }
  ]
}

// Create instance
let vplaylist = new VimeoPlaylist('js-player', options)

// Init
vplaylist.init()
Vimeo IDs from JSON file

To use external JSON file, setup you JSON like so:

// playlist.json
[
  {
    "id": "288588748"
  },
  {
    "id": "328536852"
  },
  {
    "id": "281449879"
  }
  ....
Passing IDs as external JSON file (with Babel or Parcel)
import VimeoPlaylist from 'vimeoplaylist'
import data from '../data/playlist.json'

let options = {
  playlist: data,
  ...
}

// Create instance
let vplaylist = new VimeoPlaylist('js-player', options)

// Init
vplaylist.init()
Passing IDs as external JSON file with Request()
import VimeoPlaylist from 'vimeoplaylist'

const data = new Request('assets/data/playlist.json')

fetch(req)
  .then(response => response.json())
  .then(data => {
    let options = {
      hasPlaylist: true,
      playlistOutput: '#js-vp-playlist',
      playlist: data,
      ...
    }
    let vplaylist = new VimeoPlaylist('js-vp-player', options)
    vplaylist.init()
})

Markup / HTML

Construct your markup, adding IDs for the output of the:

  • Video player
  • Playlist list of items (optional)
  • Playlist nav prev and next controls (optional)
<!-- Player (main video embed)-->
<div id="js-vp-player"></div>

<!-- Playlist (list of vids) -->
<div id="js-vp-playlist"></div>

<!-- Playlist Nav -->
<nav class="playlist-nav">
  <button id="js-vp-prev" class="playlist-nav__prev"><i>←</i> Prev</button>
  <button id="js-vp-next" class="playlist-nav__next">Next <i>→</i></button>
</nav>

You can customize the target ids

let options = {
  hasPlaylist: true,
  playlistOutput: '#js-vp-playlist',
  playlistNavPrev: '#js-vp-prev'
  playlistNavNext: '#js-vp-next'
  fullscreenToggle:  '#js-vp-fstoggle',
  fullscreenToggleKeyCode: 'Digit1',
}

Playlist Item Template

The Playlist Items provide video and user info (ie: id, title, thubnails, url, duration, etc).

You can use the default template or provide your own template to customize the layout/markup of each playlist item. Simply create a template literal, perhaps as a seperate file, and pass its reference to the itemTemplate option.

Note: when a playlist item is playing, it will have an is-playing class to leverage.

Playlist Template Example
// plist.tmpl

/**
 * Plist Item Template
 * Contents below are wrapped in <article='plist-item'/>
 * @param {obj} data - response object of video info from vimeo promise
 * @return {string} returns template literal
 */
export default function playlistTmpl(data) {
  return `
    <a class="plist-item__link" data-vimeo-id="${data.id}" tabindex="0">
      <figure class="plist-item__thumb">
        <img class="plist-item__thumb-img" src="${data.thumbnail_large}"/>
      </figure>
      <div class="plist-item__main">
        <span class="plist-item__title">${data.title}</span>
        <span class="plist-item__user">${data.user_name}</span>
      </div>
    </a>
  `
}

Pass Playlist template

import playlistTmpl from './plist.tmpl'

let options = {
  hasPlaylist: true,
  playlistTmpl: playlistTmpl,
  ...
}
Available Vimeo Response Properties

Your template's data param can use to following properties from Vimeo's reponse object.

NameTypeDescription
descriptionStringVid details
durationnumberVid duration time
embed_privacystringPrivacy embed location, ie: 'anywhere
heightnumberpx height of vid
idnumberVid id
stats_number_of_commentsnumberNumber of comments
stats_number_of_likesnumberNumber of vid's likes
stats_number_of_playsnumberNumber of vid's plays
tagsstringComma seperated tags
thumbnail_large(string|link)Large format vid thumb
thumbnail_medium(string|link)Med format vid thumb
thumbnail_small(string|link)Small format thumb
titlestringVid title
upload_date(string|date)Upload date ie "2019-01-18 10:22:32"
url(string|link)Vid URL
user_idnumberUser ID
user_namestringUser name
user_portrait_huge(string|link)User image 300x300px
user_portrait_large(string|link)User image 100x100px
user_portrait_medium(string|link)User image 75x75px
user_portrait_small(string|link)User image 30x30px
user_url(string|link)User url
widthnumberVideo width in px

Playlist Navigation

Playlist navigation contols next / prev buttons. You can use the default selectors or provide your own. Keynav arrows are also supported by default.

Default Nav ids
<!-- Playlist Nav -->
<nav class="playlist__nav">
  <button id="js-vp-prev" class="playlist__prev"><i>←</i> Prev</button>
  <button id="js-vp-next" class="playlist__next">Next <i>→</i></button>
</nav>
Customize Nav Ids
let options = {
  ...
  playlistNavNext: '#js-next',
  playlistNavPrev: '#js-prev',
}

Fullscreen Toggle

Leverage the fullscreen api to launch currently playing vid as fullscreen. Fullscreen mode repains during autoplay.

<!-- Playlist Full Screen Toggle -->
<button id="js-vp-fstoggle" class="playlist__fstoggle">Fullscreen</button>
Customize FS Toggle Ids

Provide a KeyboardEvent.code string for the fullscreenToggleKeyCode option.

let options = {
  ...
  fullscreenToggleKeyCode: 'Digit1',
}

📅 ToDos

  • Option for custom playlist template
  • Document availble data options from Vimeo's reponse object for playlist template.
  • Make hybrid npm module to support import and require.
  • Refactor how video id's are fetched, providing better error handling for 404'd items.
  • Since autoplay on load only works if muted due to Chrome policy, provide a button to unmute.
  • Provide a util method for ellapsed time.
  • Provide destory method
  • Perhaps support for multiple instances per page, with everything scoped to element.

Keywords

FAQs

Package last updated on 11 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc