W3C home > Mailing lists > Public > public-audio@w3.org > October to December 2012

Re: how to detect the end of a playing sound ?

From: Chris Rogers <crogers@google.com>
Date: Wed, 31 Oct 2012 10:41:02 -0700
Message-ID: <CA+EzO0m3eeyhGi4D_yj4SJ0hQnCBYwetFyF7YdMprs+SaENfzQ@mail.gmail.com>
To: Jerome Etienne <jerome.etienne@gmail.com>
Cc: public-audio@w3.org
On Wed, Oct 31, 2012 at 4:39 AM, Jerome Etienne <jerome.etienne@gmail.com>wrote:

> Hello,
>
> i would like to play multiple sounds (songs in mp3) one after the other.
> Is there a way to detect the end of a playing sound ? an event endOfSound
> or something like that ?
>
> Currently i storing the duration of the currently playing sound, do a
> settimeout which is triggered after this time, when it is triggered, i stop
> the current sound and start the new one... rather clumsy. is there a better
> way ?
>

You should be able to schedule the new one to start at exactly the time
when the old one ends - in other words seamless, gap-free playback.  Since
you know the start time of the first sound, and its duration, something
like:

sound1.start(time1);
sound2.start(time1 + duration1);

Of course, the second start call could be made immediately as in this
example, or called at a later time, as long as it's before the first sound
has finished.  You could use a setTimeout() for that with a comfortable
safety margin.


> Jerome
>
Received on Wednesday, 31 October 2012 17:41:34 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:50:03 UTC