Search code examples
asp.netmovaudio-player

How to play/pause a wav file in asp page


I need to play and pause a .wav file on an asp.net page, but I can't use flash, and it needs to be the lightest solution there could be. I found how to play the sound, but I can't find a way to stop it.

this is my code: (with the element "embed" it's not working in IE, but with "bgsound" it's not working in Chrome)

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <script type="text/javascript">

        var soundObject = null;


        function PlaySound() {

        if (soundObject != null) {

                document.body.removeChild(soundObject);
                soundObject = null;

            }

            soundObject = document.createElement("bgsound");

            soundObject.setAttribute("src", "C:/sound1.wav");

            soundObject.setAttribute("hidden", true);

            soundObject.setAttribute("autostart", true);

            document.body.appendChild(soundObject);
        }   

    </script>

</head>

<body>

    <form id="form1" runat="server">

        <input type = "button" onclick = "PlaySound()" value = "Play Sound" />

    </form>

</body>

</html>

Solution

  • It's not pretty, but I managed to terminate the sound like this.

    function StopSound()
            {
                 if (soundObject != null) {
    
                    soundObject.setAttribute("src", "");
                    soundObject = null;
    
                }
            }