473,703 Members | 3,018 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 3896
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
18962
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
2868
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 function could return a new page. For example: `` javascript:"<p>Hello</p>" ''. Using it simply to...
0
8669
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9122
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9017
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4433
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3125
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2453
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.