Detect if client using HTML5 Youtube player

2019-08-05 10:59发布

问题:

On a page with an embedded YouTube player, is it possible to tell which version of the player is being used (HTML5 or Flash)?

回答1:

It turns out you can check for the existence/absence of certain properties on the player. The most obvious one is perhaps cueVideoByFlashvars, so you can do:

var isHtml5Player = !player.cueVideoByFlashvars;

As Jeff mentions it's not great to have to rely on this as it could change at any time.



回答2:

There is no supported API for determining that information, and it's not likely that one will be added.

While I'm sure that there are some hacks that take advantage of subtle differences in the way AS3 and HTML5 video behave in response to certain API calls, or to find a way of inspecting the DOM, I wouldn't recommend coding anything that fragile into a production-quality application.