I have a mute button that simply mute a HTML5 audio object. It does mute the track but I like to add a fade in/out effect.
I tried it by adding audio.animate({volume: 0}, 2000);
but its not working.
Any idea?
Thank in advance!
audio = new Audio();
audio.src = "http://myst729.qiniudn.com/within-temptation_pale.mp3"
audio.play();
$(".mute").on("click tap", function(){
if (audio.muted) {
audio.animate({volume: 1}, 2000);
audio.muted = false;
$(this).text("mute");
} else {
audio.muted = true;
audio.animate({volume: 0}, 2000);
$(this).text("unmute");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="mute">mute</button>