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-youtube-iframe-gene

v0.1.0

Published

Vue JS component wrapping a Youtube Video Player with the Youtube Iframe API

Downloads

52

Readme

Vue Youtube Iframe API

Hi, this is a Vue plugin to add youtube embed videos to your web project and control them.

It is very handy to create a custom player based on youtube videos, checkout this website for example : https://foreignrap.com

Installation

First add it to your project via yarn:

yarn add vue-youtube-iframe-api

OR npm:

npm install vue-youtube-iframe-api --save

Then, tell Vue about the plugin (Note that the name of the variable here is up to you).

import Vue from 'vue';
import Vytia from 'vue-youtube-iframe-api';

// simple way
Vue.use(Vytia);

// OR, with configuration
Vue.use(Vytia, {
  scriptUrl: null, // API url, OPTIONAL, default: https://www.youtube.com/iframe_api
  width: null, // global player width, OPTIONAL, default: 640
  height: null, // global player height, OPTIONAL, default: 360
  playerVars: null, // global playerVars, OPTIONAL, default: {}
  onLoad: null, // iframe loaded callback function, OPTIONAL
  onError: null, // iframe load failed callback function, OPTIONAL
});

// instan your Vue app
new Vue( ... );

This Vue plugin gives you access to a <vytia-player ytid="..."></vytia-player> component.

However, you can use the component name you want by importing the component locally or globally.

import Vue from 'vue'
import VuePlayerPlugin, { Player } from 'vue-youtube-iframe-api'

Vue.use(VuePlayerPlugin)

// globally
Vue.component('my-custom-name', Player)

// OR locally
new Vue({
  components: {
    MyPlayer: Player
  }
})

How it works ?

Just add the component where you want with either a id or url prop.

When the prop changes, the player will automatically load the new relevant video.

Component Props

| prop | description | type | default | |------------|--------------------------------------------------------------------------------------------------------------|-----------------|---------| | id | youtube video id note: both "ytid" & "yturl" can't be used at the same time | String | null | | url | youtube video url note: both "ytid" & "yturl" can't be used at the same time | String | null | | width | the iframe's width note: youtube asks for 200 minimum | String | Number | 640 | | height | the iframe's height note: youtube asks for 200 minimum | String | Number | 360 | | playerVars | the iframe's player variables, full list: https://developers.google.com/youtube/player_parameters?hl=fr | Object | {} |

Make sure to look at all player variables as this will help you remove controls from the youtube iframe.

https://developers.google.com/youtube/player_parameters?hl=fr

Component Events

| event | description | |-----------|-------------------------------------------------------------------------------------------------------------------| | ready | fires when the player is ready and the player's instance can be used | | error | fires when the player encounters an error https://developers.google.com/youtube/iframe_api_reference?hl=fr#Events | | unstarted | fires when player ready but not started because no video | | playing | fires when player starts playing | | paused | fires when player stops playing and is on pause | | cued | fires when a video was added to the player's queue but hasn't played yet | | buffering | fires when player starts buffering / loading | | ended | fires when player video has ended |

Component Methods

You can access these methods by adding a ref on the component.

| method | description | params | |-----------|--------------------------------------------------------|-------------| | loadById | programatically loads a new video on the player by ID | id: String, options: Object | | loadByUrl | programatically loads a new video on the player by URL | url: String, options: Object |

Youtube Player instance

You can access the youtube player's instance by adding a ref on the component. You need to wait for the player to be ready though. When the player is not ready, the property holding the instance is null.

Full list of the instance's methods you can use below: https://developers.google.com/youtube/iframe_api_reference?hl=fr#Playback_controls

<vytia-player ytid="some youtube id" ref="yt" @ready="onPlayerReady"></vytia-player>
new Vue({
  methods: {
    onPlayerReady () {
      // you have access to the ref here
      this.$refs.yt.player.seekTo( ... )

      // you can see the full list of methods available here
      // https://developers.google.com/youtube/iframe_api_reference?hl=fr#Playback_controls
    }
  }
})

Make sure to check out the demo to see how to control the player.

The demo works with parcel-bundler.

Install it by doing npm install -g parcel-bundler or yarn global add parcel-bundler.