In Internet Explorer 9 (and probably Chrome/Safari) setting audio.currentTime too early will cause a "Dom Exception INVALID_STATE_ERR" because the audio file hasn't been completely loaded yet. Example:
Code: Select all
audioplayer.load() // Preload
$(audioplayer).on('loadeddata', function() { // jQuery: When audio fully loads
audioplayer.currentTime = 123 // <-- ERROR: Cannot be changed yet!
audioplayer.play()
})Anyway, what I'm now trying to implement gets basically explained in the first post over here:
So my question is: How can I implement the above mentioned workaround?I have a workaround using an interval timer with try/catch, which tries to set element.currentTime to an appropriate value, and then finally calls skipTo() after exceptions stop.
What I've set up so far is the following replacement:
Code: Select all
audioplayer.load()
$(audioplayer).on('loadeddata', function() {
global tryplayinterval = setInterval(tryplay(),100)
function tryplay() {
try {
audioplayer.currentTime = 123
audioplayer.play()
clearInterval(tryplayinterval) // Success, stop interval!
} catch (e) {}
}
})