bigpotato
bigpotato

Reputation: 27527

Javascript: Event for when video src is loaded?

Is there an event listener for when a video's src is loaded?

I've noticed sometimes YouTube takes a few seconds to load the video src on Safari Mobile on iPhone. Ideally there is a callback on HTMLVideoElement.prototype for when src is loaded.

I've tried this w3schools

var vid = document.getElementById("myVideo");
vid.onloadeddata = function() {
    alert("Browser has loaded the current frame");
};

but with no luck.

Upvotes: 0

Views: 270

Answers (1)

Amine KOUIS
Amine KOUIS

Reputation: 1459

There is an event called oncanplay, which is triggered when the src of the video was loaded. try this code :

var video = document.getElementById("myVideo");
video.oncanplay = function() {
    alert("Start watching video");
};

Upvotes: 3

Related Questions