How do I detect if the HTML5 autoplay attribute is supported?
How do I detect if the HTML5 autoplay attribute is supported?
How do I best detect whether a browser's HTML5 video element supports autoplay?
On current iOS Safari, for example, autoplay is disabled.
Update: I now designed the web page in such a way that it works irrespective of whether autoplay is supported. Now when the page is loaded an initialization video is shown. On an iPad, the user is presented with a big play button. Once playback has been triggered, the video is hidden. Afterwards, playback of the video player can be controlled from JavaScript, which is what I actually need.
Answer by Paul D. Waite for How do I detect if the HTML5 autoplay attribute is supported?
As far as I can tell, neither Modernizr nor Dive into HTML5?s detection guide know how to detect whether autoplay
is supported. (Although Modernizr?s ?Undetectables? page doesn?t list autoplay
either.)
I?ve popped up a test page which alerts the value of the autoplay
property on a newly-created element, and both Safari on iOS 4.3 and Chrome 13 on Mac OS X return
false
(as opposed to undefined
, which is what IE 6 returns).
So, unfortunately, your best bet might be to resort to browser detection, and maintain your own list of which browsers support autoplay
.
Answer by Ethan for How do I detect if the HTML5 autoplay attribute is supported?
Maybe this will help future googlers like myself - this function creates/removes a video and tests to see if it can autoplay. It then sets a global variable "autoplay" to true or false. It tests for MP4 and webM compatibility, but adding more wouldn't be difficult if need be (just base 64 encode and append another source). The "acceptable delay" variable is how long it should reasonably take the device to start playing the test videos. With a combination of limited bandwidth/processing sometimes it makes sense to use the fallback (non autoplay) solution, even if autoplay is supported. I usually use 100ms.
function detect_autoplay(acceptable_delay){ autoplay = false; var autoplay_test_content = document.createElement('video'); //create mp4 and webm sources, 5s long var mp4 = document.createElement('source'); mp4.src = "data:video/mp4;base64,AAAAFGZ0eXBNU05WAAACAE1TTlYAAAOUbW9vdgAAAGxtdmhkAAAAAM9ghv7PYIb+AAACWAAACu8AAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAnh0cmFrAAAAXHRraGQAAAAHz2CG/s9ghv4AAAABAAAAAAAACu8AAAAAAAAAAAAAAA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B8YIUzLuNs4ILuLeH94EB8YIUzLuNs4INBbeH94EB8YIUzLuNs4IOU7eH94EB8YIUzLuNs4IPoLeH94EB8YIUzLuNs4IQ7beH94EB8YIUzLuNs4ISO7eH94EB8YIUzBFNm3SPTbuMU6uEH0O2dVOsghTM"; //append sources to test video autoplay_test_content.appendChild(webm); autoplay_test_content.appendChild(mp4); //set attributes -needs to be visible or IE squawks, so we move it way outside autoplay_test_content.id = "base64_test_video"; autoplay_test_content.autoplay = true; autoplay_test_content.style.position = "fixed"; autoplay_test_content.style.left = "5000px"; //add to DOM document.getElementsByTagName("body")[0].appendChild(autoplay_test_content); var base64_test_video = document.getElementById("base64_test_video"); //test for autoplay, 100 ms buffer setTimeout(function(){ if(!base64_test_video.paused){ autoplay = true; } document.getElementsByTagName("body")[0].removeChild(autoplay_test_content); },acceptable_delay); } detect_autoplay(100);
Answer by Chip for How do I detect if the HTML5 autoplay attribute is supported?
I realize this is a video question - and it applies to audio too.
I have built an audio test with the intention of loading it into Moderizr with Modernizr.addTest()
.
The results are surprising and very dependent on platform and system state. Turns out there are several Android browsers that support autoplay. Who knew.
From looking at GitHub, I imagine the Modernizr guys will figure all this out more reliably and elegantly than I have - if they haven't already. It seems to boil down to timing. You'd think the browsers guys would throw us a bone here. Maybe they will.
Anyway, here is the jsfiddle link: Audio().autoplay test.
While there is fluff code in the jsfiddle example, here's the core:
var supportsAutoplay = false; //assume var audio = new Audio(); var waitTime; audio.autoplay = true; audio.volume = 0; // this will only be triggered if autoplay works audio.addEventListener('play', function () { supportsAutoplay = true; }); audio.src = testSrc; //see if the listener is listening setTimeout( //wait for listener to run function(){ return supportsAutoplay; }, waitTime );
While I have not seen one with a setTimeout
other than the one above (the Modernizr guys talk about it), there are several versions of this code around. I guess I'll credit Peter Coles. Maybe his version is less likely to suffer from timing issues.
Answer by JosselinTD for How do I detect if the HTML5 autoplay attribute is supported?
Maybe I respond a little bit late but I just test a solution which work fine for me :
var loadStarted = false; video.onloadstart = function(){ loadStarted = true; }; function checkRunning(){ if(!loadStarted) removeVideo(); } setTimeout(checkRunning, 1000);
The setTimeout is not very clean, but the overall solution is super simple like that !
Answer by schellmax for How do I detect if the HTML5 autoplay attribute is supported?
A little late to the party, but the accepted solution seems outdated: Modernizr now has implemented this feature, see https://github.com/Modernizr/Modernizr/blob/master/feature-detects/video/autoplay.js
Contains similar hacks to the other solutions posted here though, but as long as browsers don't expose availabilty of this feature, this seems to be the best solution for now.
Note that this an async test available since Modernizr 3, so you have to use the following .on()
syntax for your test:
Modernizr.on('videoautoplay', function(result){ if(result) { alert('video autoplay is supported'); } else { alert('video autplay is NOT supported'); } });
See for yourself: http://codepen.io/anon/pen/VYoWWY?editors=001
The above sample includes Modernizr 3 with the 'videoautplay' feature detection (http://v3.modernizr.com/download/#-videoautoplay).
Answer by Nathan for How do I detect if the HTML5 autoplay attribute is supported?
Here's an alternative solution that uses a callback and session storage to test for HTML5 video autoplay support. Once the test is preformed and the session storage exist the check isn't preformed again until the next session. This saves from running this every time a page loads. It uses a base64'd 1 second blank video clip to test for autoplay support.
https://gist.github.com/nathansearles/271870d4100f0f045c5c
// isAutoplaySupported(callback); // Test if HTML5 video autoplay is supported isAutoplaySupported = function(callback) { // Is the callback a function? if (typeof callback !== 'function') { console.log('isAutoplaySupported: Callback must be a function!'); return false; } // Check if sessionStorage exist for autoplaySupported, // if so we don't need to check for support again if (!sessionStorage.autoplaySupported) { // Create video element to test autoplay var video = document.createElement('video'); video.autoplay = true; video.src = 'data:video/mp4;base64,AAAAIGZ0eXBtcDQyAAAAAG1wNDJtcDQxaXNvbWF2YzEAAATKbW9vdgAAAGxtdmhkAAAAANLEP5XSxD+VAAB1MAAAdU4AAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAACFpb2RzAAAAABCAgIAQAE////9//w6AgIAEAAAAAQAABDV0cmFrAAAAXH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AAwAOmAAAABdBm3hJqEFsmUwIK//+tSqAAAADAAAdUQAAABFBn5ZFFSwV/wAAAwAAAwAOmAAAAA8Bn7V0QV8AAAMAAAMADpkAAAAPAZ+3akFfAAADAAADAA6ZAAAAF0GbvEmoQWyZTAgr//61KoAAAAMAAB1QAAAAEUGf2kUVLBX/AAADAAADAA6ZAAAADwGf+XRBXwAAAwAAAwAOmAAAAA8Bn/tqQV8AAAMAAAMADpkAAAAXQZv9SahBbJlMCCv//rUqgAAAAwAAHVE='; video.load(); video.style.display = 'none'; video.playing = false; video.play(); // Check if video plays video.onplay = function() { this.playing = true; }; // Video has loaded, check autoplay support video.oncanplay = function() { if (video.playing) { sessionStorage.autoplaySupported = 'true'; callback(true); } else { sessionStorage.autoplaySupported = 'false'; callback(false); } }; } else { // We've already tested for support // use sessionStorage.autoplaySupported if (sessionStorage.autoplaySupported === 'true') { callback(true); } else { callback(false); } } } // Usage: isAutoplaySupported(callback); // Using a callback assures that support // has been properly checked isAutoplaySupported(function(supported) { if (supported) { // HTML5 Video Autoplay Supported! console.log('HTML5 Video Autoplay Supported!'); } else { // HTML5 Video Autoplay Not Supported :( console.log('HTML5 Video Autoplay Not Supported :('); } });
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
Thanks for sharing this informative information...You may also refer....
ReplyDeleteHow to migrate from a typical HTML4 page to a typical HTML5 page.
www.s4techno.com/blog/2016/08/30/html5-migration/