lets-build-youtube-module
v1.1.1
Published
Load and interact with YouTube videos using the YouTube Iframe API.
Downloads
7
Readme
lets-build-youtube-module
Install
install via npm install lets-build-youtube-module
Options
youtubeId
youtube id of videoautoplay
option to start playing video as soon as it's loaded; defaultfalse
onReady
callback when video is loadedonPause
callback function when video is pausedonPlay
callback function when video resumes playing after pauseonEnded
callback function when video ends
Events
startVideo
start the videoplayPauseVideo
pause video if playing; play video if pausedstopVideo
stop the videogetVideoState
get a numeral value indicating the video state:-1
unstarted;0
ended;1
playing;2
paused;3
buffering;5
video cued
Example
HTML
<div id="ytloader-wduZHtRbSkY"></div>
Javascript
This will load a video into an iframe and insert it into the DOM in place of an element with id="youtube-wduZHtRbSkY"
var options = {
youtubeId: 'wduZHtRbSkY',
onReady: function() {
console.log("The video is loaded");
}
}
var player = new YTLoader.embed(options);
//assuming JQuery, bind events like so
$('.a-player-button').click(player.playPause);
TODO
- include options to set Iframe params, e.g., showing video player controls