www.webdeveloper.com
Results 1 to 7 of 7

Thread: .mouseup, .mousedown - paly sound

  1. #1
    Join Date
    Nov 2012
    Posts
    4

    .mouseup, .mousedown - paly sound

    Hello. Ive got a problem, trying to solve it for two days now, but wasnt lucky enough to find solution so far. I hope you might help me. I need a script which plays a sound whenever I click on a picture, but when I release the mouse button the sound stops playing and another sound will play. (Im trying to implement a piano on my web, the picture are the keys, first sound is the note, second sound is reverberation) This is what ive got so far:

    Code:
    <section id="two">
          <div class="inside">
                <div id="nav-two" class="nav">
                      <audio id="beep-two">
                            <source src="piano/E5.mp3" controls></source>
                            <source src="piano/E5.ogg" controls></source>
                            Your browser does not support that. Please get a new version.
                       </audio>
    <a
          onMouseOver="self.document['obrazek3'].src='piano/a_001.png'"
          onMouseOut="self.document['obrazek3'].src='piano/001.png';"
          onMouseDown="self.document['obrazek3'].src='piano/b_001.png';">  
          <img id="obrazek_id_3" name="obrazek3" style="margin-left: 100px; position: absolute;" hspace=5 src="piano/001.png" border="0">
    </a>
    </div>
                <script>$("#nav-two a")
                  .each(function(i) {
                    if (i != 0) { 
                      $("#beep-two")
                        .clone()
                        .attr("id", "beep-two" + i)
                        .appendTo($(this).parent()); 
                    }
                    $(this).data("beeper", i);
                  })
                  .mousedown(function() {
                    $("#beep-two" + $(this).data("beeper"))[0].play();
                  });
                $("#beep-two").attr("id", "beep-two0");</script>
          </div>
    </section>
    Script for one key, ive tried at least 70 variations but the problem is Im not able to make the sound stop playing when i release the button. I implemented everything Ive found but Im writting it syntactically wrong I guess. (.mouseup, .mousedown). Im not able to add .currentTime=0 (I guess bad syntax again). Next issue, Ive tried (with help of Google xD) to make one script using "hover" nevertheless it works the way that it plays the sound when I move the cursor into the key area and thats not what I need again.

    Code:
     <script src="(URL address blocked: See forum rules)"></script>
    
        <div class="birds">
        <audio src="piano/C5.ogg" preload="auto"></audio>
        </div> 
    
        <script language="javascript" src="(URL address blocked: See forum rules)"></script>
    
        <script type="text/javascript">
        $(function(){
        var birdhover     = $('.birds');
            var birdaudio = birdhover.find('audio')[0];
    
        birdhover.hover(function(){
           birdaudio.play();
        }, function(){
           
           var audioElm = document.getElementById('soundTour');
           birdaudio.currentTime=0;
           birdaudio.pause();
    
        });
    });
        </script>
    Reply by illustrative demonstration please

    THX

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    can you share online link ? i have tested it with minor modification and it works fine, here is what did i try.


    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <div class="birds" style="width: 100px; height: 100px; border: 1px solid red;">
      <audio src="horse.ogg"> Your browser does not support the audio element. </audio>
    </div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
    <script type="text/javascript">
        $(function(){
        var birdhover     = $('.birds');
            var birdaudio = birdhover.find('audio')[0];
    
        birdhover.hover(function(){
           birdaudio.play();
        }, function(){
           
           var audioElm = document.getElementById('soundTour');
           birdaudio.currentTime=0;
           birdaudio.pause();
    
        });
    });
    </script>
    </body>
    </html>

  3. #3
    Join Date
    Nov 2012
    Posts
    4
    Thank you for your responce but perhaps theres a little misunderstanding. My both scripts work but Im not syntactically able to make action currentTime=0 happen (this action should happen after the click, actually when I release the button).

  4. #4
    Join Date
    Mar 2009
    Posts
    452
    still your problem isnt clear

  5. #5
    Join Date
    Nov 2012
    Posts
    4
    Im trying to add a piano on my website. I need 3 actions to happen. When I click on the key it plays sound, when I release the button the first sound stops playing and another one starts to play (reverbation). I need to (or at least I think so) add function .mouseup or similar so the first sound stops playing after releasing the mouse button and the reverbation sound starts to play. I am not able to add that function or if that function is wrong I dont know which function is correct.

  6. #6
    Join Date
    Apr 2006
    Posts
    66
    Suggestion: create an "image map" of keyboard. Then use an "onMouseover" "onMouseout event"

  7. #7
    Join Date
    Nov 2012
    Posts
    4
    hm. no help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles