What's the best way to detect if a browser supports autoplay of embedded media files?
Using the youtube javascript API, on iOS (and possibly Android) devices, if you call playVideo()
prior to the user tapping on the video, the video is put in a bad state and is basically useless. You might do this when you want to autoplay the video after the page loads, or you might have your own play/pause button.
There are lots of discussions on how to get autoplay to work (see below), but another way to deal with this is to detect when it shouldn't be called. The obvious answer would be to detect a specific device or OS using the user agent string, but I'm wondering if there's a better way to do it.
Related posts:
YouTube iFrame API hangs in buffering state after the playVideo() command on iPad
Can you autoplay HTML5 videos on the iPad?
来源:https://stackoverflow.com/questions/26895492/detect-if-browser-supports-autoplay-of-embedded-media-youtube-playvideo-and