2

I have a video player on my site that has multiple videos all in a slider-type layout. There are thumbnails of each video underneath, and I need any playing video to pause if any of the thumbnails are clicked. I have the froogaloop.js in my head, and this code in my scripts.js file : (function(){

            // Listen for the ready event for any vimeo video players on the page
            var vimeoPlayers = document.querySelectorAll('iframe'),
                player;

            for (var i = 0, length = vimeoPlayers.length; i < length; i++) {
                player = vimeoPlayers[i];
                $f(player).addEvent('ready', ready);
            }

            /**
             * Utility function for adding an event. Handles the inconsistencies
             * between the W3C method for adding events (addEventListener) and
             * IE's (attachEvent).
             */
            function addEvent(element, eventName, callback) {
                if (element.addEventListener) {
                    element.addEventListener(eventName, callback, false);
                }
                else {
                    element.attachEvent(eventName, callback, false);
                }
            }

            /**
             * Called once a vimeo player is loaded and ready to receive
             * commands. You can add events and make api calls only after this
             * function has been called.
             */
            function ready(player_id) {
                // Keep a reference to Froogaloop for this player
                var container = document.getElementById(player_id).parentNode.parentNode,
                    froogaloop = $f(player_id),
                    apiConsole = container.querySelector('.console .output');

                /**
                 * Prepends log messages to the example console for you to see.
                 */
                function apiLog(message) {
                    apiConsole.innerHTML = message + '\n' + apiConsole.innerHTML;
                }

                // Setup clear console button
                var clearBtn = container.querySelector('.console button');
                addEvent(clearBtn, 'click', function(e) {
                    apiConsole.innerHTML = '';
                }, false);

                apiLog(player_id + ' ready!');
            }
        })();

Then I have this for my thumbnails:

jQuery("a.switch-foto").click(function(){
    jQuery(".fotos").fadeOut();
    jQuery(".fotos").removeClass("first");
    jQuery('#see_'+this.id).delay(600).fadeIn();
    froogaloop.api('pause');
});

But when I test it on my site - it doesn't work - I get this error: Uncaught ReferenceError: froogaloop is not defined

can anyone help? Sorry I dont really understand Froogaloop.

4

1 回答 1

4

乍一看,在 click 事件中没有定义 froogaloop.api 调用。为了暂停视频,您应该将播放器传递给 Froogaloop 以暂停。像这样的东西:

Froogaloop( jQuery('iframe')[0] ).api('pause');

请注意,Froogaloop 有大写字母。我也和 Froogaloop 有关系。我希望这可以帮助你。

于 2012-10-04T16:05:03.330 回答