简体   繁体   中英

Getting a callback to fire immediately in javascript (and the Vimeo api)

I have code that works with Vimeo videos. It is supposed to get the exact position that the video is at, and then continue processing. To do this with the javascript API, it seems that you cannot do a simple call like "GetCurrentTime();". Instead you need to use callbacks. So you might have:

var savevalue;
froogaloop.api('getCurrentTime', function(value, player_id) {
savevalue = value;
}

I may be missing something, but if that is the only way to do it, how do I use this in the middle of a function that cannot afford to wait for a callback? In other words, Suppose my function needs to do operation A,B, and then C, where B is getting the current position, and C is using it.
Thanks,

You can't get the return without a callback, but if you listen to the playProgress event, you can set a value every time it fires (which is rather frequently) and then access that when you need the current time.

var savevalue;
froogaloop.api('getCurrentTime', function(value, player_id) {
savevalue = value;
}
do_operation_a;
do_operation_b; //using savevalue as the current time
do_operation_c;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM