Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26641
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: test for autoplay |
| Date | Wed, 21 Jan 2015 23:03:43 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 55 |
| Message-ID | <2227075.ZdhQdnHKJ3@PointedEars.de> (permalink) |
| References | <ttCdnYD1iYEQjl3JnZ2dnUVZ8v-dnZ2d@westnet.com.au> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1421877861 5868 eJwNyckRwDAIBLCWuJeUA9j0X0I8eso1OAYWHub7CJisR4dETu1WDbSos5X4IgF6lZePygf6ARoXELA= (21 Jan 2015 22:04:21 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Wed, 21 Jan 2015 22:04:21 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNyskBwDAIA7CZAjbHOEDC/iO0eotqx8ZhNHC54kBOGhk9HmJTefAQj/4f7ZrbPVoRd7uK4itvMzeQ1fkBR44V7g== |
| Cancel-Lock | sha1:l6NKF4QLIklFdVN0NDde2ad25Qk= |
| X-NNTP-Posting-Host | eJwVyckRACEIBMCUOGSAcMTdyT8Ey/52OBQnFwIrGCyGDvG5KdtQ/5ZpBQeOl8YtLVqozkLnBRiuEGk= |
| Xref | csiph.com comp.lang.javascript:26641 |
Show key headers only | View raw
Andrew Poulos wrote:
> I found this that looked worth trying
>
> var AUTOPLAY = false;
>
> (function() {
> var mp3 = 'data:audio/mpeg;base64,/[ a data URI here ];
>
> try {
> var audio = new Audio();
> audio.autoplay = true;
>
> $(audio).on('play', function() {
> AUTOPLAY = true;
> });
>
> audio.src = mp3;
> } catch(e) {
> // error
> }
> })();
>
> Alas I don't understand "$(audio).on('play', function() {"
>
> What is it doing?
This is the jQuery way of adding an event listener for the “play” event to
the element referred to by “audio”. Apparently the standards-compliant
audio.onplay = function () {
AUTOPLAY = true;
};
was too hard for them :->
This code creates an “audio” element in memory (using a proprietary
approach; the standards-compliant approach would be
“document.createElement("audio")”) and sets its “autoplay” property, thereby
the “autoplay” attribute of the corresponding element, to “true”. The
assumption is that if autoplay is supported, the “play” event is fired
immediately after the “src” property was assigned to, thereby the “src”
attribute was set, to refer to an MPEG-1/2 Audio Layer Ⅲ (mp3) resource by
“data:” URI. In that case, the value of the global “AUTOPLAY” variable
(both misguided and misplaced) is set to “true”.
This approach may or may not work as it may or may not be based on flawed
logic. One issue of several is that a decoder for mp3 may not be installed
in a browser on a mobile device.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
test for autoplay Andrew Poulos <ap_prog@hotmail.com> - 2015-01-22 07:55 +1100
Re: test for autoplay Scott Sauyet <scott.sauyet@gmail.com> - 2015-01-21 13:17 -0800
Re: test for autoplay Andrew Poulos <ap_prog@hotmail.com> - 2015-01-22 08:42 +1100
Re: test for autoplay Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-21 23:03 +0100
Re: test for autoplay "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-01-21 23:35 +0100
Re: test for autoplay Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-22 01:10 +0100
Re: test for autoplay "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-01-22 14:14 +0100
csiph-web