Supported player types: HTML5 video, HTML5 audio, YouTube, and Vimeo.
$3
A demo of the components (equivalent to the html example include here) can be found at redxtech.github.io/vue-plyr.
Installation
``bash yarn add vue-plyr # or npm i vue-plyr `
$3
`js // In your main vue file - the one where you create the initial vue instance. import Vue from 'vue' import VuePlyr from 'vue-plyr' import 'vue-plyr/dist/vue-plyr.css'
// Vue 3.x // The second argument is optional and sets the default config values for every player. createApp(App) .use(VuePlyr, { plyr: {} }) .mount('#app')
// Vue 2.x // The second argument is optional and sets the default config values for every player. Vue.use(VuePlyr, { plyr: {} })
`
$3
For SSR, you can import the SSR optimized module, found at dist/vue-plyr.ssr.js. There is a more in depth description on how to use it with nuxt below.
$3
In the browser you can include it as you would any other package with unpkg, along with the stylesheet:`html
`
Usage
Once installed, it can be used in a template as simply as:`vue
To access the player instance, you can use the player property from the refs attribute.`html
...
`
Examples
Examples of how to use this app can be found here.
Events
If you want to capture events from the plyr instance, you can do so by accessing the player instance through the ref attribute and using that object for events, as you would with a vanilla plyr instance.
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 have added a new 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.
You can also specify the default options when registering the plugin (these will be ignored if you specify a player-specific options object via props):
`js createApp(App).use(VuePlyr, { plyr: {} }) `
SSR
$3
This should support SSR out of the box. For nuxt, create a file called vue-plyr.js in your plugins folder containing only these three statements:`js import Vue from 'vue' import VuePlyr from 'vue-plyr/dist/vue-plyr.ssr.js' import 'vue-plyr/dist/vue-plyr.css'
// The second argument is optional and sets the default config values for every player. Vue.use(VuePlyr, { plyr: {} })
`
Then, in your
nuxt.config.js file add { src: '~/plugins/vue-plyr', mode: 'client' } to the plugins array. The vue-plyr element should be globally registered now.
The
nuxt.config.js file should at minimum include this:`js export default { plugins: [{ src: '~/plugins/vue-plyr', mode: 'client' }] } ``