A bare bones wrapper around the Youtube Iframe API.
npm install watsondg/youtube-player -S
var Youtube = require('youtube-player');
var player = new Youtube();
player.cue('dQw4w9WgXcQ', 6); // Start playback at 6 seconds
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 thehasAutoplay
value.
The player size defaults to 100% so you should use a container for any positioning/resizing.
Change the displayed video.
videoId
- the youtube video hash (in the URL afterwatch?v=
).startTime
- (OPTIONAL) - time to start the video playback, in seconds.
Resume playback.
Pause playback.
Jump to a specific time.
time
- the time to jump to, in seconds.
Mute the sound.
Unmutes the sound.
Sets the sound volume.
value
- the volume, in 0-1 range.
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.
Return the current video duration.
Return the current sound volume.
Return the current video time.
Return whether or not the player is ready (creating the player using YT API is asynchronous).
Return whether or not a video is currently playing.
Return whether or not the sound is muted.
Return whether or not a video has already started since the player was created.
Stop and destroy the player.
MIT.