Documentation
¶
Overview ¶
Command controls gives media elements a control bar and stops them downloading until someone asks for them.
<video src="a.mp4"> -> <video src="a.mp4" controls="" preload="none"> <audio src="a.mp3"> -> <audio src="a.mp3" controls="" preload="none">
Two attributes, added for two different reasons. A media element with no controls is a player nobody can operate: it has no play button, no volume and no keyboard target, so a video that fails to start on its own is a black rectangle. preload="none" is about the other end of it - a page with six videos on it can ask a browser for six video files before anyone has decided to watch one - and the two attributes fight in exactly one case, which is why this program looks at the rest of the tag before adding either.
<video autoplay muted> a decorative background: controls would sit on it <video autoplay> preload="none" contradicts it: it must fetch to play <video preload="auto"> the page decided; not this program's business <video controls> already has one
So an element that autoplays keeps whatever preload the page gave it, and an element that autoplays muted - the shape a background video takes - is left without controls unless -all says otherwise. Both are counted, because "skipped" is a number a caller needs to see.
The attributes come out with values: controls="" is what the library writes for a boolean attribute, since there is no way through the C API to write a bare one. It means the same thing to a browser and looks different in a diff. See lolhtml.Element.SetAttribute.
One thing this program counts rather than assumes: media inside a <template>. Handlers fire in there - a template's content is markup to this library, at any depth of nesting - but that content is inert until a script clones it, so a video in a template is not a video on the page. This program rewrites it, on the grounds that the clone is a real player, and reports it separately so that the number it prints is not two numbers added together. -skip-templates leaves it alone. See the "Templates" section of the package documentation.