![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
create-youtube-player
Advanced tools
Easy way to load and manage multiple Youtube players with API
Create Youtube Player is a lightweight Javascript library to instanciate Youtube players, without any dependencies.
The libraryis available as the create-youtube-player
package on npm.
npm install create-youtube-player --save
Online demo is available on the Create Youtube Player Github page.
The minimalist HTML structure below is enough to create the Youtube player.
Replace the {{idVideo}}
with the video id from the Youtube url.
For example, idVideo
is equal to uXLbQrK6cXw
in the address below: https://www.youtube.com/watch?v=uXLbQrK6cXw
<div class="player" data-youtube-id="{{idVideo}}"></div>
Every page that contains a player, has to instanciates them. The following example create one item.
import YoutubePlayer from 'create-youtube-player'
const youtubePlayer = new YoutubePlayer();
youtubePlayer.loadAPI(() => {
youtubePlayer.create({
element: document.querySelector('.player')
});
});
To customize the player with a poster, add a div tag inside the data-youtube-id
element.
<div class="player" data-youtube-id="{{idVideo}}">
<div class="player-poster">
<img src="" alt="" />
</div>
</div>
You can pass configuration options to the constructor. Example below show all default values. Allowed values are as follows:
{
multiplePlaying: true
}
multiplePlaying
- {Boolean} - Disable multiple player Youtube playing in the same timeEach player instanciations returns the instance of the class with somes available methods to easily manipulate the element.
The create()
function create the Youtube player. The function need before to use the Youtube API.
If the Youtube API is already available, you can call the function directly. Else, call the create()
function inside the loadAPI()
callback function.
youtubePlayer.create({
element: document.querySelector('.player')
});
You can pass configuration options to the create()
function.
Example below show all default values. Allowed values are as follows:
{
element: null,
width: '100%',
height: '100%',
playerVars: {
'showinfo': 0,
'modestbranding': 0,
'autohide': 0,
'rel': 0,
'wmode': 'transparent',
'controls': 1
},
selectors: {
posterWrapper: '.player-poster'
}
}
element
- {Object} - DOM element referencewidth
- {String} - Width of the player (with unity)height
- {String} - Height of the player (with unity)playerVars
- {Object} - Parameters of the Youtube playerselectors
- {Object} - Configuration of selectors used by the library
posterWrapper
- {String} - Selector of the poster wrapperMore informations about player parameters in the Youtube API documentation.
The loadAPI()
function load the Youtube API.
youtubePlayer.loadAPI(() => {
// Youtube API is ready
});
There are callbacks function available with the library.
The onPlayerReady
function is called when the player is ready and instanciated.
youtubePlayer.create({
element: document.querySelector('.player'),
events: {
onPlayerReady: (player) => {
// Youtube player is ready
}
}
});
Parameters:
player
- {Object} - Youtube player instanceThe onPlayerStateChange
function is called when the player status changed.
youtubePlayer.create({
element: document.querySelector('.player'),
events: {
onPlayerStateChange: (state) => {
// Youtube player state changed
}
}
});
Parameters:
state
- {Object} - Youtube player statePossible values of the state
:
Value | Status |
---|---|
-1 | not started |
0 | stop |
1 | playing |
2 | paused |
3 | buffering |
5 | queued |
More informations in the Youtube API documentation.
The onPosterClick
function is called when the poster is clicked.
There is a default behavior to play the video and hide the poster.
Declaring this function will disable the default behavior.
youtubePlayer.create({
element: document.querySelector('.player'),
events: {
onPosterClick: (e, player) => {
// Poster is clicked
e.target.style.display = 'none';
player.playVideo();
}
}
});
Parameters:
e
- {Object} - Event listener datasplayer
- {Object} - Youtube player instanceFAQs
Easy way to load and manage multiple Youtube players with API
The npm package create-youtube-player receives a total of 15 weekly downloads. As such, create-youtube-player popularity was classified as not popular.
We found that create-youtube-player demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.