Skip to content Skip to sidebar Skip to footer

Html5 Audio - Testing For Invalid State Error ( Or Dom Exception 11 )

I am dynamically creating a audio file and changing the source on the fly. However after i change the src and try to change the currentTime i always get a Invalid state error. How

Solution 1:

For those coming after who actually need a test to prevent this invalid state error, you can try this:

if(this.readyState > 0)
    this.currentTime = aTime;

Seems to work for me anyways :)


Solution 2:

You are not passing a function reference to your addEventListener - you are calling the function inline. The doneLoading() function executes immediately (before the file has loaded) and the browser correctly throws an INVALID_STATE_ERR:

this.mAudioPlayer.addEventListener('canplaythrough', this.doneLoading(aTime), false );

Try passing in a function reference instead. Like this:

this.mAudioPlayer.addEventListener('loadedmetadata',function(){
    this.currentTime = aTime / 1000.0;
}, false );

Post a Comment for "Html5 Audio - Testing For Invalid State Error ( Or Dom Exception 11 )"