Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Audio played once only in Google Chrome in html

    The below code is how I put audio in my webpage. It will play the sound when I received protocol from my slave device.

    Code:
    <script>
    function RxProtocol()
     {
        var a = document.getElementById("audio1");
        a.play();
     }
    
    </script>
    
    <body>
    <audio id="audio1">
    <source src="audio.wav" type="audio/wav">
    <source src="audio.mp3" type="audio/mpeg">
    audio tag not supported.
    </audio>
    </body>
    It is suppose to play the sound each time it received a protocol. But when I use google Chrome, it just play once only (after refresh/reloading the page) when it received the first protocol. After that it is silence when receive protocols.

    Other browser like IE9 or firefox do not have this problem. Do you guys know why?

  • #2
    New Coder
    Join Date
    Apr 2013
    Posts
    38
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Thumbs up Try adding addEventListener :

    Try adding addEventListener :

    Code:
    <script>
    function RxProtocol()
     {
        var a = document.getElementById("audio1");
        a.play();
     }
    
    document.addEventListener("load", RxProtocol, false);
    
    </script>
    Regards,

    John


  •  

    Posting Permissions

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