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 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    60
    Thanks
    1
    Thanked 0 Times in 0 Posts

    sound, calling sound after delay

    Trying to call a sound after 5 second delay, after a while it will be a php call, so after a certain amount of time call the sound, but first I have to get delaying the sound to the certain point down.

    <html>
    <head>

    </head>
    <body>
    <audio id="audio2"
    preload="auto"
    src="http://upload.wikimedia.org/wikipedia/commons/a/a9/Tromboon-sample.ogg" >

    <p>Your browser does not support the audio element</p>
    </audio>
    <input type="button" onclick="stop()">
    <script type="text/javascript">
    setTimeout(function() { play(); }, 5000);

    function play(){
    myAudio=document.getElementById('audio2');
    myAudio.addEventListener('canplaythrough', function() {
    this.currentTime = 12;
    this.play();
    });
    }

    </script>
    </body>
    </html>

    it doesn't work, but this is what I have so far, it plays the sound if I take out the function variable

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Not a thing to do with Java. Moving to the Javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 584 Times in 565 Posts
    Code:
    <script type="text/javascript">
    setTimeout( play, 5000);
    
    
    function play(){
       myAudio.play();
    }
    
    myAudio=document.getElementById('audio2');
    myAudio.addEventListener('canplaythrough', function() {
       this.currentTime = 12;
    });
    </script>
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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