Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] sounds
- From: sclay at ufl.edu (Steve Clay)
- Subject: [Javascript] sounds
- Date: Wed Jun 21 12:48:13 2006
Tuesday, June 20, 2006, 11:05:59 PM, tedd wrote: > So, I would like to know if there is an "approved" way of doing this, is there? I think the most reliable way to trigger a sound in Javascript would be to dynamically create a Flash object (google SWFObject) using a SWF that just plays the sound specified in the FlashVars. Of course this limits you to the sound formats Flash supports. -- BTW, Opera 9 is supposed to support the new WebApps Audio object: http://whatwg.org/specs/web-apps/current-work/#audio new Audio("test.wav").play(); // create object, play clip once. You could fake this interface using the above Flash approach, then you'd have easy cross-browser sound. Something like this (untested): if (typeof Audio == 'undefined') { function Audio(uri, swfContainer) { this.uri = uri; window.Audio_guid = window.Audio_guid ? (window.Audio_guid + 1) : 0; this._guid = window.Audio_guid; if (!swfContainer) { swfContainer = document.getElementsByTagName('body')[0].appendChild( document.createElement('span') ); } swfContainer.id = 'Audio_cont' + this._guid; this.swfContainer = swfContainer; } Audio.prototype.play = function() { var so = new SWFObject("Audio.swf", "Audio_object" + this._guid, "1", "1"); so.addParam("wmode", "transparent"); so.addParam("flashvars", "file=" + escape(this.uri)); so.write("Audio_cont" + this._guid); }; } Steve -- http://mrclay.org/
- References:
- [Javascript] sounds
- From: John Warner
- [Javascript] sounds
- From: tedd
- [Javascript] sounds
- Prev by Date: Quoting others (Re: [Javascript] DOM vs AJAX et al).
- Next by Date: [Javascript] Re: sounds
- Previous by thread: [Javascript] sounds
- Next by thread: [Javascript] Re: sounds
- Index(es):