title: HTML5 audio - testing for Invalid State Error ( Or Dom Exception 11 )
body: <p>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 do you go about testing for it? Or better fire a event when its ready and then calling currentTime to change its audio position. </p>
  
  <pre><code>this.doneLoading = function(aTime){
  
      try{
          this.mAudioPlayer.currentTime = aTime / 1000.0;
      }catch(err){
          console.log( err );
      }
      this.mAudioPlayer.play();   
  }
  
  this.playAtTime = function(aTime) {
      Debug("play at time audio: " + aTime);
      Debug("this.mAudioPlayer.currentTime: " + this.mAudioPlayer.currentTime);
  
       this.startTime = aTime;
  
      if (this.mAudioPlayer.src != this.mAudioSrc) {
          this.mAudioPlayer = new Audio();
          this.mAudioPlayer.src = this.mAudioSrc;
          this.mAudioPlayer.load();
          this.mAudioPlayer.play();
          this.mAudioPlayer.addEventListener('canplaythrough', this.doneLoading(aTime), false );
      }
      else if ((isChrome() || isMobileSafari()) &amp;&amp; aTime == 0) {
          this.mAudioPlayer.load();
          this.mAudioPlayer.currentTime = aTime / 1000.0;
          this.mAudioPlayer.play();
          Debug("Reloading audio");
      }else{
  
          this.mAudioPlayer.currentTime = aTime / 1000.0;
          this.mAudioPlayer.play();
      }       
  
  
  
  };
  </code></pre>