#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    3
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    This might be an issue with chrome, try:
    Code:
    function RxProtocol()
    {
        var a = document.getElementById("audio1");
    	
        if (window.chrome) {
            a.load();
        }
        
        a.play();
    }
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    3
    Rep Power
    0
    It worked!
    Thanks man...
    So, for google chrome we need to load first before play?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    Exactly, or it will only play once. Found it here: http://stackoverflow.com/a/8959342

IMN logo majestic logo threadwatch logo seochat tools logo