0

On my site I want to play tick/click like sounds on mouse over (hover) or on mouse clicks. Can this be achieved?

I can do this in flash, but I want to avoid flash.

Conner
  • 30,144
  • 8
  • 52
  • 73
Moon
  • 19,518
  • 56
  • 138
  • 200
  • 12
    Please be sure to have a very easy option to disable the feature. There are those of us who get no joy out of a site making noise at us. :-) – Icode4food Oct 20 '10 at 12:13
  • this is answered here http://stackoverflow.com/questions/3342803/audio-on-mouseover – loQ Oct 15 '12 at 02:14
  • If you want to play a sound on-click, then see here: http://stackoverflow.com/questions/12025223/play-sound-on-click – Anderson Green Feb 22 '13 at 18:58

3 Answers3

2

You can play audio with tag or object or embed. This is the best way like below. You can control audio tag with javascript.

You can control audio by clicking these button:

Play Stop

And you must put this script to

<script>
    $(document).ready(function() {
    var audioElement = document.createElement('audio');
    audioElement.setAttribute('src', 'audio.mp3');
    audioElement.setAttribute('autoplay', 'autoplay');
    //audioElement.load()
    $.get();
    audioElement.addEventListener("load", function() {
    audioElement.play();
    }, true);




    $('.play').click(function() {
    audioElement.play();
    });


    $('.pause').click(function() {
    audioElement.pause();
    });

     });

But for Chrome you cant use .play() and .pause(). You must use .Play() and .Stop.

Bluerain
  • 477
  • 5
  • 9
2

See here for all the options that you have if you dont want flash http://www.phon.ucl.ac.uk/home/mark/audio/play.htm

Javascript cannot play audio so one of the above is the only way out.

See 3 & 4 in above link and you can trigger it probably on mouse over with javascript.

OR DHTML to play sound http://webdesign.about.com/od/sound/a/play_sound_oncl.htm

ToughPal
  • 2,231
  • 5
  • 26
  • 30
0

You can control an HTML5 <audio> element from JavaScript.

This won’t work in IE 8 and below (not sure about 9) though, nor in older versions of Firefox, Safari, Chrome and Opera.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270