I need to know the current time of a source that is playing, but I can't use context.currentTime because when I change the source.playbackRate.value the speed rate of the context don't change too, so I can't determinate where is the current position of sound. There isn't another way?
Edit, some code:
I use this functions to load and play an mp3 from the network
function loadSoundFile(url) { source = null; var request = new XMLHttpRequest(); request.open('GET', url, true); request.responseType = 'arraybuffer'; request.onload = function(e) { context.decodeAudioData(request.response, initSound, function() { alert("error"); }); }; request.send(); } var source = null; var inittime = 0; function initSound(buffer) { source = context.createBufferSource(); source.buffer = buffer; source.connect(context.destination); source.start(0); inittime = context.currentTime; //I save the initial time }
Then to get the actual position of the audio track I should do:
var current_position = context.currentTime-inittime;
This work fine while I don't change in the source the playbackRate:
source.playbackRate.value
I need to change this value dynamically to synchronize the audio track to another audio track that is playing, so I need to speed up, if the actual position of the track is lower than the position received from a "server" or slow down if it is higher. But if I change the play back rate how I can know where is currently the position of the audio track?
In fact now if I use
var current_position = context.currentTime-inittime;
current_position will be the time spent from the begin of the playback that is different from the current time position of the playback dude the changes playbackrate value.