Am I allowed to replace the original youtube play icon on embedded youtube videos? I would place my own icon above the youtube iframe to achieve that. I know that facebook does not allow to style the like button, so that's why I am asking about youtube player customization.
I'm not sure you can customise a YouTube embedded without using the YouTube JavaScript api.
Heres how to do it with the api:
Javascript
//youtube script
var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
onYouTubeIframeAPIReady = function () {
player = new YT.Player('player', {
height: '244',
width: '434',
videoId: 'AkyQgpqRyBY', // youtube video id
playerVars: {
'autoplay': 0,
'rel': 0,
'showinfo': 0
},
events: {
'onStateChange': onPlayerStateChange
}
});
}
onPlayerStateChange = function (event) {
if (event.data == YT.PlayerState.ENDED) {
$('.start-video').fadeIn('normal');
}
}
$(document).on('click', '.start-video', function () {
$(this).fadeOut('normal');
player.playVideo();
});
HTML
<div id="player"></div>
<button class="start-video">Start Video</button>
CSS
button {
position: absolute;
top: 106px;
padding: 12px;
left: 174px;
}
I've created a Jsfiddle with a working example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With