Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/webistomin/vuetube

๐Ÿš€ A fast, lightweight, lazyload vue component acting as a thin layer over the YouTube Iframe Player API which renders fast
https://github.com/webistomin/vuetube

vue-youtube vue-youtube-iframe vuetube youtube youtube-api youtube-player

Last synced: 2 months ago
JSON representation

๐Ÿš€ A fast, lightweight, lazyload vue component acting as a thin layer over the YouTube Iframe Player API which renders fast

Awesome Lists containing this project

README

        



๐Ÿš€

VueTube


Vue component acting as a thin layer over the YouTube IFrame Player API which renders fast.


Explore website ยป




NPM version


NPM downloads


GitHub issues


GitHub last commit


npm type definitions


npm bundle size


Key Features โ€ข
Installation โ€ข
Documentation โ€ข
FAQ โ€ข
Browsers support โ€ข
License โ€ข
Inspiration โ€ข
Support the project โ€ข
Contributing

## Key Features โœจ

* **Small** `~2KB` js (minified and gzipped) and `~1KB` css
* **No dependencies**
* **Lazy load** support
* **Webp support**, and fallback to `jpg` if the browser doesn't support it
* **Render fast**, improve your web's performance
* Built with **a11y** in mind

## Installation โš™๏ธ

**npm**
```shell
# Vue 2
npm install vuetube

# Vue 3
npm install vuetube@next
```

**yarn**
```shell
# Vue 2
yarn add vuetube

# Vue 3
yarn add vuetube@next
```

**Install plugin**
```js
/**
* Vue 2
*/
import Vue from 'vue'
import VueTube from 'vuetube';
import 'vuetube/dist/vuetube.css'

Vue.use(VueTube)

/**
* Vue 3
*/
import { createApp } from 'vue'
import VueTube from 'vuetube';
import 'vuetube/dist/vuetube.css'
import App from './App.vue'

const app = createApp(App)
app.use(VueTube)
```

or

**Install component**
```js
/**
* Vue 2
*/
import Vue from 'vue'
import { VueTube } from 'vuetube';
import 'vuetube/dist/vuetube.css'

Vue.component('VueTube', VueTube)

/**
* Vue 3
*/
import { createApp } from 'vue'
import { VueTube } from 'vuetube';
import 'vuetube/dist/vuetube.css'
import App from './App.vue'

const app = createApp(App)
app.component('VueTube', VueTube)
```

## Documentation ๐Ÿค—

Browse [online documentation here](https://vuetube-ten.vercel.app/)

### Props



Prop


Type


Description


Default value




videoId


string


The ID of YouTube video (required)


-




isPlaylist


boolean


Should embed a playlist of several videos


false




aspectRatio


number


The aspect ratio for iframe


16 / 9




enableCookies


boolean


Change video host to www.youtube.com. By default, video loaded from https://www.youtube-nocookie.com.


false




playerVars


object


Parameters that are available in the YouTube embedded player.


{}




disableWarming


boolean


Disable warming up connections to origins that are in the critical path on component hover.


false




disableWebp


boolean


Disable webp thumbnail.


false




imageAlt


string


Alt attribute for image


''




imageLoading


string


Loading attribute for image


'lazy'




resolution


string


Thumbnail resolution from YouTube API.


'sddefault'




buttonLabel


string


Aria-label attribute for button


'Play video'




iframeTitle


string


Title attribute for iframe


''




iframeAllow


string


Allow attribute for iframe


'accelerometer;autoplay;encrypted-media;gyroscope;picture-in-picture'

### Events


Event name
Description


player:play
The user clicked on the play button


player:load
Iframe has been loaded


player:ready
This event fires whenever a player has finished loading and is ready to begin receiving API calls.

Make sure you pass enablejsapi: 1 to the playerVars props object

This event is similar to onReady event from Youtube API documentation.


player:statechange
This event fires whenever the player's state changes.

Make sure you pass enablejsapi: 1 to the playerVars props object

This event is similar to onStateChange event from Youtube API documentation.


player:playbackqualitychange
This event fires whenever the video playback quality changes.

Make sure you pass enablejsapi: 1 to the playerVars props object

This event is similar to onPlaybackQualityChange event from Youtube API documentation.


player:playbackratechange
This event fires whenever the video playback rate changes.

Make sure you pass enablejsapi: 1 to the playerVars props object

This event is similar to onPlaybackRateChange event from Youtube API documentation.


player:error
This event fires if an error occurs in the player.

Make sure you pass enablejsapi: 1 to the playerVars props object

This event is similar to onError event from Youtube API documentation.


player:apichange
This event is fired to indicate that the player has loaded (or unloaded) a module with exposed API methods.

Make sure you pass enablejsapi: 1 to the playerVars props object

This event is similar to onApiChange event from Youtube API documentation.

## FAQ ๐Ÿ—ฏ๏ธ

### How to get access to player API?

You need to pass enablejsapi: 1 to the playerVars props object. Then subscribe on player:ready event.

```vue



export default {
data() {
return {
playerInstance: null,
}
},

methods: {
onPlayerReady(event) {
this.playerInstance = event.target
}
}
}

```

Now you have a player instance in the `playerInstance`. You can do whatever you want with video.

`this.playerInstance.playVideo()`, `this.playerInstance.pauseVideo()` etc. All methods can be found [here](https://developers.google.com/youtube/iframe_api_reference#Playback_controls).

### How to use my play button?

You can pass your button through the `icon` slot.

```vue









```

### How to use my thumbnail?

You can pass your thumbnail through the `thumbnail` slot.

```vue







```

## Browsers support ๐ŸŒŽ

| [IE / Edge](http://godban.github.io/browsers-support-badges/)
IE / Edge | [Firefox](http://godban.github.io/browsers-support-badges/)
Firefox | [Chrome](http://godban.github.io/browsers-support-badges/)
Chrome | [Safari](http://godban.github.io/browsers-support-badges/)
Safari | [iOS Safari](http://godban.github.io/browsers-support-badges/)
iOS Safari | [Samsung](http://godban.github.io/browsers-support-badges/)
Samsung | [Opera](http://godban.github.io/browsers-support-badges/)
Opera | [Yandex](http://godban.github.io/browsers-support-badges/)
Yandex |
| --------- | --------- | --------- | --------- | --------- | --------- | --------- | --------- |
| IE11, Edge 80 | 60+ | 60+ | 10+ | 10+ | 12+ | 50+ | 14.4+

## License ๐Ÿ“„

### [MIT](https://github.com/webistomin/vuetube/blob/master/LICENSE)

## Inspiration ๐Ÿ‘

Vuetube is a vue component version of the popular package [lite-youtube-embed](https://github.com/paulirish/lite-youtube-embed).

## Support the project โญ

If you feel awesome and want to support me in a small way, please consider starring and sharing the repo!

## Contributing ๐ŸŽ‰

Found a bug? Missing a specific feature?
Your contributions are always welcome! Please have a look at the [contribution guidelines](https://github.com/webistomin/vuetube/blob/master/CONTRIBUTING.md) first.

## Contributors โค๏ธ



Alexey Istomin

๏ธ๏ธ๏ธ๏ธโ™ฟ๏ธ โš ๏ธ ๐Ÿ’ป ๐Ÿค”