How to play a sound in Firefox?
|
|
Thread rating:  |
Dobedani - 26 May 2006 10:57 GMT 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>
Randy Webb - 26 May 2006 15:51 GMT Dobedani said the following on 5/26/2006 5:57 AM:
> Dear All, > [quoted text clipped - 8 lines] > 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.
 Signature Randy comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
cwdjrxyz - 26 May 2006 17:21 GMT > Dear All, > [quoted text clipped - 53 lines] > <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.
Stephen Chalmers - 28 May 2006 04:07 GMT > 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/
cwdjrxyz - 28 May 2006 08:35 GMT > 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.
cwdjrxyz - 28 May 2006 08:40 GMT > The script tag needs > a type added. This should read that the style tag needs a type added.
Stephen Chalmers - 28 May 2006 21:27 GMT > > Try this demo and use the code if you think it's OK. It's not widely > > tested so I'm not guaranteeing anything: [quoted text clipped - 5 lines] > 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 [quoted text clipped - 3 lines] > 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.
cwdjrxyz - 29 May 2006 00:37 GMT > > 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 [quoted text clipped - 6 lines] > 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.
Thomas 'PointedEars' Lahn - 29 May 2006 17:07 GMT >> > Try this demo and use the code if you think it's OK. It's not widely >> > tested so I'm not guaranteeing anything: [quoted text clipped - 7 lines] > > 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
 Signature Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one. -- Benjamin Franklin
Randy Webb - 29 May 2006 17:11 GMT Thomas 'PointedEars' Lahn said the following on 5/29/2006 12:07 PM:
>>>> Try this demo and use the code if you think it's OK. It's not widely >>>> tested so I'm not guaranteeing anything: [quoted text clipped - 12 lines] > > <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?
 Signature Randy comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Stephen Chalmers - 29 May 2006 18:41 GMT > 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.
Thomas 'PointedEars' Lahn - 29 May 2006 19:00 GMT >> 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. [quoted text clipped - 4 lines] > 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
 Signature When the power of love overcomes the love of power, the world will know peace. -- Jimi Hendrix
the DtTvB - 28 May 2006 13:03 GMT I would use flash with sound embedded in it.
Stephen Chalmers - 29 May 2006 18:46 GMT > I would use flash with sound embedded in it. What would be the comparative bandwidth requirement of such a solution?
Thomas 'PointedEars' Lahn - 29 May 2006 19:01 GMT >> 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
 Signature There are two possibilities: Either we are alone in the universe or we are not. Both are equally terrifying. -- Arthur C. Clarke
cwdjrxyz - 29 May 2006 21:25 GMT > > 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.
gmgj - 31 May 2006 15:51 GMT 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
|
|
|