I'm coding a Google Chrome extension where I embed a YouTube video:
<iframe id="ytplayer" type="text/html" width="640" height="360"
src="https://www.youtube.com/embed/M7lc1UVf-VE"
frameborder="0" allowfullscreen>
I then added a button below that should allow a user to click to play this video in full screen:
<a href="#" id="lnkFullScreen">Play full screen</a>
The work is done via JavaScript (and jQuery) using the code I found here:
$("#lnkFullScreen").click(function(e)
{
e.stopPropagation();
e.preventDefault();
var playerElement = document.getElementById("ytplayer");
playerElement.playVideo(); //`playVideo` is undefined
var requestFullScreen = playerElement.requestFullScreen || playerElement.mozRequestFullScreen || playerElement.webkitRequestFullScreen;
if (requestFullScreen)
{
requestFullScreen.bind(playerElement)();
}
});
But when I run this code the playVideo
function is undefined
for playerElement
.
Any idea what am I doing wrong?
PS. I want my player to remain in HTML5.