I have initialized a youtube video with youtube apis in a div with certain dimensions. Is it possible to display the video as it would be an image set as background sized cover of a div? I mean without any black spaces.
Here below you can find the actual result and the code I used.
Code:
var player123;
if(jQuery('#player123')){
bindVideo();
}
function bindVideo(){
var playerHeight = "500px";
if(jQuery(window).width() < 1023){
playerHeight = "100%";
}else{
playerHeight = "400px";
}
jQuery(window).resize(function(){
if(jQuery(window).width() < 1023){
playerHeight = "100%";
}else{
playerHeight = "400px";
}
});
player123 = new YT.Player('player123', {
height: playerHeight,
width: '100%',
videoId: 'video-id-here',
events: {
'onReady': onPlayerReady(event),
'onStateChange': onPlayerStateChange
},
playerVars:{
rel:0,
loop:1,
showinfo:0,
controls:0,
disablekb:1
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
//event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if(event.data == "2"){
pauseVideo();
}else if(event.data == "0"){
stopVideo();
}
}
function stopVideo() {
jQuery("#player-overlay").show();
player123.stopVideo();
}
function PlayVideo2(){
jQuery("#player-overlay").hide();
player123.playVideo();
}
function pauseVideo(){
jQuery("#player-overlay").show();
player123.pauseVideo();
}
Is there any parameter to set to remove them ?