Coder Social home page Coder Social logo

youtube-player's Introduction

youtube-player

A bare bones wrapper around the Youtube Iframe API.

Install

npm install watsondg/youtube-player -S

Usage

var Youtube = require('youtube-player');

var player = new Youtube();
player.cue('dQw4w9WgXcQ', 6); // Start playback at 6 seconds

Instance Methods

new Youtube(el[, options])

Create a new player instance.

  • el - an element that will be REPLACED by the player iframe.
  • options - (OPTIONAL) - configuration parameters:
  • controls: show or hide the default player controls
  • allowFullscreen: enable/disable fullscreen
  • hasAutoplay: automatically plays video - only works on desktop. Defaults to false
  • hasCueAutoplay: control if player.cue automatically plays the video - autoplay only works on dekstop. Defaults to the hasAutoplay value.

The player size defaults to 100% so you should use a container for any positioning/resizing.

cue(videoId[, startTime])

Change the displayed video.

  • videoId - the youtube video hash (in the URL after watch?v=).
  • startTime - (OPTIONAL) - time to start the video playback, in seconds.

play()

Resume playback.

pause()

Pause playback.

seek(time)

Jump to a specific time.

  • time - the time to jump to, in seconds.

mute()

Mute the sound.

unmute()

Unmutes the sound.

volume(value)

Sets the sound volume.

  • value - the volume, in 0-1 range.

fullscreen()

Toggle the player to fullscreen, if supported. Note that this is using the javascript requestFullScreen API since Youtube doesn't support this, unless you use built-in controls.

getDuration()

Return the current video duration.

getVolume()

Return the current sound volume.

getCurrentTime()

Return the current video time.

isPopulated()

Return whether or not the player is ready (creating the player using YT API is asynchronous).

isPlaying()

Return whether or not a video is currently playing.

isMuted()

Return whether or not the sound is muted.

hasPlayed()

Return whether or not a video has already started since the player was created.

destroy()

Stop and destroy the player.

Instance Events

populated

playing

paused

ended

buffering

unstarted

cued

timeupdate

License

MIT.

youtube-player's People

Contributors

ayamflow avatar

Watchers

 avatar  avatar

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.