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,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Not a thing to do with Java. Moving to the Javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,413
    Thanks
    11
    Thanked 595 Times in 575 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 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

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