Hello please anyone help me.
I have some code like below
let duration;
let video = document.createElement('video');
video.setAttribute("id", 'test')
video.setAttribute("src", "https://vdoelearning.s3-ap-southeast-1.amazonaws.com/Charlie%2BPuth%2B-%2BOne%2BCall%2BAway.mp4");
video.preload = 'metadata'
video.ondurationchange = function() {
duration = video.duration
}
console.log(duration)
Why variable duration is always undefined? I've been searching on google but did not find any solution. Has anyone ever had a problem similar to mine?