GithubHelp home page GithubHelp logo

p0rto / vue-video-wrapper Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 2.0 1.47 MB

A Vue.js component to wrap embed iframes from Vimeo and Youtube.

License: MIT License

JavaScript 100.00%
vue vuejs vimeo youtube wrapper video embedded vue-wrapper

vue-video-wrapper's Introduction

Vue Video Wrapper πŸ“Ή

A Vue.js component to wrap embeded iframes from Vimeo and Youtube.

npm version vue version npm downloads License: MIT

Supported Players

  • Vimeo βœ”οΈ
  • YouTube βœ”οΈ

Intro

A simple Vue.js component where you can wrap your Vimeo or Youtube embeded video and use their events.

Installation πŸ”§

Using npm:

npm install vue-video-wrapper

Getting Started πŸš€

Using globally:

import Vue from 'vue'
import VueVideoWrapper from 'vue-video-wrapper'

Vue.use(VueVideoWrapper) 
Vue.use(VueVideoWrapper, { componentId: "another-component-name" }) //if you want to give another name to the component

Using locally:

import VueVideoWrapper from 'vue-video-wrapper'

export default {
    components: { VueVideoWrapper }
}

Examples πŸ‘€

The required prop :player must receive a String with the name of the video player.

Vimeo

<video-wrapper :player="'vimeo'" :videoId="videoId" />

<another-component-name :player="'vimeo'" :videoId="videoId" />  <!-- if you changed the name of the component -->

Youtube

<video-wrapper :player="'youtube'" :videoId="videoId" />

<another-component-name :player="'youtube'" :videoId="videoId" />  <!-- if you changed the name of the component -->

πŸ” You can see here a demo on CodeSandbox.

Props πŸ“

Both players

Prop Type Required Default Description
player String true The embeded iframe player. Acceptable values: "Vimeo" and "Youtube", case insensitive.
videoId String, Number true Video identifier.

Vimeo

Prop Type Required Default Description
playerHeight String, Number false 320 Height of the embeded iframe player.
playerWidth String, Number false 640 Width of the embeded iframe player.
options Object false {} Options to pass to the Vimeo instance. See on https://github.com/vimeo/player.js/#embed-options
loop Boolean false false Enable loop on the end of the video.
autoplay Boolean false false The video starts automatically when it's ready.
controls Boolean false true If false, all elements in the player (play bar, sharing buttons, etc) will be hidden.

Example:

<video-wrapper :player="'vimeo'" :videoId="videoId" :autoplay="true" :playerHeight="500" />

Youtube

Prop Type Required Default Description
height String, Number false 360 Height of the embeded iframe player.
width String, Number false 640 Width of the embeded iframe player.
resize Boolean false false Embeded iframe player proportionally scale height with its width.
resizeDelay Number false 100 Delay in ms to before resize.
nocookie Boolean false false If true use https://www.youtube-nocookie.com as host.
fitParent Boolean false false Use parent's width.

Example:

<video-wrapper :player="'youtube'" :video="videoId" :height="500" :width="800" />

Events πŸ’₯

The component triggers events to notify the changes in the player.

Vimeo

  • play
  • pause
  • ended
  • timeupdate
  • progress
  • seeked
  • texttrackchange
  • cuechange
  • cuepoint
  • volumechange
  • error
  • loaded

Example

<template>
    <video-wrapper :player="'vimeo'" :videoId="videoId" @play="handlePlay" @pause="handlePause" />
</template>
<script>
export default {
    data() {
        return {
            videoId: "some-video-id"
        }
    },
    methods: {
        handlePlay() {
            console.log("playing video...");
        },
        handlePause() {
            console.log("pausing video...");
        }
    }
}
</script>

Youtube

  • ready
  • ended
  • play
  • pause
  • buffering
  • cued
  • error

Example

<template>
    <video-wrapper :player="'youtube'" :videoId="videoId" @play="handlePlay" @ended="handleEnded" />
</template>
<script>
export default {
    data() {
        return {
            videoId: "some-video-id"
        }
    },
    methods: {
        handlePlay() {
            console.log("playing video...");
        },
        handleEnded() {
            console.log("ended video...");
        }
    }
}
</script>

Player ⭐

You have access to all api methods from both players through component referencing.

Vimeo

Check the Vimeo api methods

Example

<template>
    <video-wrapper ref="player" :player="'vimeo'" :videoId="videoId" />
</template>
export default {
    // ...
    methods: {
        playVideo() {
            this.$refs.player.play();
        },
        pauseVideo() {
            this.$refs.player.pause();
        }
    }
}
export default {
    // ...
    methods: {
        getDuration() {
            this.$refs.$player.$player.getDuration().then(function(duration) {
                // do something with the duration
            });
        },
        getCurrentTime() {
            this.$refs.$player.$player.getCurrentTime().then(function(seconds) {
                // do something with the current time
            });
        }
    }
}

Youtube

Check the Youtube api methods

Example

<template>
    <video-wrapper ref="player" :player="'youtube'" :videoId="videoId" />
</template>
export default {
  // ...
  methods: {
    playVideo() {
        this.$refs.player.player.playVideo();
    },
    pauseVideo() {
        this.$refs.player.player.pauseVideo();
    }
  }
}

vue-video-wrapper's People

Contributors

p0rto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vue-video-wrapper's Issues

Inconsistent template name in README

This is a great pluginβ€”nice and simple.

I think the tag <video-wrapper> should be renamed to <VueVideoWrapper> or <vue-video-wrapper> by default.

I didn't notice that there was an option to rename the tag with the componentId option, but I think that should be off by default in the example to avoid confusing newbies.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.