I have the following code which is being called after the native player.loadNewVideoById function from youtube.
function initSliderAndTime() {
setTimeout(() => {
var durationInSeconds = player.getDuration()
$('#time-slider').attr('max', player.getDuration().toString().match(/^-?\d+(?:\.\d{0,1})?/)[0])
$('#end-time')[0].innerText = calculateTimeFormat(durationInSeconds);
}, 1000);
}
If I don't call a time out the player id is undefined and the function ins't doing what it it supposed to do. How can I turn this into an asynchronous function, so that it executes after the player has initialised.
I know about the OnReady Function from youtube's iframe api, but that doesn't get called when the player is updated, only if it created.
Any help is appreciated!