HTMLMediaElement.canPlayType()
developer.mozilla.org
developer.mozilla.org
As the method returns strings anyways and `maybe` is pretty unhelpful, I request the return be changed to '¯\_(ツ)_/¯' (which is equally unhelpful, but at least a bit more fun).
MediaCapabilities is the new way to ask the "can I play this" question: https://developer.mozilla.org/en-US/docs/Web/API/Media_Capab...
It returns a boolean for whether a codec is supported or not.
https://developer.mozilla.org/en-US/docs/Web/API/MediaCapabi... is on the way. I believe the latest Safari preview has it implemented and Chromium should have it shortly as well.
It's a very old API that was speced before promises were a thing. Once you ship an API, sites start using it, and if you change behavior, you break them. If your browser ships the behavior change first, and breaks a website, people just assume your browser is the one that's broken, and switch browser. So browsers don't like to change behavior, especially before other browsers have, or if other browsers won't.
At least in Firefox's case, it's hard to be confident that the decoders we use for H.264 (the most commonly used codec at the time) would support a given mime type.
Firefox uses the operating system's H.264 decoders, because we had a policy of not feeding the patent trolls. H.264 has a plethora of different levels, profiles and features [1]. The documentation for operating system's H.264 decoders often isn't very clear as to what profiles/levels/features they support. Sometimes the user has installed codec packs which affect what codecs are playable. Sometimes the user is on Windows K/N which ships without H.264 codecs. So the only way to give an accurate answer to the question, is to actually start up Windows Media Foundation, and run some video through them. This requires loading DLLs from disk, and obviously we don't want to be blocking on disk IO in the browser's JS event loop in order to accurately answer this question, and we might not have an example file for the specific combination of profile/level/features the script was asking about. In the end, we ended up doing a "test decode" on startup of the common profiles and caching the result in the user's profile. But again, if the user asks about an obscure profile or level combination we've not tried, we can't necessarily be confident that we'll actually be able to play this.
Saying "yes" optimistically and being wrong would be bad, as then the player would appear to be broken in your browser, leading users to switch browser. So the idea was script would try a few profile/level/feature combinations and pick the best to which the browser returned yes.
We probably could have done a more accurate job here if we had more time, but it's always a trade off between marginal benefits here, verses fixing something else.
[1] https://blog.pearce.org.nz/2013/11/what-does-h264avc1-codecs...
> For example, codecs="av01.0.04M.10.0.112.09.16.09.0" represents AV1 Main Profile, level 3.0, Main tier, 10-bit content, non-monochrome, with 4:2:0 chroma subsampling co-located with (0, 0) luma sample, ITU-R BT.2100 color primaries, ITU-R BT.2100 PQ transfer characteristics, ITU-R BT.2100 YCbCr color matrix, and studio swing representation.
But how the hell am I supposed to reliably figure that out. It would be awesome if the browser devtools or the Media API could spit out the right string for a video file.
> If the browser is not aware of any of these
In my case the browser is playing the file, so it should know what info is there. But ideally it would at least make a best-effort attempt.
The whole spec is unbelievably complex just to tell which codec and profile to use for the media player.
[0]:https://developer.mozilla.org/en-US/docs/Web/Media/Formats/c...
- Maybe: the mime type is likely a container, and there are a wide range of possible contained formats… some supported, some not. As in the example, mp4 is such a container.
- Probably: this is either a known format that’s definitely supported (boolean true) or a container format with a narrower range of contained formats, all of which are likely to be supported if any are. Newer or more obscure containers will more likely fall in this category.
I hate to imagine the bikeshedding that must have gone into this API.
I can't imagine any comprehensively bikeshedded API that wouldn't result in a number being returned here. And it's in the HTML5 spec., which has a reputation for being dictatorially authored by a single individual.
I thought it might be that each value is specified to correspond to some specific confidence, but the spec. is extremely and deliberately vague, which makes the whole thing even more useless as that will inevitably just lead to different implementers returning inconsistent values for arbitrary confidences.
How come so much incompetence is concentrated in those places, and what can be done about that?
Has it crossed your mind that you are less informed about the trade-offs and limitations of browser media stacks 15 years ago, and the design is baffling to you, because your opinion comes from ignorance?