Skip to content

Instantly share code, notes, and snippets.

@mrspeaker
Created April 3, 2015 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrspeaker/324a7512755e7b32fa7f to your computer and use it in GitHub Desktop.
Save mrspeaker/324a7512755e7b32fa7f to your computer and use it in GitHub Desktop.
get youtube vid lengths with jquery promises
//Getting length of the youtube vids...
$('#yt_player_container').on("onPlayerReady", (msg) => {
$.when().then(delay(1000)).then(() => {
_.toArray(window.talk_metadata)
.reduce((seq, talk) => seq.then(() => {
return new Promise((res, rej) => {
const cb = ({event}) => {
if (event == YT.PlayerState.PLAYING) {
stopVideo();
$('#yt_player_container').off("onPlayerStateChange", cb);
setTimeout(() => res("ok"), 2000)
console.log("vidid", talk.fullName, "duration", window.player.getDuration());
}
}
$('#yt_player_container').on("onPlayerStateChange", cb);
window.player.loadVideoById(talk.videoId);
});
}), Promise.resolve());
})
.fail(e => console.log("err", e));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment