npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-playr

v0.1.1

Published

A vue component for the plyr video & audio player.

Downloads

58

Readme

vue-playr

v0.0.1 - Changelog

A vue component for the plyr video & audio player.

This is useful for when you want a nice video player in your Vue app.

It uses plyr by sampotts v3 for the players.

Supported player types: HTML5 video, HTML5 audio, YouTube (div & progressive enhancement), and Vimeo (div & progressive enhancement).

Installation

yarn add vue-playr plyr # or npm i vue-playr plyr

Module

// In your main vue file - the one where you create the initial vue instance.
import Vue from 'vue'
import VuePlayr from 'vue-playr'

// The second argument is optional and sets the default config values for every player.
Vue.use(VuePlayr, {
  plyr: {
    fullscreen: { enabled: false }
  },
  events: ['ended']
})

SSR (more below)

For SSR you can import the SSR optimized module, found at ./dist/vue-playr.ssr.js. There is a more in depth description on how to use it with nuxt below.

Browser

In the browser you can include it as you would any other package: with unpkg.

<script type="text/javascript" src="https://unpkg.com/vue"></script>
<script type="text/javascript" src="https://unpkg.com/plyr"></script>
<script type="text/javascript" src="https://unpkg.com/vue-playr"></script>

<!-- You will also need to install the component during app creation -->
<script>
  window.Vue.createApp(VuePalyr).mount('#app')
</script>

Usage

Once installed, it can be used in a template as simply as:

<!-- video element -->
<vue-playr>
  <video poster="poster.png" src="video.mp4">
    <source src="video-720p.mp4" type="video/mp4" size="720">
    <source src="video-1080p.mp4" type="video/mp4" size="1080">
    <track kind="captions" label="English" srclang="en" src="captions-en.vtt" default>
  </video>
</vue-playr>

<!-- audio element -->
<vue-playr>
  <audio>
    <source src="audio.mp3" type="audio/mp3"/>
    <source src="audio.ogg" type="audio/ogg"/>
  </audio>
</vue-playr>

<!-- youtube iframe with progressive enhancement (extra queries after the url to optimize the embed) -->
<vue-playr>
  <div class="plyr__video-embed">
    <iframe
      src="https://www.youtube.com/embed/bTqVqk7FSmY?iv_load_policy=3&modestbranding=1&playsinline=1&showinfo=0&rel=0&enablejsapi=1"
      allowfullscreen allowtransparency allow="autoplay">
    </iframe>
  </div>
</vue-playr>

<!-- youtube div element -->
<vue-playr>
  <div data-plyr-provider="youtube" data-plyr-embed-id="bTqVqk7FSmY"></div>
</vue-playr>

<!-- vimeo iframe with progressive enhancement (extra queries after the url to optimize the embed) -->
<vue-playr>
    <div class="plyr__video-embed">
      <iframe
        src="https://player.vimeo.com/video/76979871?loop=false&byline=false&portrait=false&title=false&speed=true&transparent=0&gesture=media"
        allowfullscreen allowtransparency allow="autoplay">
      </iframe>
    </div>
  </vue-playr>

<!-- vimeo div element -->
<vue-playr>
  <div data-plyr-provider="vimeo" data-plyr-embed-id="76979871"></div>
</vue-playr>

Player Instance

To access the player instance, you can use the refs attribute.

<template>
  <vue-playr ref="plyr" />
</template>

<script>
export default {
  name: 'Component',
  computed: {
    player () {
      return this.$refs.plyr.player
    }
  },
  mounted () {
    console.log(this.player)
  }
}
</script>

Events

If you want to capture events from the plyr instance, there are a few options:

The preferred method is accessing the player instance through the ref attribute and using that object for events, as you would with a vanilla plyr instance.

Valid events are here.

<template>
  <vue-playr ref="plyr" />
</template>
<script>
export default {
  name: 'Component',
  computed: {
    player () {
      return this.$refs.plyr.player
    }
  },
  mounted () {
    this.player.on('event', () => console.log('event fired'))
  }
</script>

The other way is to just pass an array of the events you want emitted.

<vue-playr :events="['timeupdate','exitfullscreen']" @timeupdate="videoTimeUpdated" @exitfullscreen="exitedFullScreen">

Options

For custom options you can pass an options prop which is an object that will be passed to the new Plyr() creation. Available options here. I added an additional option (hideYouTubeDOMError) that hides the error that is always logged when destroying a YouTube player. It defaults to true, and you can disable it and see the error by setting it to false.

SSR

Nuxt

This should support SSR out of the box. For nuxt, create a file called vue-playr.js in your plugins folder containing only these three statements:

import Vue from 'vue'
import VuePlayr from 'vue-playr/dist/vue-playr.ssr.js'

// The second argument is optional and sets the default config values for every player.
Vue.use(VuePlayr, {
  plyr: {
    fullscreen: { enabled: false }
  },
  events: ['ended']
})

Then, in your nuxt.config.js file add '~/plugins/vue-playr' to the plugins array. The vue-playr element should be globally registered now.

You will also want to add plyr/dist/plyr.css to your css array in the same file.

The nuxt.config.js file should at minimum include this:

export default {
  plugins: [
    '~/plugins/vue-playr'
  ],
  css: [
    'plyr/dist/plyr.css'
  ]
}

Author

vue-playr © Chantouch, Released under the MIT License.