Created
April 3, 2015 21:12
-
-
Save mrspeaker/324a7512755e7b32fa7f to your computer and use it in GitHub Desktop.
get youtube vid lengths with jquery promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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