YouTube API - Play/Pause Toggle Button
<p>I have an embedded YouTube video with a transparent PNG "frame" in front of it, so I need to have an invisible play/pause button in front of the PNG. Everything is working correctly, and the video plays onClick, BUT I can't pause the video once it's playing. I've tried several variations of "section 4" below, and nothing seems to work. Can someone please tell me what I'm missing?</p>

<pre><code>    var video_id = $('#video-player').attr('data-id');
    // 1. This code loads the IFrame Player API code asynchronously.
    var tag = document.createElement('script');

    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    // 2. This function creates an &lt;iframe&gt; (and YouTube player) after the API code downloads.
    var player;
    function onYouTubeIframeAPIReady() {
        player = new YT.Player('video', {
            width: '470',
            height: '263',
            videoId: 'ubvR6_pwpIk',
            playerVars: {
                modestbranding: 1,
                controls: 0,
                showinfo: 0,
                wmode: 'opaque',
                branding: 0,
                autohide: 0,
                rel: 0
            },
            events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
            }
        });
    }

    // 3. The API calls this function when the video player is ready.
    function onPlayerReady(event) {
        $('#video-button').click(function(event){
            player.playVideo();
        });
    }

    // 4. The API calls this function when the player's state changes.
    function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING) {
            $('#video-button').click(function(event){
                player.pauseVideo();
            });
        }
        else {
            $('#video-button').click(function(event){
                player.playVideo();
            });
        } 
    }
</code></pre>