Sound with JavaScript but not Flash

Written by on January 31st, 2007 in Ajax News.

Reinier Zwitserloot wanted to see if he could add sound support without embedding a Flash bridge, and shared his research in his article on Sound in Web Browsers without Flash.

Check out his test page for a Sound Check

An example API

JAVASCRIPT:

  1.  
  2.                         function sound2Play() {
  3.                                 if ( !sound2Embed ) {
  4.                                         sound2Embed = document.createElement(”embed”);
  5.                                         sound2Embed.setAttribute(”src”, “machinegun.wav”);
  6.                                         sound2Embed.setAttribute(”hidden”, true);
  7.                                         sound2Embed.setAttribute(”autostart”, true);
  8.                                 } else sound2Stop();
  9.                                 sound2Embed.removed = false;
  10.                                 document.body.appendChild(sound2Embed);
  11.                         }
  12.                        
  13.                         function sound2Stop() {
  14.                                 if ( sound2Embed && !sound2Embed.removed ) {
  15.                                         document.body.removeChild(sound2Embed);
  16.                                         sound2Embed.removed = true;
  17.                                 }
  18.                         }
  19.  

Source: Ajaxian
Original Article: http://ajaxian.com/archives/sound-with-javascript-but-not-flash

Leave a Reply

You must be logged in to post a comment.



Site Navigation