Re: How can I play midi and/or audio files?
- From: Thomas 'PointedEars' Lahn <PointedEars@xxxxxx>
- Date: Mon, 27 Mar 2006 16:52:38 +0200
Stephen Chalmers wrote:
Stephen Kellett wrote:
How can I play midi and/or audio files using JavaScript?
I have never seen a satisfactory answer to playing sound files
interactively, so here's my solution:
<html>
Not Valid. <URL:http://validator.w3.org/>
[...]
<a href='#'>Blip</a> - <a href='#'>Ding</a> - <a href='#'>Dumb</a> - <a
href='#'>Dumb</a> - <a href='#'>Chime</a>
Displays even if client-side script support and DOM support is not
available.
[...]
SCmediaPlay.prototype.playSound=function()
{
this.removeObj();
this.objRef=document.createElement('embed');
There is no `embed' element in HTML, so this is not supposed to work in a
standards compliant UA. And any UA that supports DOM Level 2 Core should
also support the standards compliant `object' element, so you should create
that.
You do not do any feature test, which is error-prone.
<URL:http://pointedears.de/scripts/test/whatami#inference>
this.objRef.setAttribute("width","0");
this.objRef.setAttribute("height","0");
this.objRef.setAttribute("hidden","true");
this.objRef.setAttribute("src", this.soundFile);
Neither of this is supposed to work. Especially, setAttribute() is known
to have buggy implementations. Both the proprietary `embed' element and
the standards compliant `object' element have `param' child elements that
should be used. (Otherwise there is no sound with certain non-common
plugins, such as the mplayer-plugin on GNU/Linux.)
[...]
document.write("<embed src='"+this.soundFile+"' hidden='true'
autostart='false' width='0' height='0'>");
See above.
PointedEars
.
- Follow-Ups:
- Re: How can I play midi and/or audio files?
- From: Stephen Chalmers
- Re: How can I play midi and/or audio files?
- References:
- How can I play midi and/or audio files?
- From: Stephen Kellett
- Re: How can I play midi and/or audio files?
- From: Stephen Chalmers
- How can I play midi and/or audio files?
- Prev by Date: ATLAS and External Javascript
- Next by Date: Re: How can I play midi and/or audio files?
- Previous by thread: Re: How can I play midi and/or audio files?
- Next by thread: Re: How can I play midi and/or audio files?
- Index(es):
Relevant Pages
|
Loading