Re: How can I play midi and/or audio files?



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
.



Relevant Pages

  • Re: vs2008 problems
    ... uppercase tags flag as errors although the table still runs. ... As for the VS 2008 html designer, it has been redesigned from the original ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Issue Getting Suckerfish Dropdown Menu Working in IE6
    ... The `script' element is supported since HTML 3.2, ... This requires support for the Web standards W3C DOM Level 2 Core and HTML. ... This requires support for a proprietary property on a host object. ... This also requires support for a proprietary property on a host object. ...
    (comp.lang.javascript)
  • Re: VS mangles HTML
    ... I have went through all the options and I don't see a "reset VS 2005 ... The is getting inserted into the html!! ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Updating the html inside a panel
    ... the most outside of the html source. ... control with the html source and add the control to the Panel: ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Page switcher
    ... unless you select the "HTML Code" template for your new Website (which will ... Internet Explorer does not support XHTML, and you do not need XHTML here. ... (Search the archives.) ...
    (comp.lang.javascript)

Loading