开发者

Anythingslider and Youtube API passing variable

开发者 https://www.devze.com 2023-03-23 10:47 出处:网络
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\" fr

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').anythi开发者_JAVA百科ngSlider({
    easing : "swing",
    width  : 500,
    ............
    ............
    onSlideComplete : function(){
                      jQuery('.button').click(function(){
                      if (newState == '3') {....}
                      });
                      }
    });
});

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


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.


Based on your comments:

In onPlayerStateChange you have an argument called newState, so I'm guessing you call that function by doing something like

result = OnPlayerStateChange(1);

So newState is always defined, locally to that function.

If you want to access the same value in other functions, you need to define this variable outside all functions, in the global space, so

var newSate = 1 

(maybe at the top of the js source to avoid confusion)

Hope that helps

0

精彩评论

暂无评论...
验证码 换一张
取 消