Autoplay, go away!

, , , , ,

HTML5 has an autoplay attribute on the audio and video elements. Ostensibly, this is a problem for those who work in shared offices and who aren’t expecting sound to blare out when following a link, and would be a huge problem for people who rely on sound for understanding the Web, such as those using a screenreader, because the sound in a video would drown out all other content on the page.

Paradoxically, however, this could be good for accessibility. Simon Pieters points out

Removing the attribute will not make pages stop autoplaying video. Instead they will use script to make videos autoplay, and then it becomes harder for the user to prevent videos from autoplaying. (You could have a pref in the UA to disable autoplay.)

The idea is that a simple attribute is easier to write than scripts that force autoplay, and therefore content providers will use it. It's also much easier to write user scripts that block the autoplay attribute. Until Opera has a "never autoplay media" option in the configuration settings (soon!), you may wish to use this tiny Opera Extension Autoplay, Go Away! by Daniel Davis, Philip Jägenstedt, Bruce Lawson and Simon Pieters.

Why so many authors? Because it wasn't completely simple to write. Originally, Bruce had written


var els = document.querySelectorAll('video, audio');
for (var i= els.length - 1; i >= 0; i--)  {
	els.removeAttribute('autoplay');
	els.setAttribute('title', 'right-click to start media');
}

This simply loops through all media elements, removing the autoplay attribute if present, and adding an informative title. It worked perfectly on a test page in which linked to media stored locally, but failed on a test page that calls in media across the network.

Of all the HTML5 APIs, the media events are the subtlest and hardest to grasp to people not as brainy as Philip and Simon, with whom I consulted, who came up with the code that powers the extension:


window.addEventListener('loadstart', function(e) 
        {e.target.removeAttribute('autoplay') }, true);

which works pretty well on Mac and Linux, with some unduplicatable weirdnesses on Windows. It doesn't work for elements not in the document or for scripts that do play().

Anyway, please do any virus checking you feel you need to do (this isn't an official Opera extension) and download Autoplay, Go Away! beta 1.

And I'm available for freelance icon design, too.

Beta 2

I got some useful feedback from John Foliot who said

[the] title [attribute] is affected by the verbosity settings in screen readers, with the net result that for most power users of screen reader technology, the value of title is not read aloud more often than not … title should not be used to convey mission critical information, as many screen readers will miss it.

When planning how to do this, I had previously not used title, but instead had added the controls attribute but backed that out because it would disrupt the lovely design of someone's custom video player. But if they're so rude as to force autoplaying media, who cares about their design? So beta two dispenses with adding a title and adds controls instead.

Anyway, please do any virus checking you feel you need to do (this isn't an official Opera extension) and download Autoplay, Go Away! beta 2.

An Opera of Creativity at NAConf!"Making your site mobile-friendly" presentation at M-Days 2011, Frankfurt

Comments

João EirasxErath Friday, January 28, 2011 5:39:12 PM

a) if autoplay is so undesirable, and wastes bandwidth, why having it in the spec in the 1st place ?
b) like on demand plugins, there should be a very visible pref in the browser UI to disable auto-play of video, and to turn off sound.

Cutting Spoonhellspork Friday, January 28, 2011 5:57:45 PM

Thanks for this, downloading.

Also I commend you for that awesome image in the sidebar of your blog.

Rafael Luikrafaelluik Friday, January 28, 2011 7:50:46 PM

Originally posted by xErath:

a) if autoplay is so undesirable, and wastes bandwidth, why having it in the spec in the 1st place ?

Can't you see most people do want autoplay? It's great for 90% of people on YouTube... If they had to click play they'd become angry having to repeat the action of clicking play in every video.

Robert MeijersRobert90 Friday, January 28, 2011 8:04:35 PM

Originally posted by xErath:

a) if autoplay is so undesirable, and wastes bandwidth, why having it in the spec in the 1st place ?


"The idea is that a simple attribute is easier to write than scripts that force autoplay, and therefore content providers will use it. It's also much easier to write user scripts that block the autoplay attribute."

Originally posted by xErath:

b) like on demand plugins, there should be a very visible pref in the browser UI to disable auto-play of video, and to turn off sound.


"Until Opera has a "never autoplay media" option in the configuration settings (soon!)"


Both "answers" are quotes from Bruces articles. So if you had read the article carefully you didn't have to ask those questions wink

Laurentlsaplai Saturday, January 29, 2011 6:43:46 AM

With countries like Canada starting to charge for traffic on the web*, Autoplay is going to hurt some wallets very badly.

So thank you for providing this extension and for the upcoming option to disable Autoplay in the browser.

*check out: http://openmedia.ca/meter for more details

Cutting Spoonhellspork Monday, January 31, 2011 6:41:08 PM

Originally posted by lsaplai:

Canada starting to charge


I hear their law against prostitution was struck down by the court? Everybody's got their own priorities...

Martin RauscherHades32 Tuesday, February 1, 2011 4:03:38 PM

I'm not a JS Guru, but shouldn't it be "els.removeAttribute(...)" instead of just "els.rem..."?

While Philip and Simon's script might be cleverer, why not simply append a "els.stop()" (or whatever the call is named), in case the media did already start to buffer/play, to your script? Would "stop()" also stop the buffering?

Originally posted by hellspork:

I hear their law against prostitution was struck down by the court? Everybody's got their own priorities...


It's more than obvious that you are an American bigsmile

Bruce Lawsonbrucelawson Thursday, February 3, 2011 11:32:46 AM

Martin Rauscher -

video.pause() sounds like a good idea. Will try it.

Jimtoyotabedzrock Tuesday, February 15, 2011 9:55:19 PM

We should have a default sound level setting in the browser as well.

Write a comment

New comments have been disabled for this post.