2

I have created a fiddle of my function here( http://jsfiddle.net/rhy5K/10/ ) . Now i want to provide the Sound "Mute/unpute" option for users. Example if i click on "a link then sound playing like Get ready,5,4,3,2,1 should be mute and vice-versa.

I am thinking like to call a to toggle_sound function on click, but i am confuse like what should i write inside the function to mute the sound.

Please provide me a logic, or a solution for my problem.

Explanation using code example:

I want to MUTE/UnMUTE this below sound playing

var playGetReady = function (done) {
    var ids = ['audiosource', 'a_5', 'a_4', 'a_3', 'a_2', 'a_1'],
        playNext = function () {
            var id = ids.shift();
            document.getElementById(id).play();
            if (ids.length) {
                setTimeout(playNext, 1000);
            } else {
                done();
            }
        };
    playNext();
};

Warning: This JS fiddle demo may play sound on load

beginner
  • 645
  • 5
  • 13
  • 28
  • Use `document.getElementById(id).setVolume(0);` to mute – Ian Oct 08 '13 at 13:20
  • or `document.getElementById(id).muted = true;` – Oliboy50 Oct 08 '13 at 13:21
  • http://stackoverflow.com/questions/10075909/how-to-set-the-loudness-of-html5-audio or http://stackoverflow.com/questions/13937118/set-volume-of-html-5-audio-tag-with-javascript – Alex Oct 08 '13 at 13:21
  • @Ian okay i got it, now I want to check whether sound is playing or not, how to check ? – beginner Oct 08 '13 at 13:35
  • @rani I added a toggle volume handler in your jsfiddle, but it seems that your App class is not really functionnal already. Maybe if you work on a bit more, this could work : http://jsfiddle.net/rhy5K/25/ – Oliboy50 Oct 08 '13 at 13:59
  • @Oliboy50 I am trying since last few mins for this but still not done. May be if you also try for me then it wil be more helpfull. I can see you set `this.muted`, but you don't use it to prevent playing sound. I think You should check if it's muted like with `this.newTimer` in start method – beginner Oct 08 '13 at 14:45
  • @Ian is it possible to solve to update a fiddle for me? i could not solve this, since last 1 hour. Feeling very difficult. – beginner Oct 08 '13 at 15:06

2 Answers2

0

Try

HTML5 Video_tag for display video with audio

or this below example along with html5 with jquery

window.my_mute = false;

$('#my_mute_button').bind('click', function(){

$('audio,video').each(function(){

    if (!my_mute ) {

        if( !$(this).paused ) {
            $(this).data('muted',true); //Store elements muted by the button.
            $(this).pause(); // or .muted=true to keep playing muted
        }

    } else {

        if( $(this).data('muted') ) {
            $(this).data('muted',false);
            $(this).play(); // or .muted=false
        }

    }
});

my_mute = !my_mute;

});

thiyaram
  • 222
  • 2
  • 8
  • Kindly delete your answer its no use for me according to my question. And its neither solve my problem – beginner Oct 08 '13 at 14:46
0

I think you can use:

document.getElementById(id).volume = 1;

or

document.getElementById(id).volume = 0;
  • but before applying this, how can i check whether the sound is playing or not? Better can you update my fiddle(http://jsfiddle.net/rhy5K/10/) ? – beginner Oct 08 '13 at 13:38
  • those links i know, but you really want to help me means, plz update my fiddle with the answer as i wanted. Your link does not solve my problem – beginner Oct 08 '13 at 14:31