我正在动态创建音频文件并动态更改源。但是,在我更改 src 并尝试更改 currentTime 之后,我总是会收到 Invalid state 错误。你如何进行测试?或者更好地在它准备好时触发一个事件,然后调用 currentTime 来改变它的音频位置。
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()) && 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();
}
};