472,779 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

How to play a sound in Firefox?

Dear All,

I found the code added below at:
http://simplythebest.net/sounds/sound_guide.html

Unfortunately, the code doesn't seem to work in Firefox. These are the
error messages I can see in my Javascript Console:
Error: self.document.guitar.IsReady is not a function
Error: self.document.guitar.stop is not a function

Are there other functions we have to invoke for FireFox? Any help will
be appreciated!

Kind regards,
Dobedani

<BGSOUND id=BGSOUND_ID src="">
<bgsound id="bgsound_id" loop=1 src="jsilence.mid">
<embed name="guitar" src="malaguena.mid" loop=false autostart=false
hidden=true mastersound>

<script language="JavaScript">
<!--
ver=parseInt(navigator.appVersion)
ie4=(ver>3 && navigator.appName!="Netscape")?1:0
ns4=(ver>3 && navigator.appName=="Netscape")?1:0
ns3=(ver==3 && navigator.appName=="Netscape")?1:0

function playSound() {
if (ie4) document.all['BGSOUND_ID'].src='malaguena.mid';
if ((ns4||ns3)
&& navigator.javaEnabled()
&& navigator.mimeTypes['audio/x-midi']
&& self.document.guitar.IsReady()
)
{
self.document.guitar.play()
}
}

function stopSound() {
if (ie4) document.all['BGSOUND_ID'].src='jsilence.mid';
if ((ns4||ns3)
&& navigator.javaEnabled()
&& navigator.mimeTypes['audio/x-midi']
)
{
self.document.guitar.stop()
}
}
//-->
</script>

<form name=myform>
<input type=button value="Play Sound" onClick="playSound()">
<input type=button value="Stop Sound" onClick="stopSound()">
</form>

May 26 '06 #1
16 14674
Dobedani said the following on 5/26/2006 5:57 AM:
Dear All,

I found the code added below at:
http://simplythebest.net/sounds/sound_guide.html

Unfortunately, the code doesn't seem to work in Firefox. These are the
error messages I can see in my Javascript Console:
Error: self.document.guitar.IsReady is not a function
Error: self.document.guitar.stop is not a function

Are there other functions we have to invoke for FireFox? Any help will
be appreciated!


Best help with regards to that code:

Find another script. When hunting, if you see one that says anything
about navigator.appName, skip it and keep hunting.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 26 '06 #2

Dobedani wrote:
Dear All,

I found the code added below at:
http://simplythebest.net/sounds/sound_guide.html

Unfortunately, the code doesn't seem to work in Firefox. These are the
error messages I can see in my Javascript Console:
Error: self.document.guitar.IsReady is not a function
Error: self.document.guitar.stop is not a function

Are there other functions we have to invoke for FireFox? Any help will
be appreciated!

Kind regards,
Dobedani

<BGSOUND id=BGSOUND_ID src="">
<bgsound id="bgsound_id" loop=1 src="jsilence.mid">
<embed name="guitar" src="malaguena.mid" loop=false autostart=false
hidden=true mastersound>

<script language="JavaScript">
<!--
ver=parseInt(navigator.appVersion)
ie4=(ver>3 && navigator.appName!="Netscape")?1:0
ns4=(ver>3 && navigator.appName=="Netscape")?1:0
ns3=(ver==3 && navigator.appName=="Netscape")?1:0

function playSound() {
if (ie4) document.all['BGSOUND_ID'].src='malaguena.mid';
if ((ns4||ns3)
&& navigator.javaEnabled()
&& navigator.mimeTypes['audio/x-midi']
&& self.document.guitar.IsReady()
)
{
self.document.guitar.play()
}
}

function stopSound() {
if (ie4) document.all['BGSOUND_ID'].src='jsilence.mid';
if ((ns4||ns3)
&& navigator.javaEnabled()
&& navigator.mimeTypes['audio/x-midi']
)
{
self.document.guitar.stop()
}
}
//-->
</script>

<form name=myform>
<input type=button value="Play Sound" onClick="playSound()">
<input type=button value="Stop Sound" onClick="stopSound()">
</form>


The above code should have been retired several years ago. It only
tests for old style Netscape browsers and not modern Mozilla family
browsers such as recent Netscape, Mozilla, and Firefox. Hence Firefox
is locked out. In the early days of the browser wars, Netscape would
support embed for sound and IE would support bgsound. However IE soon
supported embed for bgsound, but Netscape and modern Mozilla family
browsers never supported bgsound. You can usually just use an embed
code these days without testing for browser type, as IE browsers
earlier than 4 now are all but gone, which is a good thing because many
modern browsers are set to spoof other browsers to avoid lockouts
resulting from faulty browser type detection. However embed never has
been an official part of html, and there are more modern methods for
including sound on a page.

Javascript has been around a long time now, as time goes for computing.
There are many sites around with examples of script that have not been
updated for perhaps 10 years. Some of these scripts do not work
properly on modern browsers. Since there is no official quality control
for web pages, anyone can put up just about anything and keep it there
without updates, so long as they pay their host for server space. This
is especially true for collections of script submitted by many people,
often in the distant past.

May 26 '06 #3

Dobedani wrote:
Dear All,

I found the code added below at:
http://simplythebest.net/sounds/sound_guide.html

Unfortunately, the code doesn't seem to work in Firefox.


Try this demo and use the code if you think it's OK. It's not widely
tested so I'm not guaranteeing anything:

http://www.hotspot.freeserve.co.uk/ttdemo/

May 28 '06 #4

Stephen Chalmers wrote:
Try this demo and use the code if you think it's OK. It's not widely
tested so I'm not guaranteeing anything:

http://www.hotspot.freeserve.co.uk/ttdemo/


Your page works properly on the most recent versions of IE6, Firefox,
Opera, Mozilla, and Netscape. There is no sound and the page layout is
not correct on the old Netscape 4.8(no problem, in my opinion, for this
old relic).

You mention that this is just a demo, but validation at W3C indicates
that it probably would be fairly easy to get the page to validate
completely. Since there was no Doctype or encoding given, I put in the
Doctype for html 4.01 transitional and the encoding of iso-8859-1
(Western Europe) to get the W3C validator to work. The script tag needs
a type added. There are a few errors that look minor and that should be
easy for you to correct.

May 28 '06 #5

cwdjrxyz wrote:
The script tag needs
a type added.


This should read that the style tag needs a type added.

May 28 '06 #6
I would use flash with sound embedded in it.

May 28 '06 #7

cwdjrxyz wrote:
Stephen Chalmers wrote:
Try this demo and use the code if you think it's OK. It's not widely
tested so I'm not guaranteeing anything:

http://www.hotspot.freeserve.co.uk/ttdemo/
Your page works properly on the most recent versions of IE6, Firefox,
Opera, Mozilla, and Netscape. There is no sound and the page layout is
not correct on the old Netscape 4.8(no problem, in my opinion, for this
old relic).


It's a DOM script so NN4 is well out of it and users see a message to
that effect. As for layout, that browser loses the plot as soon as it
sees a CSS margin specifier, so no surprise.
You mention that this is just a demo, but validation at W3C indicates
that it probably would be fairly easy to get the page to validate
completely. Since there was no Doctype or encoding given, I put in the
Doctype for html 4.01 transitional and the encoding of iso-8859-1
(Western Europe) to get the W3C validator to work. The script tag needs
a type added. There are a few errors that look minor and that should be
easy for you to correct.


I've corrected that now, but it wouldn't affect operation. I think the
best one can hope is that it doesn't cause errors anywhere.

May 28 '06 #8

Stephen Chalmers wrote:
You mention that this is just a demo, but validation at W3C indicates
that it probably would be fairly easy to get the page to validate
completely. Since there was no Doctype or encoding given, I put in the
Doctype for html 4.01 transitional and the encoding of iso-8859-1
(Western Europe) to get the W3C validator to work. The script tag needs
a type added. There are a few errors that look minor and that should be
easy for you to correct.


I've corrected that now, but it wouldn't affect operation. I think the
best one can hope is that it doesn't cause errors anywhere.


Yes, the page now validates at W3C.

My computer is somewhat like my closets, and is stuffed with many old
things that really should be cleaned out. I happen to have an old MSNTV
Viewer, a program to simulate how a page viewed on the old MSNTV set
top box with the 2.8 upgrade. This is absolutely of no current
practical importance, since users of the old boxes were forced to
upgrade versions long ago. This unit does not use a cursor. Rather the
first clickable area at the top left is outlined in a yellow box and
one moves from one clickable area to another by using arrow buttons
that point up,down, left, right on the remote control for the box. Of
course there can be no cursor effect activated by moving a cursor.
However your page viewed correctly on this very old relic, and you were
able to click to go to a link such as Google. Interesting, but
completely useless at this late date. So far as I know, the
MSNTV(former WebTV) boxes are only used in the US, although there was
some usage in Canada at one time. Their old boxes have been replaced by
a new one that uses a watered down IE6 and is completely different from
the old boxes. A small number, likely well under one million, of the
old boxes still are in use. The MSNTV service also was built into a few
small dish satellite TV receivers at one time. Most users of the MSNTV
boxes these days appear to be older people, most of whom have never
used a computer before. Although the old boxes are now a very small
target, someone in the US who is selling health products, prune juice,
etc may need to consider how their pages view on this old relic.
Javascript and CSS support for these old boxes is best described as
strange.

May 28 '06 #9
Stephen Chalmers wrote:
cwdjrxyz wrote:
Stephen Chalmers wrote:
> Try this demo and use the code if you think it's OK. It's not widely
> tested so I'm not guaranteeing anything:
>
> http://www.hotspot.freeserve.co.uk/ttdemo/


Your page works properly on the most recent versions of IE6, Firefox,
Opera, Mozilla, and Netscape. There is no sound and the page layout is
not correct on the old Netscape 4.8(no problem, in my opinion, for this
old relic).


It's a DOM script so NN4 is well out of it [...]


Not true.

1. DOM is a concept that exists since NN3/IE3. You are confusing this
with "W3C DOM".

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/glossary.html>

2. NN 4.8 (released 2002 CE), which is the latest of the Netscape browsers
using the old Mozilla codebase (and which I therefore do not consider a
relic), supports the proprietary `embed' element and has means to access
the corresponding DOM object, through the `document.embeds' collection,
provided a handling plugin is installed.
PointedEars
--
Those who desire to give up freedom in order to gain security,
will not have, nor do they deserve, either one.
-- Benjamin Franklin
May 29 '06 #10
Thomas 'PointedEars' Lahn said the following on 5/29/2006 12:07 PM:
Stephen Chalmers wrote:
cwdjrxyz wrote:
Stephen Chalmers wrote:
Try this demo and use the code if you think it's OK. It's not widely
tested so I'm not guaranteeing anything:

http://www.hotspot.freeserve.co.uk/ttdemo/
Your page works properly on the most recent versions of IE6, Firefox,
Opera, Mozilla, and Netscape. There is no sound and the page layout is
not correct on the old Netscape 4.8(no problem, in my opinion, for this
old relic). It's a DOM script so NN4 is well out of it [...]


Not true.

1. DOM is a concept that exists since NN3/IE3. You are confusing this
with "W3C DOM".

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/glossary.html>


In 2006 those two terms are synonymous, even if the W3C says they aren't.
2. NN 4.8 (released 2002 CE), which is the latest of the Netscape browsers
using the old Mozilla codebase (and which I therefore do not consider a
relic),


A 4 year old browser based on almost 10 year old code isn't a relic?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 29 '06 #11
Thomas 'PointedEars' Lahn wrote:
2. NN 4.8 (released 2002 CE), which is the latest of the Netscape browsers
using the old Mozilla codebase (and which I therefore do not consider a
relic),
It never can deserve to called a relic, in the sense that such a
description cannot be applied to anything unfinished. The continued
distribution of any item does not prevent it from being obsolete.
supports the proprietary `embed' element and has means to access
I think you'll find it's not the only one that does, which is just as
well.
the corresponding DOM object, through the `document.embeds' collection,
provided a handling plugin is installed.


Use of that plugin is well documented, but I saw little point in
cluttering the code with a branch whose probability of execution rivals
that of the client rendering the containing document intelligibly,
without rupturing itself or insisting that one or more layers don't
exist.

May 29 '06 #12

the DtTvB wrote:
I would use flash with sound embedded in it.


What would be the comparative bandwidth requirement of such a solution?

May 29 '06 #13
Stephen Chalmers wrote:
Thomas 'PointedEars' Lahn wrote:
2. NN 4.8 (released 2002 CE), which is the latest of the Netscape
browsers using the old Mozilla codebase (and which I therefore
do not consider a relic),
It never can deserve to called a relic, in the sense that such a
description cannot be applied to anything unfinished.


Pardon? It was a /release/. One that corrected several errors of previous
releases. Not all errors, yes. But that does not mean it is unfinished.
The continued distribution of any item does not prevent it from being
obsolete.
But its continued use does.
supports the proprietary `embed' element and has means to access


I think you'll find it's not the only one that does,


But it is the only one that only supports this approach for multimedia
objects. (Although I have the idée fixe of having seen it working with
a single `object' element once. Maybe that was on Windows then.)
which is just as well.


Sorry, I am not familiar with this idiom in that context. Please explain.
the corresponding DOM object, through the `document.embeds'
collection, provided a handling plugin is installed.


Use of that plugin is well documented, but I saw little point in
cluttering the code with a branch whose probability of execution rivals
that of the client rendering the containing document intelligibly,
without rupturing itself or insisting that one or more layers don't
exist.


Not understood. Anyway, there are Valid workarounds to have NS4 ignore
stylesheet rules that have harmful effects on it (because of its bugs).
PointedEars
--
When the power of love overcomes the love
of power, the world will know peace.
-- Jimi Hendrix
May 29 '06 #14
Stephen Chalmers wrote:
the DtTvB wrote:
I would use flash with sound embedded in it.


What would be the comparative bandwidth requirement of such a solution?


Probably less than serving it as is. Flash compresses audio content well.
PointedEars
--
There are two possibilities: Either we are alone in the
universe or we are not. Both are equally terrifying.
-- Arthur C. Clarke
May 29 '06 #15

Stephen Chalmers wrote:
the DtTvB wrote:
I would use flash with sound embedded in it.


What would be the comparative bandwidth requirement of such a solution?


You appear to be using all wav sound files, which are uncompressed. I
see no problem with this for such short sound files, but then I am on
SBC/Yahoo DSL Professional which gives me an over 2.5 mbps download
rate. Just about any other sound format will compress the wav sound
files considerably, and you can adjust compression to as much as you
can stand the quality of the sound. I like .wma for the web. I like a
..rm Real file just as well, but fewer viewers are likely to have a
player that can handle this. The WMP, Real, QT, and Winamp players, to
name a few, all support .wma files, and many also support .wmv video
files if you want to include video as well as audio. Then there are
many other audio options that will compress including ogg vorbis, mp3,
mp4 etc. There is really a glut of available audio and video formats
that compress. I like flash only for banners, cartoons, and such, but
not for serious audio or video. Part of the reason is that much of the
flash code is far from standards complient, and it is more difficult to
get around this and use proper modern code than for some of the other
media. Of course the other media formats also are often used in a non
standards compliant way. I usually capture sound completely
uncompressed as PCM (high resolution wav). I use up to 24 bit, 96 khz
when the source merits this. Then I use any of many available programs
to edit the sound if needed and to convert it to a format for use on
the web. Microsoft has a free encoder for wma and wmv formats, and Real
has a free encoder for their formats. Despite all I have said, I likely
would stick to the wav files for your case unless you expect many
viewers on exceptionally slow dialup connections.

May 29 '06 #16
I am doing dictionary type pronunciations. I use 8khz 8 bit mono to
record . I get files around 400k for most words. I like Steve's
approach. With some simple DHTML and a dynamic embed, you can create
some pretty spiffy navigation, without having to learn or buy anything
else

May 31 '06 #17

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

Similar topics

22
by: The Road To Utopia | last post by:
Here's one for the trolls...a common jibe from them is setting up audio/video hardware under linux. Ok, true story: at work today, someone asked me if I could tell him why his XP Home would play...
2
by: Keyser | last post by:
On most my pages, I use Javascript to play a sound. It works fine in Netscape 4.7, Netscape 7.2, Firefox 1.0, IE5 and IE6 using Windows98 as the operating system. However, using WindowsXP as the...
1
by: Ron Provost | last post by:
Hello, I'm developing a piece of software to assist illiteraate adults to learn to read. I'm trying to figure out how, if possible, to make audio playback asynchrnous but still controllable. ...
2
by: NB | last post by:
I've done a thorough search, but could not find any posts If I store a sound file within the mdb, How do I play it (in a form event, for example) I can save it to a temp folder and call the...
22
by: MLH | last post by:
I have some audio help files that play fine from within Access 97 and Access 2.0. Both are running on a Windows XP box. But I do not know what program plays the files. If I click Start, Run and...
1
by: Lam | last post by:
how can I play sound file in a .aspx page written in C#? I try to use the code like the following. But whenI call the play function play("sound.wav", this.SND_ASYNC) my computer give out "be"...
3
by: Jared | last post by:
I'm using the first code sample below to play WAV files stored as embedded resources. For some reason I *occasionally* get scratching and crackling. I'm using a couple WAVs that ship with...
5
by: | last post by:
Hello, I am wrtting a program that does some sound effects... the files are stored in a subfolder in the application folder... and I check the existence of the files before calling the method to...
26
by: Jake Barnes | last post by:
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...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.