HTML5 audio - testing for Invalid State Error ( Or Dom Exception 11 )

后端 未结 2 804
我寻月下人不归
我寻月下人不归 2021-02-15 16:01

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. H

2条回答
  •  一整个雨季
    2021-02-15 16:31

    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 );
    

提交回复
热议问题