Today I Learned - Rocky Kev

TIL Waiting for video to load event listeners

POSTED ON:

TAGS:

I wanted to fire an action in JS when there was enough video loaded that wouldn't cause a weird buffer.

I discovered the Media Events loadedmetadata, loadeddata, canplay, canplaythrough


const video = document.querySelector("video");

video.addEventListener("loadeddata", () => {

console.log("I have enough data to play now!");

});

So what's the difference between the Media Events?

(Media Events)[https://html.spec.whatwg.org/multipage/media.html#ready-states]

They return true when the readyState hits a certain threshold.

(Check their ready states)[https://html.spec.whatwg.org/multipage/media.html#ready-states]

HTML Documentation:
https://html.spec.whatwg.org/multipage/media.html#dom-media-have_current_data


Related TILs

Tagged:

TIL why you should always use textContent

Today I learned the difference between 'Node.textContent'. It handles all elements, even hidden ones. It also prevents XSS attacks since it strips tags.

TIL prepend

When you're creating new elements in Javascript, you want to attach the new element to something that exists in the DOM already. You do that with append, and prepend.

TIL the simulating a Pipe function

It’s a pipe function that allows you to chain multiple operations together by taking a series of functions as arguments and applying them in a specific order to the input.