[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Audio autoplay again

Andrew Poulos

1/22/2015 11:26:00 PM

I'm try to test if HTML5 audio can auto play so I'm creating an audio
element, setting its autoplay property to true and then waiting to see
if the play event gets triggered.

I have set a 3 second timeout to catch if the audio doesn't trigger play.

The problem is that if the audio takes more than 3 seconds to load/start
the timeout triggers.

What audio event should I use to "contain" the timeout? I've looked at
load and canplaythrough but I'm not concerned with whether or not the
whole audio can play but whether it will start playing or not.

Andrew Poulos
16 Answers

Scott Sauyet

1/23/2015 1:36:00 PM

0

Andrew Poulos wrote:
> The problem is that if the audio takes more than 3 seconds to load/start
> the timeout triggers.

I'm not actually sure if the following is possible; I've never tried it.

Could you embed an extremely minimal audio sample in a data URI? That
would skip the wait for an external load and require only the parsing
of that data URI.

Of course this would limit your autoplay detection to those browsers that
support data URIs, but I'm assuming you already have some fallback plan
for those that don't support autoplay, so perhaps it could work for these
older browsers as well?

-- Scott

Dr.Kral

1/23/2015 10:15:00 PM

0

On Fri, 23 Jan 2015 10:26:17 +1100, Andrew Poulos <ap_prog@hotmail.com>
wrote in <7qudnc66lNbiFVzJnZ2dnUVZ8iednZ2d@westnet.com.au>:

>I'm try to test if HTML5 audio can auto play so I'm creating an audio
<snip>

Have you considered that some people who go to your page do NOT want to
disturb other people with a sound blast? And that others are not ready to
give you that sort of attention (since your previous post mention video)?

Personally, that is one thing that will drive me away from your page
immediately. And not just me -- the weather.com page reported that the
number one change people wanted was to NOT to turn on a video with sound.

Frankly, auto start audio/video is extremely rude except, perhaps, when
going to a video directly.

JMHO.

Christoph M. Becker

1/23/2015 10:30:00 PM

0

Andrew Poulos wrote:

> I'm try to test if HTML5 audio can auto play so I'm creating an audio
> element, setting its autoplay property to true and then waiting to see
> if the play event gets triggered.

I'm wondering whether the `paused` attribute can be utilized instead of
the `play` event. I don't know, but it might be worth investigating.

--
Christoph M. Becker

Andrew Poulos

1/24/2015 12:37:00 AM

0

On 24/01/2015 9:14 AM, Dr.Kral@nyc.rr.com wrote:
> On Fri, 23 Jan 2015 10:26:17 +1100, Andrew Poulos <ap_prog@hotmail.com>
> wrote in <7qudnc66lNbiFVzJnZ2dnUVZ8iednZ2d@westnet.com.au>:
>
>> I'm try to test if HTML5 audio can auto play so I'm creating an audio
> <snip>
>
> Have you considered that some people who go to your page do NOT want to
> disturb other people with a sound blast? And that others are not ready to
> give you that sort of attention (since your previous post mention video)?
>
> Personally, that is one thing that will drive me away from your page
> immediately. And not just me -- the weather.com page reported that the
> number one change people wanted was to NOT to turn on a video with sound.
>
> Frankly, auto start audio/video is extremely rude except, perhaps, when
> going to a video directly.

I'm working on some elearning courses where its generally expected that
media autoplays.

Andrew Poulos

Andrew Poulos

1/24/2015 12:56:00 AM

0

On 24/01/2015 12:36 AM, Scott Sauyet wrote:
> Andrew Poulos wrote:
>> The problem is that if the audio takes more than 3 seconds to load/start
>> the timeout triggers.
>
> I'm not actually sure if the following is possible; I've never tried it.
>
> Could you embed an extremely minimal audio sample in a data URI? That
> would skip the wait for an external load and require only the parsing
> of that data URI.

I'm finding that browsers are not consistently playing data URI and
"normal" MP3 files. I created a 1 second low quality MP3 or silence and
it wouldn't play (I'm guessing it didn't play because onplay never
triggered). I've tried files of different bit rates and found the lower
rates failing.

It needs lots of testing.

> Of course this would limit your autoplay detection to those browsers that
> support data URIs, but I'm assuming you already have some fallback plan
> for those that don't support autoplay, so perhaps it could work for these
> older browsers as well?

On devices that won't autoplay I'm going to display a message to tell
users to click a play button.

Andrew Poulos


Andrew Poulos

1/24/2015 1:02:00 AM

0

On 24/01/2015 9:30 AM, Christoph M. Becker wrote:
> Andrew Poulos wrote:
>
>> I'm try to test if HTML5 audio can auto play so I'm creating an audio
>> element, setting its autoplay property to true and then waiting to see
>> if the play event gets triggered.
>
> I'm wondering whether the `paused` attribute can be utilized instead of
> the `play` event. I don't know, but it might be worth investigating.

I'll have a look.

Currently I'm testing calling play() without setting autoplay and then
testing for onplay because it seems to me that devices that let you
start playback using code also allow autoplay.

Andrew Poulos

Christoph M. Becker

1/24/2015 1:30:00 AM

0

Andrew Poulos wrote:

> Currently I'm testing calling play() without setting autoplay and then
> testing for onplay because it seems to me that devices that let you
> start playback using code also allow autoplay.

If I'm not mistaken, "all" browsers accept play(), if it is called on
direct user interaction, e.g.

button.onclick = function () {
audio.play();
};

should work "everywhere" (e.g. on iOS), whereas

window.onload = function () {
audio.play();
};

does not necessarily.

--
Christoph M. Becker

Andrew Poulos

1/24/2015 2:08:00 AM

0

On 24/01/2015 12:29 PM, Christoph M. Becker wrote:
> Andrew Poulos wrote:
>
>> Currently I'm testing calling play() without setting autoplay and then
>> testing for onplay because it seems to me that devices that let you
>> start playback using code also allow autoplay.
>
> If I'm not mistaken, "all" browsers accept play(), if it is called on
> direct user interaction, e.g.
>
> button.onclick = function () {
> audio.play();
> };
>
> should work "everywhere" (e.g. on iOS), whereas
>
> window.onload = function () {
> audio.play();
> };
>
> does not necessarily.
>
Yes, you're right.

Perhaps I should've said "devices that let you start playback using
code, without any user input, also allow autoplay."

Andrew Poulos

Thomas 'PointedEars' Lahn

1/24/2015 2:30:00 PM

0

Andrew Poulos wrote:

> I'm try to test if HTML5 audio can auto play [â?¦]

Your current approach of creating a new thread for a subject discussed only
days ago in a thread also started by you is not appreciated.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Andrew Poulos

1/26/2015 1:31:00 AM

0

On 25/01/2015 1:29 AM, Thomas 'PointedEars' Lahn wrote:
> Andrew Poulos wrote:
>
>> I'm try to test if HTML5 audio can auto play [â?¦]
>
> Your current approach of creating a new thread for a subject discussed only
> days ago in a thread also started by you is not appreciated.

To me it was a different aspect of the problem and so deserved a new thread.

At any rate, when we did the accessibility testing having a screen
reader reading the screen while a piece of audio autoplays is unacceptable.

Andrew Poulos