Reputation: 27527
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
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