Audio or music codes needed bad

Discussion in 'Web Design and Development' started by nightwolf, Nov 2, 2007.

  1. nightwolf macrumors member

    nightwolf

    Joined:
    Oct 4, 2005
    Location:
    Ontario, CANADA
    #1
    I really need music or audio codes that will work on windows and macs. These are the codes I have been using and they do not seem to work that well on both platforms.

    1. <BGSOUND balance=0 src="music/song.mp3" volume=0 loop=infinite autostart="true"></FONT></A><br>

    2. <embed src="music/Hero of the day 16.mp3" autostart="true" loop="true" width="2" height="0">
    </embed>

    I really need these codes. Please help!
    :confused:
     
  2. ChicoWeb macrumors 65816

    ChicoWeb

    Joined:
    Aug 16, 2004
    Location:
    California
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    Here is some JavaScript code I have from a web game I created. It was a while back, but I believe it worked in IE, Firefox, Safari, and Opera. I had only tried it with .wav files from what I remember. You'll just have to try out the mp3 to see if it works. Should also work for midi files.

    The "s" that get passed to the function is a string that holds the destination of the file (e.g. "music/soundfile.wav"). It dynamically inserts a sound file into the page then deletes itself after 2 seconds. This can be modified to meet your needs though.

    Code:
    function soundPlay(s)
    {
      if(window.opera) soundPlayOpera(s);
      sound = document.createElement("embed");
      sound.setAttribute("src", s);
      sound.setAttribute("id", "sfx");
      sound.setAttribute("hidden", true);
      sound.setAttribute("autostart", true);
      document.body.appendChild(sound);
      // pause long enough to play sfx, then delete itself
      setTimeout("removeSound()",2000);
    }
    function soundPlayOpera(sfx)
    {
      a = new Audio(sfx);
      a.play();
    }
    function removeSound()
    {
      d = document.getElementById("sfx");
      d.parentNode.removeChild(d);
    }
    Playing music on web pages doesn't have great support from HTML alone. The alternative is generally Flash. Check this article out for some details about your options.

    http://www.boutell.com/newfaq/creating/audio.html
     

Share This Page