Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
194
rated 0 times [  197] [ 3]  / answers: 1 / hits: 34835  / 12 Years ago, sun, july 1, 2012, 12:00:00

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',
});
}


Here's a demo in jsFiddle



However, it's not working. Anyone have a idea how to do this?


More From » youtube

 Answers
15

Use player.playVideo(); (resume) and player.pauseVideo(); (pause) once the player is ready: http://jsfiddle.net/4WPmY/6/



function onYouTubePlayerAPIReady() {
    player = new YT.Player('player', {
        height: '315',
        width: '560',
        videoId: 'bpOR_HuHRNs',
    });
    document.getElementById('resume').onclick = function() {
        player.playVideo();
    };
    document.getElementById('pause').onclick = function() {
        player.pauseVideo();
    };
}

[#84542] Friday, June 29, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
grayson

Total Points: 36
Total Questions: 113
Total Answers: 95

Location: Tonga
Member since Fri, Aug 21, 2020
4 Years ago
grayson questions
;