Hi All,
I encountered recently the following strange behavior of JS:
I need to create a simple page that contains one button. After clicking it
there should be generated two short sounds with a 0,5s gap between them. The
code looks as follows:
<html>
<EMBED SRC="sound1.wav" LOOP=FALSE AUTOSTART=false HIDDEN=true>
<EMBED SRC="sound2.wav" LOOP=FALSE AUTOSTART=false HIDDEN=true>
<script language="JavaScript">
function PlaySounds() {
document.embeds[0].play();
for (j=1;j<=100000;j++) {a=Math.log(1)}
document.embeds[1].play();
}
</script>
<button onClick="PlaySounds()">Play sounds</button>
</html>
Please look at three rows of PlaySounds function. The for loop is used to
introduce 0,5 s delay, but depending on processor speed it may take longer
or shorter.
It seems like there should be emitted the first sound, then 0,5 silence and
second sound. As I experienced IT IS NOT SO! First there is the loop
executed and then both sounds mixed, emitted simultaneously!
Why???
And the second qestion, how to achieve desired effect? Please do not advice
me the setTimeout function because with long series of sound samples it
works improperly.
Regards,
Grzegorz 3 1845
Grzegorz wrote: I encountered recently the following strange behavior of JS: I need to create a simple page that contains one button. After clicking it there should be generated two short sounds with a 0,5s gap between them. The code looks as follows:
<html> <EMBED SRC="sound1.wav" LOOP=FALSE AUTOSTART=false HIDDEN=true> <EMBED SRC="sound2.wav" LOOP=FALSE AUTOSTART=false HIDDEN=true>
<script language="JavaScript">
function PlaySounds() { document.embeds[0].play(); for (j=1;j<=100000;j++) {a=Math.log(1)} document.embeds[1].play(); }
</script> <button onClick="PlaySounds()">Play sounds</button> </html>
Please look at three rows of PlaySounds function. The for loop is used to introduce 0,5 s delay, but depending on processor speed it may take longer or shorter. It seems like there should be emitted the first sound, then 0,5 silence and second sound. As I experienced IT IS NOT SO! First there is the loop executed and then both sounds mixed, emitted simultaneously! Why??? And the second qestion, how to achieve desired effect? Please do not advice me the setTimeout function because with long series of sound samples it works improperly.
Use setTimeout. Your loop blocks the browser.
--
Martin Honnen http://JavaScript.FAQTs.com/
In article <bs**********@news.onet.pl>, "Grzegorz" <gr******@op.pl> writes: Hi All,
I encountered recently the following strange behavior of JS: I need to create a simple page that contains one button. After clicking it there should be generated two short sounds with a 0,5s gap between them. The code looks as follows:
<script language="JavaScript">
use type="text/javascript" instead, language is deprecated.
function PlaySounds() { document.embeds[0].play(); for (j=1;j<=100000;j++) {a=Math.log(1)} document.embeds[1].play(); }
</script> <button onClick="PlaySounds()">Play sounds</button>
Please look at three rows of PlaySounds function. The for loop is used to introduce 0,5 s delay, but depending on processor speed it may take longer or shorter.
No, you think its introducing a 1/2 second delay, but as you say, it doesn't
work. Thats not how you do it in javascript.
It seems like there should be emitted the first sound, then 0,5 silence and second sound. As I experienced IT IS NOT SO! First there is the loop executed and then both sounds mixed, emitted simultaneously! Why???
Because too many other things can affect the speed at which it happens. My IE6
executes it the same way. But my processor is fast. On a 386 processor, it
would run slower.
And the second qestion, how to achieve desired effect? Please do not advice me the setTimeout function because with long series of sound samples it works improperly.
If you do not want to use the proper way to introduce a delay, your only other
option would be to edit the sound files and make a new file, with the delays
built in.
Or, use a blank sound file (of 1/2 second length) and then instead of embedding
the sounds, embed an .m3u file instead and play it.
--
Randy
Grzegorz wrote: Hi All,
I encountered recently the following strange behavior of JS: I need to create a simple page that contains one button. After clicking it there should be generated two short sounds with a 0,5s gap between them. The code looks as follows:
<html> <EMBED SRC="sound1.wav" LOOP=FALSE AUTOSTART=false HIDDEN=true> <EMBED SRC="sound2.wav" LOOP=FALSE AUTOSTART=false HIDDEN=true>
<script language="JavaScript">
function PlaySounds() { document.embeds[0].play(); for (j=1;j<=100000;j++) {a=Math.log(1)} document.embeds[1].play(); }
</script> <button onClick="PlaySounds()">Play sounds</button> </html>
Please look at three rows of PlaySounds function. The for loop is used to introduce 0,5 s delay, but depending on processor speed it may take longer or shorter. It seems like there should be emitted the first sound, then 0,5 silence and second sound. As I experienced IT IS NOT SO! First there is the loop executed and then both sounds mixed, emitted simultaneously! Why??? And the second qestion, how to achieve desired effect? Please do not advice me the setTimeout function because with long series of sound samples it works improperly.
Regards, Grzegorz
You are hearing them at the same time, likely, because the sound does
not actually play, until the javascript block has ended. The message to
play the sound is queued up, and when the block ends, it plays it... and
the next one.
There have only been, in my experience, a few situations where
busy-waits are appropriate when programming... and they have all been in
embedded systems, at the microprocessor level. In _ALL_ other cases,
the programming environment provided me with the resources to do a
non-blocking sleep.
In Javascript, it is setTimeout. I am not familiar with embedding
sounds, but you _might_ be able to use setTimeout to probe when the
sound has finished, and set the next timeout to play the next sound...
just a stab in the dark.
Brian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: AIM |
last post by:
Error in msvc in building inheritance.obj to build hello.pyd
Hello,
I am trying to build the boost 1.31.0 sample extension hello.cpp.
I can not compile the file inheritance.cpp because the two...
|
by: Gregory |
last post by:
Hi,
One of the disadvantages of using error handling with error codes
instead of exception handling is that error codes retuned from a
function can be forgotten to check thus leading to...
|
by: deko |
last post by:
I use this convention frequently:
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
|
by: p |
last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also
have Crystal 9 pro on my development machine. The web app runs fine on my
dev machine but am having problems deploying....
|
by: Manuel |
last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using
devc++.
So I've imported the glut32.dsp into devc++, included manually some
headers, and start to compile.
It return a very...
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: ...
|
by: hyperpau |
last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding.
I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com).
Ergo, I...
|
by: hyperpau |
last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding.
I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com).
Ergo, I...
|
by: yashu0209 |
last post by:
I have an error occurring when i try to compile the program and the error is:
D:\Program Files\visual studio 6.0\MSDev98\MyProjects\GLEnabledView\GLNew.cpp(164) : error C2653: 'CGLEnabledView' :...
|
by: randa zaghdan |
last post by:
Hi
I have a problem with my program in vc 2008
When I compile it, the following errors are listed.
I try to resolve it but no hope
Does any one can help me ?
thanks .
Linking......
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |