Vue 3 plugin for Plyr
Plyrue (/pliru/) is a Vue plugin that wraps the Plyr media player and gives it a simple, declarative API.
Written in TypeScript, shipped as ESM + UMD with bundled type declarations.
| Plyrue | Vue | Plyr | Node |
|---|---|---|---|
| 3.x | ^3.4 | ^3.7.8 | >= 20.19 |
| 2.x | ^2.6 | ^3.6 | — |
vue and plyr are peer dependencies — install them alongside Plyrue.
npm install plyrue plyrImport Plyr's stylesheet once in your app:
import 'plyr/dist/plyr.css';import { createApp } from 'vue';
import Plyrue from 'plyrue';
import 'plyr/dist/plyr.css';
import App from './App.vue';
createApp(App).use(Plyrue).mount('#app');Or import the component directly, without registering the plugin:
<script setup lang="ts">
import { Plyrue } from 'plyrue';
</script>
<template>
<Plyrue type="video" src="https://example.com/video-576p.mp4" />
</template>Plyrue can be used in two ways:
- with slots
- with data (for audio and video)
<plyrue
type="video"
poster="https://example.com/video-HD.jpg"
src="https://example.com/video-576p.mp4"
:options="options"
>
<source src="https://example.com/video-576p.mp4" type="video/mp4" size="576" />
<track
kind="captions"
label="English"
srclang="en"
src="https://example.com/video-HD.en.vtt"
default
/>
</plyrue>When type is set, Plyrue renders the video / audio tag for you. When it is not set, the default component is used and you must supply the media element yourself:
<plyrue>
<video controls src="https://example.com/video-576p.mp4">
<source src="https://example.com/video-1080p.mp4" type="video/mp4" size="1080" />
<track
kind="captions"
label="English"
srclang="en"
src="https://example.com/video-HD.en.vtt"
default
/>
<a href="https://example.com/video-576p.mp4" download>Download</a>
</video>
</plyrue><script setup lang="ts">
import type { PlyrueCaption, PlyrueSource } from 'plyrue';
const sources: PlyrueSource[] = [
{ src: 'https://example.com/video-576p.mp4', type: 'video/mp4', size: 576 }
];
const captions: PlyrueCaption[] = [
{
label: 'Croatian',
srclang: 'hr',
src: 'https://example.com/video-HD.hr.vtt'
}
];
</script>
<template>
<plyrue
type="video"
poster="https://example.com/video-HD.jpg"
src="https://example.com/video-576p.mp4"
:sources="sources"
:captions="captions"
/>
</template>app.use(Plyrue, { name: 'my-player' });- Type:
string - Default:
plyrue
The name the component is registered under.
-
Type:
'default' | 'audio' | 'video' | 'embed' -
Default:
'default' -
videofor HTML5 video -
audiofor HTML5 audio -
embedfor YouTube and Vimeo -
defaultrenders the slot as-is
- Type:
Plyr.Options - Default:
{}
Options for the Plyr player, documented here. The player is recreated when this object changes.
- Type:
string - Required: false
Poster image, applied to the player and kept in sync when it changes.
- Type:
PlyrueSource[] - Required: false
For video:
[{ src: 'https://example.com/video.mp4', type: 'video/mp4', size: 576 }];For audio:
[{ src: 'https://example.com/audio.mp3', type: 'audio/mp3' }];- Type:
PlyrueCaption[] - Required: false
[
{
label: 'Croatian',
srclang: 'hr',
src: 'https://example.com/caption.hr.vtt'
}
];All valid attributes for video, audio and iframe are passed down to the corresponding element. Plyrue provides sensible defaults for video and audio.
<plyrue type="audio" :sources="audio" autoplay loop />Every Plyr event is re-emitted by the component, plus a player event carrying the Plyr instance once it is created.
<script setup lang="ts">
import type { PlyrPlayer } from 'plyrue';
const onPlayer = (player: PlyrPlayer) => console.log(player);
const onPlaying = (event: Event) => console.log(event);
</script>
<template>
<plyrue type="video" src="…" @player="onPlayer" @playing="onPlaying" />
</template>The full list is exported as PLYR_EVENTS.
<script setup lang="ts">
import { ref } from 'vue';
const plyrue = ref();
const pause = () => plyrue.value?.player?.pause();
</script>
<template>
<plyrue ref="plyrue" type="video" src="…" />
</template>- Requires Vue 3. Register with
app.use(Plyrue)instead ofVue.use(Plyrue). vueandplyrare now peer dependencies you install yourself.- Plyr's CSS is no longer imported by the package — add
import 'plyr/dist/plyr.css'to your app. - All Plyr events are emitted unconditionally; you no longer need a listener attached at mount time for an event to fire.
embedsources are restricted tohttp(s)URLs; anything else renders an iframe with nosrc.- The package is published as ESM + UMD (
plyrue.js/plyrue.umd.cjs) with bundled types.
npm run dev # run the example app
npm run test # run the test suite
npm run test:coverage # run tests with coverage
npm run lint # lint
npm run typecheck # type-check
npm run build # type-check and build the libraryAll contributions are welcome.
Plyrue is inspired by vue-plyr.
MIT @ Zdravko Ćurić (zcuric)