Search code examples
jqueryvariablesanythingslider

Anythingslider and Youtube API passing variable


I'm trying to bind the Youtube API with a jQuery Anythingslider, and I'm achieving it.

Now, I need to pass the variable "newState" defined out of anythingslider (within "onPlayerStateChange" from Youtube API) into its callback. This is the code, first the variable and then the anythingslider:

function onPlayerStateChange(newState) {
....
// other stuff not important 
....
}

jQuery.(document).ready(function() {

  jQuery('#myslider').anythingSlider({
    easing : "swing",
    width  : 500,
    ............
    ............
    onSlideComplete : function(){
                      jQuery('.button').click(function(){
                      if (newState == '3') {....}
                      });
                      }
    });
});

This code returns me: "newState" is undefined..obviously..thanks a lot


Solution

  • I'm not sure what you are trying to do, but the latest version of AnythingSlider has a video extension that will automatically continue playing a video when the panel comes into view, and pause the video when it goes out of view. This extension currently supports HTMl5, YouTube (embed & iframe) and Vimeo (embed & iframe) with additional code on the video wiki page to control JW Player and Flow Player (without the extension).

    If you are using this extension and you need to get the status of the video, it is accessible using this external method:

    var slider = $('#slider').data('AnythingSlider'),
        index = slider.$currentPage.find('[id^=asvideo]')[0].id.replace(/asvideo/,''),
        status = slider.video.list[index].status;
    

    Note: The status value is a number for YouTube videos and a string ('play', 'pause' and 'finish') for Vimeo videos. HTML5 video status can be accessed directly and does not have a status variable.