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


D

David Mark

Currently I don't have a plugin installed. I used to have a plugin
installed (I think it was the VLC plugin), but it always set the volume
to 0% and wouldn't auto-start so it was pretty useless.

Sounds like it.
In any case, if you're relying on plugins anyway, my /guess/ would be
that flash has the largest install base of any plugin.

Perhaps, but not all versions are scriptable and is a lot of overhead
to play a sound effect.
What I'm getting at is that just using <object> tags is no guarantee
whatsoever and that, currently, using flash is probably a very sane

One needs no guarantees for an enhancement like sound effects.
fallback/default if you want reasonably reliable scriptable sound.

No, I think my method is far more reliable as it requires no plug-ins
at all for IE. As for the non-IE browsers, if there is no audio plug-
in, then the script detects that and doesn't attempt to play audio.
Applications can then disable any UI related to audio and all is
well. Doing that with Flash means additional overhead as you have to
detect the installed version number and compare it to versions that
are known to be scriptable (Flash sniffing.)
 
Ad

Advertisements

T

Thomas 'PointedEars' Lahn

David said:
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.

Good point.
It works far better in IE than the object approach. It is faster and
does not require ActiveX.

The ActiveX argument is void because you can't have plugins without ActiveX
support in MSHTML until version 7 (Internet Options, Security, $zone,
ActiveX Controls and plugins). I have to test if the `bgsound' element is
really faster. Why do you think so? Any benchmarks?


PointedEars
 
D

David Mark

I don't think that with this approach the script would need to detect
whether there was an appropriate plugin installed (is that even possible

Certainly it would, else the browser may prompt the user to install a
plug-in (which is the last thing you want to subject your users to.)
Also, the application may have audio-related UI and will therefore
need to know whether audio is possible or not.
in !MSHTML?).  If there is not, simply nothing happens.

No, you can't detect it in IE and don't need to with my approach (it
always works in IE.)
 
J

Joost Diepenmaat

Thomas 'PointedEars' Lahn said:
It then is likely that you have done something wrong. I'm not on Debian
GNU/Linux now, but it works in Firefox 2.0.0.11 on Windows and I remember
it working on Debian (must have been Firefox 1.5.x) as well.

Oh, it may work, but it does rely on plugins being installed that
specifically handle it (and handle it usefully, see my other post in
this thread).
It also works in IE 7, Opera 9.25, NN 7.2, and even NN 4.8 on Windows.

I had created a test case then, slightly adapted now:

http://PointedEars.de/scripts/test/dom/multimedia/liveconn

If that doesn't work for you (script-support enabled), you should check your
about:plugins. It could be that a) you have no plugin that can handle the
media type or b) an obsolete or misconfigured player plugin prevents the
sound from playing.

I currently have no plugin enabled to handle <object> sounds (or at
least, neither wav or mp3) directly, again - see the other post. I do
have flash installed. Anyway I get a "install missing plugins" message,
which doesn't find "any suitable plugins".

This is with debian's Iceweasel (firefox) 2.0.0.11-1 on debian/intel 32
bits, which is not /that/ unusual.
 
J

Joost Diepenmaat

David Mark said:
No, I think my method is far more reliable as it requires no plug-ins
at all for IE. As for the non-IE browsers, if there is no audio plug-
in, then the script detects that and doesn't attempt to play audio.

Sure, but the point is you probably won't be able to detect if the
plugin actually supports audio the way you want to. Only that it can
potentially play audio.
 
T

Thomas 'PointedEars' Lahn

Joost said:
Oh, it may work, but it does rely on plugins being installed that
specifically handle it (and handle it usefully, see my other post in
this thread).

So what? If *you* install plugins that don't adhere to standards that is
*your* fault. Especially on GNU/Linux where there are several
possibilities. Firefox handles the object element as specified, at least
since version 1.5. It worked for me, IIRC with the mplayer plugin.
This is with debian's Iceweasel (firefox) 2.0.0.11-1 on debian/intel 32
bits, which is not /that/ unusual.

Non sequitur. The plugins are not provided by the browser package.


PointedEars
 
Ad

Advertisements

S

SAM

David Mark a écrit :
If you have a library of WAV, SND, MIDI, etc. files, then having to
convert them all to MP3 is a considerable drawback.

personally I have more midi than mp3
but I have no wav nor snd ...

So to judge mp3 or anything the other one?
I say it is a monstrously bad script and should be avoided at all
costs.

Perhaps could you help him ? ;-)
Why use Flash at all?

Perhaps only because that works ?
(no loading except on user's action for instance, not to wait the end of
loading to begin to hear the sound/song/music, button for volume,
play-list, ... )
Perhaps because it is easy to insert in the page ?
Perhaps because it is very light ?
I would never do such thing, but yes, it is certainly possible. I
have included an audio module in my library that allows for this sort
of user abuse. Would you like to help with the Beta testing? I would
like to get a few more Mac testers on board. Send me an email if you
have some spare time.
OK


Audio files are cached just like other resources.

.... ? ? ? ...

That was not exactly the question.
Cache doesn't avoid the go and back to the server (to compare dates)

Ie : with AudioLive (who yet know this antic ?) coming with NC<5
you had to load an empty sound file to get a space to play sound
then to give a kind of shortcuts to the sounds you want to play
on demand. (avowing to download all the sounds/musics if user didn't
want to listen all of them)

For repetitive play of same sound (ie 'clic' when clicking)
a named hidden non played sound with a magic attribute
and enough simple JS functions to play/stop the sound
(almost same as used for QuickTime or Flash but enough different for
that can't be universally used)
 
J

Joost Diepenmaat

Thomas 'PointedEars' Lahn said:
So what? If *you* install plugins that don't adhere to standards that is
*your* fault.

What standards? Plugins can do whatever they like.
Non sequitur. The plugins are not provided by the browser package.

I'll do some research to see what I can dig up. From memory what I
installed was whatever the recommended plugin packages were.
 
D

David Mark

David Mark a écrit :



personally I have more midi than mp3
but I have no wav nor snd ...

So to judge mp3 or anything the other one?


Perhaps could you help him ? ;-)

I'm sure I could. But why would I bother?
Perhaps only because that works ?

We've been over that. It works sometimes, just like other plug-ins.
(no loading except on user's action for instance, not to wait the end of
loading to begin to hear the sound/song/music, button for volume,

I do have a method to control the volume in IE, but it is really not
necessary. A mute button is a must though.
play-list, ... )
?

Perhaps because it is easy to insert in the page ?

No, it is not. It is ridiculously complex to insert a Flash movie.
That is why virtually every Flash script on the Internet resorts to
browser sniffing, and/or non-standard embed elements. Even Adobe gets
it wrong (horribly so.)
Perhaps because it is very light ?

As compared to audio plug-ins?
... ? ? ? ...

That was not exactly the question.
Cache doesn't avoid the go and back to the server (to compare dates)

If you are worried about that, then send appropriate headers with your
audio files to prevent it (e.g. far future expiration dates.)
Ie : with AudioLive (who yet know this antic ?) coming with NC<5
you had to load an empty sound file to get a space to play sound
then to give a kind of shortcuts to the sounds you want to play
on demand. (avowing to download all the sounds/musics if user didn't
want to listen all of them)

As I mentioned, ymmv with NN4. Luckily, nobody uses it.

[snip]
 
S

SAM

David Mark a écrit :
We've been over that. It works sometimes, just like other plug-ins.

I think a bit more
I do have a method to control the volume in IE, but it is really not
necessary. A mute button is a must though.

I don't agree with that : I've no real button to fix the volume and I
appreciate to have something very close of the play button on the page.

list of musics where to chose (attached to the player)

I'm still speaking of a flash player
(not Flash but a player built for Flash).
No, it is not.

Yes it is, nothing to do except a bit of code to load the player and
some parameters to fix.
You have nothing to know about Flash.
It is ridiculously complex to insert a Flash movie.

not more, hop! a Flash movie player

The only things are sound must be mp3 and movies flv

Anyway sounds as movies and even images are most of the time useless in
a web page.
It is no too much important if the sound is not played (no Flash ? no
player and no sound, no list of musics, nothing useless to download)
As compared to audio plug-ins?

no the code to insert (and the Flash player)

a plug-in is a plug-in
is it important if it is fatter than its fellow ?
If you are worried about that, then send appropriate headers with your
audio files to prevent it (e.g. far future expiration dates.)

Not everybody can send headers
As I mentioned, ymmv with NN4. Luckily, nobody uses it.

I didn't learn all the posts
And it was only an example of the complexity to serve a sound in any
circumstance (and much more at this time, last century).
 
S

SAM

Thomas 'PointedEars' Lahn a écrit :
I had created a test case then, slightly adapted now:

http://PointedEars.de/scripts/test/dom/multimedia/liveconn

If that doesn't work for you (script-support enabled), you should check your
about:plugins. It could be that a) you have no plugin that can handle the
media type or b) an obsolete or misconfigured player plugin prevents the
sound from playing.

I have at least 2 QuickTime plug-ins in Safari (one for web the other ?)
If I open directly your sound that works
but with the page liveconn ... nothing to listen

what was displayed :
UA supports Netscape Plugin API

namedItem = [function]
item = [function]
tags = [function]

Safari does certainly not support LiveConnect

What Apple says :
<http://developer.apple.com/document...ing_HTML_Document/chapter_1000_section_5.html>

Works with Firefox (which has only one QT plug-in) :
UA supports Netscape Plugin API
length = 0
item = function item() { [native code] }
namedItem = function namedItem() { [native code] }
 
Ad

Advertisements

D

David Mark

David Mark a écrit :



I think a bit more
Perhaps.



I don't agree with that : I've no real button to fix the volume and I
appreciate to have something very close of the play button on the page.

Play (and stop) buttons are no problem.
list of musics where to chose (attached to the player)

I'm still speaking of a flash player
(not Flash but a player built for Flash).

Yes, I understand what a playlist is, but I don't see the relevance to
ambient sounds in a Web page.
Yes it is, nothing to do except a bit of code to load the player and
some parameters to fix.
You have nothing to know about Flash.

YMMV. That "bit of code" is quite a lot if you want to do it right.
not more, hop! a Flash movie player

?

[snip]
 
T

Thomas 'PointedEars' Lahn

Joost said:
What standards? Plugins can do whatever they like.

Plugins that work with non-standard elements like `embed' and do not work
with standardized ones like `object' are simply junk. If *you* employ them
despite there are viable alternatives, that is *your* fault, not that of the
Web author who used the element or the (X)HTML user agent.


PointedEars
 
J

Joost Diepenmaat

Thomas 'PointedEars' Lahn said:
Plugins that work with non-standard elements like `embed' and do not work
with standardized ones like `object' are simply junk. If *you* employ them
despite there are viable alternatives, that is *your* fault, not that of the
Web author who used the element or the (X)HTML user agent.

I can't help it if flash sucks. Most plugins suck. The issue is that
many browsers don't support native playing of audio and video, so you're
going to end up supporting some kind of plugin (and probably more than
one, if you want to be safe) anyway, and flash probably has a larger
install base than any other plugin capable of playing audio (and video).

Please point me to some kind of standard that says /anything at all/
about how and when sound is supposed to be played by an <object> tag. As
far as I know things like "autostart", streaming and volume control are
not defined anywhere.
 
T

Thomas 'PointedEars' Lahn

Joost said:
I can't help it if flash sucks. Most plugins suck.

I think you miss the point of what I was saying.
The issue is that many browsers don't support native playing of audio and
video, so you're going to end up supporting some kind of plugin (and
probably more than one, if you want to be safe) anyway, and flash
probably has a larger install base than any other plugin capable of
playing audio (and video).

I seriously doubt that, as AFAIK Windows Media Player 6 is preinstalled with
IE/Windows.
Please point me to some kind of standard that says /anything at all/
about how and when sound is supposed to be played by an <object> tag. As
far as I know things like "autostart", streaming and volume control are
not defined anywhere.

That is a valid point, though. If *that* is your problem, you are free to
remove the "hide controls" parameters and see if that works for your (it
should).

However, firstly any media player plugin should support the defined
parameters, and secondly if the "autostart" parameter are not supported, I
doubt the user would mind that there is silence. The same goes for using
ActiveX controls (which the Flash plugin also is on Windows). So I really
don't see the problem.


PointedEars
 
J

Joost Diepenmaat

Thomas 'PointedEars' Lahn said:
I seriously doubt that, as AFAIK Windows Media Player 6 is preinstalled with
IE/Windows.

You may be right. Though I'm not sure about the situation on Macs, and
on most Linux distros you can pretty much count on having no multimedia
plugins whatsoever, especially ones supporting MP3 - you'll have to find
and install them yourself. Oh, and then there are (probably ignorable)
non-multimedia windows distributions:

http://www.microsoft.com/About/Legal/eudecision/faq.mspx

As for flash, it's pretty much a chicken-and-egg problem: flash is
popular enough on the popular platforms that many sites will use it, and
because of that, many people will have it installed, even if it's just
to be able to watch youtube. Having a pretty good, more or less "click
here to install and watch this video" installer works in their advantage
too.
That is a valid point, though. If *that* is your problem, you are free to
remove the "hide controls" parameters and see if that works for your (it
should).

At this point, I've pretty much given up on any audio solution that
doesn't use flash (as a fallback, at least). I just couldn't get it to
work on my debian box using any of the standard (i.e. apt-get
installable from the default configuration) plugins. For "click here to
listen" scenarios, there are good non-flash solutions, but see below.
However, firstly any media player plugin should support the defined
parameters, and secondly if the "autostart" parameter are not supported, I
doubt the user would mind that there is silence. The same goes for using
ActiveX controls (which the Flash plugin also is on Windows). So I really
don't see the problem.

It's only a problem if you want scriptable sound. I.e. you want to
trigger sounds based on specific events, without too much (less than 100
ms or so) delay. The problem is mostly academic, since in most
situations where you'd use that, you'd probably use flash anyway, but I
ran into it trying to hack together a simple shooter game in javascript.
 
Ad

Advertisements

S

SAM

Thomas 'PointedEars' Lahn a écrit :
Plugins that work with non-standard elements like `embed' and do not work
with standardized ones like `object' are simply junk. If *you* employ them
despite there are viable alternatives, that is *your* fault, not that of the
Web author who used the element or the (X)HTML user agent.

I would apreciate you teel me which plug-in (standardized with 'object')
I can find to listen to sounds (in any format) with my Safari 2 on my Mac.

The JS functions of my QuickTime Player seems to work only with 'embed'.
 
T

The Magpie

The question from the OP now seems to have been slightly amended
following the comments from everyone else to read more like it does
below than how it started. Does this fairly summarise the way the
question has grown?

"How can I play a sound with Javascript, even if Javascrip is not
available to the user's browser or has been disabled and without
needing to load any plugin software and by making sure that any plugin
software that is already on the user client is working, even if it is
blocked or disabled, and that the sound will adapt to play on whatever
is available even if the sound was recorded and saved in a totally
different format to the one that the client can use and, incidentally,
even if the user has the sound turned off or perhaps no sound card in
the PC at all or maybe even no speakers on the computer?"

If you get the feeling that I think the question has grown beyond all
reasonable bounds, you'd be dead on the button! Its time for this to
go back to the OP and for the question to be put in terms that the OP
actually wants to use.
 
L

Laurent vilday

Thomas 'PointedEars' Lahn a écrit :
Plugins that work with non-standard elements like `embed' and do not work
with standardized ones like `object' are simply junk. If *you* employ them
despite there are viable alternatives, that is *your* fault, not that of the
Web author who used the element or the (X)HTML user agent.

I don't get it.

You keep saying everything must be tested, everything must be supported
- even ultra odd rare stuff - and is the responsability of the web
author to provide something working in every exceptionnal situation.

However you just say it is not the author's responsability anymore when
it concerns plugins ?

At the moment I am using a plugin I, as a web author which I am not, am
allowed to do anything I want ?

If it is not working as expected with every available plugins it is your
fault, as a web visitor, and not mine anymore ?

I really don't get it. Why would the responsability be switched ?
 
Ad

Advertisements

V

VK

I did a search on the newsgroup comp.lang.javascript. 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.

That is about right. The last time I had tried to make an universal
_reliable_ Javascript player is dated circa 2003-2004, after that I
(as the majority of Web developers) dropped this dirty business.

The problem lyes in the fact that somewhere by the end of the last
century the major players got the idea that the future of the Web is
in the media players/buyers/downloaders - so respectively whoever has
his proprietary player ruling - he is also "ruling the future".
Respectively the main task was to enforce any media not just to be
played, but to be player in _one particular_ player plus to ensure
that the consumer will be always aware of - grace to what software he
is happily watching/listening the given media. This way the main job
was to:
1) any media file attached to a particular playing software.
2) any media is played in visually recognizable particular software.

That is obviously against of the main aim of any Web developer with
1) play the media on whatever is available in the given environment.
2) play the media over an uniformed software-independent interface.

This situation inevitable lead to a real "programming war" between Web
developers and browser producers with RealPlayer, QuickTime and
MediaPlayer doing all their best to enforce "either me - or not game":
and numerous "interface wrappers" some of which - like Yahoo! one -
are still remaining samples of sophisticated workarounds for
intentional incompatibility. Still even the most sophisticated ones
remained nothing but hucks over software producer intentions with all
expected reliability impacts. Whoever was surfing the Web that time
may recall at least a couple of times when prompted to download
10-15Mb plugin/ActiveX to listen 10Kb MIDI bgsound file.
This way the community got sick tired of this crap and then Adobe/
Macromedia/YouTube came with an obvious idea to use what is already
installed on 99% of computers, Macromedia Flash. As the result FLV
players took the market by the storm. I personally do not recall a
single instance over the last 6-8 months when my browser launched any
of former rivals (RealPlayer, QuickTime, MediaPlayer) on visited
pages. As long as one has Flash installed, the things are fine. Just
another splendid sample of how careful anyone has to be with the
competition: if no compromise made with your even worst rival, the
chances are high to be eventually smashed out by a 3rd force.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top