I'm trying to pause and play YouTube videos with the following code which is pretty much a copy from the Youtube API page:
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '315',
width: '560',
videoId: 'bpOR_HuHRNs',
});
}
However, it's not working. Anyone have a idea how to do this?
In your HTML, have some buttons to control the video:
Using jQuery, bind an event listener (the click) to trigger a function on your player object:
I built an app using YouTube's Player and Data api. Take what you need: https://github.com/HunterMeyer/YouTV
Use
player.playVideo();
(resume) andplayer.pauseVideo();
(pause) once the player is ready: http://jsfiddle.net/4WPmY/6/In this code I added the Resume and Pause buttons in one: Example