Results 1 to 3 of 3

Thread: Play *.wav or beep in javascript

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    17

    Play *.wav or beep in javascript

    I have a javascript file that runs from an ASP.Net page. I need to either emit a beep or play a wav file of a beep. Can you tell me how to do that? Here is my code where I want to place it.

    if (document.getElementById('hidEndAlarm').value == "1")
    {
    if (document.getElementById('lblTargetTime').innerText == document.getElementById('lblElapsedTime').innerText)
    {
    // Flash screen and beep
    var Flash=0;

    // PLAY BEEP HERE
    }
    }

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    You could make a div which inserts a sound object into the HTML on a certain action... I'm not sure if JavaScript itself has the ability to play sounds
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    this will do it. Let me know if you needit tweaking


    Code:
    <script type="javascript/text">
    var audioOn = false;
    
    function audioDo(doWhat,toWhat){ 
    if(audioOn){
    var A = eval('document.'+toWhat);
    if (A != null){
    if (doWhat=='stop') A.stop();
    else{
    if (navigator.appName == 'Netscape') A.play();
    else{
    if (document.M == null){
    document.M = false; var m;
    for(m in A) if (m == "ActiveMovie"){
    document.M = true; break;
    }
    }
    if (document.M) A.SelectionStart = 0;
    if (document.M) A.play();
    }
    }
    }
    }
    }
    </script>
    then it HTML.

    Code:
    <a href="#" onclick="audioDo('play','song');">song</a>
    
    <embed NAME="song" SRC="music/song.mp3" ASTERSOUND LOOP="false" AUTOSTART="false" AUTOREWIND="true" HIDDEN="true" WIDTH="0" HEIGHT="0">

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width