473,549 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why is "how to play a sound with Javascript" such a rare topic?


I did a search on the newsgroup comp.lang.javas cript. I was searching
for "how to play a sound with Javascript". I'm somewhat suprised that
the majority of entries are from the 1990s, and there are almost no
posts from the last 3 years:

http://groups.google.com/group/comp....rch+this+group

Even after sorting by date, there don't appear any entries more recent
than 2006, and there are only 3 from 2006.

If I were to chart the frequency of questions about sound on a graph,
it would appear there was great interest in the question during the
1990s, and then that interest faded away, disappearing almost entirely
after 2004.

Why is that? Did Flash become good enough and widespread enough that
programmers now rely on it completely when trying to get sound to play
on a site? Is there the sense that it is too difficult to use
Javascript to play a sound on a web page?

I was working on some Ajax chat software and I was asked to make a
sound play when someone posted a new message to a chat room. I was
thinking of doing this in a pure-Javascript way, but perhaps that is
to be advised against? Should I use Flash instead?

I asked my friends for a pure Javascript solution and they pointed me
to a script that still involves Flash:

http://www.boutell.com/newfaq/creating/scriptsound.html
Feb 26 '08 #1
26 3861
On Feb 26, 12:30*am, Jake Barnes <lkrub...@geoci ties.comwrote:
I did a search on the newsgroup comp.lang.javas cript. I was searching
for "how to play a sound with Javascript". I'm somewhat suprised that
the majority of entries are from the 1990s, and there are almost no
posts from the last 3 years:

http://groups.google.com/group/comp....rch?group=comp...

Even after sorting by date, there don't appear any entries more recent
than 2006, and there are only 3 from 2006.
It is a rare Web page that needs to make use of sounds.
>
If I were to chart the frequency of questions about sound on a graph,
it would appear there was great interest in the question during the
1990s, and then that interest faded away, disappearing almost entirely
after 2004.

Why is that? Did Flash become good enough and widespread enough that
programmers now rely on it completely when trying to get sound to play
on a site? Is there the sense that it is too difficult to use
Javascript to play a sound on a web page?
Flash is not "good enough" for much of anything IMO. It is a rare Web
page that needs to make use of Flash.

There may be a sense that it is too difficult to play sounds with
JavaScript, but it is nonsense. The issues involved are virtually
identical to those involved with using Flash. The difference is that
there are tons of (incompetent) Flash scripts out there (most notably
the one provided by Adobe), but few that deal with audio plug-ins.
>
I was working on some Ajax chat software and I was asked to make a
sound play when someone posted a new message to a chat room. I was
thinking of doing this in a pure-Javascript way, but perhaps that is
to be advised against? Should I use Flash instead?
No, you had it right to begin with.
>
I asked my friends for a pure Javascript solution and they pointed me
to a script that still involves Flash:

http://www.boutell.com/newfaq/creating/scriptsound.html
Then they pointed you to an inappropriate script.

If you are writing an Ajax chat application, then you should be able
to tackle this. As with Flash, you need two branches, one that checks
the plugins and/or mimeTypes collections to determine support for your
chosen format and a fallback for IE and its various derivations (e.g.
old AOL browsers, which have no such collections (the feature
detection pattern should be obvious.)

The first branch adds an object element to the body to play a sound
and removes it after a suitable delay (which cannot be calculated
exactly as it takes time to download the file and load the plug-in.)
I use two object elements to allow for music and sounds to play
simultaneously. You can "preload" the plug-in with dummy (silent)
audio file(s) when the page loads, but still need to pad the duration
to allow time for the initial download.

The second branch adds a bgsound element (or two) to the head and
changes the src property to play sounds. You can actually preload the
sound files with this method as you can play sounds silently by
manipulating the volume property. This works much better than the
other method as you never have to remove the elements, so there is no
need to pad the play time.
Feb 26 '08 #2
SAM
Jake Barnes a écrit :
>
I asked my friends for a pure Javascript solution and they pointed me
to a script that still involves Flash:

http://www.boutell.com/newfaq/creating/scriptsound.html
It's the best.

Anyway it is impossible to play a sound in JS ...
a sound can only be played by a plug-in and there was so much plug-ins
to play sound whom each one with its proper JS commands, in these
conditions how to be sure to have thought to all of them?

Today it is not very important any more to use a heavy mp3 instead of
light midi
Flash play mp3 and can be driven via JS
Flash is present on 90% of home computers
so ... at this date ... it's the solution

--
sm
Feb 26 '08 #3
On Feb 26, 9:21*am, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
wrote:
Jake Barnes a écrit :
I asked my friends for a pure Javascript solution and they pointed me
to a script that still involves Flash:
http://www.boutell.com/newfaq/creating/scriptsound.html

It's the best.
How so?
>
Anyway it is impossible to play a sound in JS ...
a sound can only be played by a plug-in and there was so much plug-ins
to play sound whom each one with its proper JS commands, in these
conditions how to be sure to have thought to all of them?
You really don't have to consider the plug-in at all.
>
Today it is not very important any more to use a heavy mp3 instead of
light midi
Flash play mp3 and can be driven via JS
I didn't follow that, but you can certainly play MP3's using the
methods I described. In fact, they work best for longer clips as most
plug-ins will stream them.
Flash is present on 90% of home computers
That isn't a comforting statistic. And not all of those Flash
installations will support interaction with JavaScript.
so ... at this date ... it's the solution
Of course, there aren't any decent scripts out there for Flash.

Quoting the first two lines from the "SoundManag er" script:

var isIE = navigator.appNa me.toLowerCase( ).indexOf('inte rnet explorer')
+1;
var isMac = navigator.appVe rsion.toLowerCa se().indexOf('m ac')+1;

I stopped reading after that.

And it appears you have to convert every sound effect to MP3. On the
plus side, it is very responsive, but do you really need UI sounds in
a Web page? The OP just wants to sound a chime periodically.
Feb 26 '08 #4
On Feb 26, 10:53 am, David Mark <dmark.cins...@ gmail.comwrote:
Flash is present on 90% of home computers

That isn't a comforting statistic. And not all of those Flash
installations will support interaction with JavaScript.
Nor does the presence of Flash necessarily mean that it's turned on. A
number of my colleagues (myself included) utilize a plugin that blocks
Flash from loading automatically (replacing it with the Flash icon so
we know it's there) unless we specifically click it to activate.
Feb 26 '08 #5
SAM
David Mark a écrit :
On Feb 26, 9:21 am, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
wrote:
>Jake Barnes a écrit :
>>I asked my friends for a pure Javascript solution and they pointed me
to a script that still involves Flash:
http://www.boutell.com/newfaq/creating/scriptsound.html
It's the best.
Oooops!
I thought we told of this one :
<http://www.schillmania .com/projects/soundmanager2/>
issued from :
<http://www.schillmania .com/projects/soundmanager/>
(perhaps are they all the same ?)

(snip)
Quoting the first two lines from the "SoundManag er" script:
I've seen that too :-/
var isIE = navigator.appNa me.toLowerCase( ).indexOf('inte rnet explorer')
+1;
var isMac = navigator.appVe rsion.toLowerCa se().indexOf('m ac')+1;

I stopped reading after that.
I only have a look to the code after having pushed some of proposed
buttons in soundManager_1 that did noises (yes they did !)
And it appears you have to convert every sound effect to MP3.
And then ?
The sound has to be coded anyway (even it is a midi), no ?
On the
plus side, it is very responsive, but do you really need UI sounds in
a Web page? The OP just wants to sound a chime periodically.
I don't say the OP has to have its page to download an elephant if he
just needs a mouse.
I say only that soundmanager is the best (the easiest way) to serve sounds.
There are some others Flash mp3 players on the Net but most of them are
not so efficient (even if they probably be used too).
(I like this one : http://www.alsacreations.fr/dewplayer )

But I'am seriously very curious to see *with an example* how you do to
play a sound on demand (a "clic" when clicking a link for instance)
without using Flash and without downloading the sound each time.
Because personally I can't do it.

--
sm
Feb 26 '08 #6
SAM
Kevin Scholl a écrit :
On Feb 26, 10:53 am, David Mark <dmark.cins...@ gmail.comwrote:
>>Flash is present on 90% of home computers
That isn't a comforting statistic. And not all of those Flash
installation s will support interaction with JavaScript.

Nor does the presence of Flash necessarily mean that it's turned on. A
number of my colleagues (myself included) utilize a plugin that blocks
Flash from loading automatically (replacing it with the Flash icon so
we know it's there) unless we specifically click it to activate.
You're right.
I've recently downloaded a flash blocker.
And the JS also can be disabled too.

The Net will kill the Net ... :-(

Feb 26 '08 #7
David Mark wrote:
If you are writing an Ajax chat application, then you should be able
to tackle this. As with Flash, you need two branches, one that checks
the plugins and/or mimeTypes collections to determine support for your
chosen format and a fallback for IE and its various derivations (e.g.
old AOL browsers, which have no such collections (the feature
detection pattern should be obvious.)

The first branch adds an object element to the body to play a sound
and removes it after a suitable delay (which cannot be calculated
exactly as it takes time to download the file and load the plug-in.)
I don't see a need for removing the element, especially not because of
the uncertainty you mentioned.

Audio compression aside, I also don't see a need for Flash here. User
agents are capable to load the audio resource directly with the object
element. You will have to use another branch for MSHTML, though, that
uses a CLSID to trigger the Windows Media Player ActiveX control.
The second branch adds a bgsound element (or two) to the head and
changes the src property to play sounds.
There really is no need for that, unless you want to support IE 4.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Feb 26 '08 #8
Thomas 'PointedEars' Lahn <Po*********@we b.dewrites:
Audio compression aside, I also don't see a need for Flash here. User
agents are capable to load the audio resource directly with the object
element.
This is an unusually sweeping statement coming from you. My main browser
(firefox 2.something on debian) certainly doesn't play mp3s when they're
provided via an object tag.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Feb 26 '08 #9
On Feb 26, 6:17*pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
David Mark wrote:
If you are writing an Ajax chat application, then you should be able
to tackle this. *As with Flash, you need two branches, one that checks
the plugins and/or mimeTypes collections to determine support for your
chosen format and a fallback for IE and its various derivations (e.g.
old AOL browsers, which have no such collections (the feature
detection pattern should be obvious.)
The first branch adds an object element to the body to play a sound
and removes it after a suitable delay (which cannot be calculated
exactly as it takes time to download the file and load the plug-in.)

I don't see a need for removing the element, especially not because of
the uncertainty you mentioned.
You have to remove it, set the src property and re-add it to get a new
sound to play (at least in the browsers I have tested.) And then
there is the issue of fast history navigation. Leave the object in
place and the last sound played will play again when you return to the
page, which is very annoying.
>
Audio compression aside, I also don't see a need for Flash here. *User
agents are capable to load the audio resource directly with the object
element. *You will have to use another branch for MSHTML, though, that
uses a CLSID to trigger the Windows Media Player ActiveX control.
The second branch adds a bgsound element (or two) to the head and
changes the src property to play sounds.

There really is no need for that, unless you want to support IE 4.
It works far better in IE than the object approach. It is faster and
does not require ActiveX.
Feb 26 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
18955
by: Steph. | last post by:
Hi ! How can I play "standard system sounds" in C# ? ( "standard system sounds" = The kind of sound you hear when you use MessageBox.Show() ) Thanks ! steph.
19
2825
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have <a href="javascript:somefunction()"what ... ? ----------------------------------------------------------------------- Whatever the rest of your question, this is generally a very bad use of the javascript pseudo protocol. It was designed so that a...
0
7518
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7715
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.