Pause youtube video, youtube api

javascript, youtube, youtube-api, youtube-javascript-api

Solution

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();
    };
}

Problem

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?

Original source