2

First off here is my javascript code:

$(function() {
stepFade('.fadable',700,1);
});

function stepFade(target, speed, opacity) {
    var mysound = new Audio("./sounds/kick.mp3");
    var $fade = $(target);
    ($fade).each( function( i ) {
        $(this).delay(i*speed).fadeTo(speed, opacity);
        mysound.play();
        mysound.currentTime = 0;
    });
}

My goal here is to play a sound in conjunction with the fade ins that are happening on the website with jquery. I'm having trouble looping the sound in a way so that they are in sync. I've tried resetting the currentTime and that doesn't seem to work for some reason.

Another method would be to use mysound.loop(); however this just plays the sound in a loop without any considerations in the timing of the sounds. Thus this becomes de-synchronized with the animations.

Anyone can first explain why setting the current time doesn't work and what possible solutions exists?

Thanks!

Vangogh500
  • 939
  • 1
  • 7
  • 17
  • I find the `currentTime` to be quite fragile on browsers. There are a number of caveats to getting it to work: http://stackoverflow.com/questions/16966724/html5-audio-currenttime-doesnt-work - this one has bitten me: http://pervasivecode.blogspot.co.uk/2012/09/currenttime-not-working-with-html5.html – CodingIntrigue May 16 '15 at 05:53

0 Answers0