javascript audio.currentTime invalidStateError IE11、JS、HTML5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20245164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
audio.currentTime invalidStateError IE11, JS, HTML5
提问by user2998173
I get this error in IE11, i have temporary changed all variables on just a number, but i can't get rid of this error.
我在 IE11 中收到此错误,我临时更改了一个数字上的所有变量,但我无法摆脱此错误。
audio.currentTime = 10;
The error looks like:
错误看起来像:
SCRIPT5022: InvalidStateError
This script works good in Chrome and Firefox. According to this pageit is should work.
此脚本在 Chrome 和 Firefox 中运行良好。根据此页面,它应该可以工作。
回答by Tom G
I know this question is old but I just encountered the same problem and wanted to post what I learned.
我知道这个问题很老,但我刚刚遇到了同样的问题,想发布我学到的东西。
Did your audio player successfully load the audio? If the src="#" or if you gave the player the wrong path to the audio file the line of code you provided will give the error you mentioned.
您的音频播放器是否成功加载了音频?如果 src="#" 或者如果您为播放器提供了错误的音频文件路径,则您提供的代码行将给出您提到的错误。
I would suggest trying the following code where audioPlayer is the id of the audio element to perform a simple check that the audio file has indeed loaded:
我建议尝试以下代码,其中 audioPlayer 是音频元素的 id 以执行简单的检查音频文件确实已加载:
if (!isNaN(aud.duration)) {
aud.currentTime = vid.currentTime;
}
But of course, if you're expecting the audio to have loaded, fix the path to the audio file
但是当然,如果您希望音频已加载,请修复音频文件的路径
回答by vinesh
In IE11, this error occurs while accessing the currentTime
attribute of video before the meta data of video is loaded. So following code solved my error.
在IE11中,在currentTime
加载视频元数据之前访问视频属性时会出现此错误。所以下面的代码解决了我的错误。
vidEl.addEventListener('loadedmetadata', function() {
vidEl.currentTime = someSeekTime;
}, false);
Hope this helps someone.
希望这可以帮助某人。
回答by alwin
Just wanted to add that converting the Wav file to MP3 solved the issue for me. Using https://stackoverflow.com/a/20462684/5053952prevented the error but the Wav file still would not play. Converting to MP3 solved the issue completely.
只是想补充一点,将 Wav 文件转换为 MP3 为我解决了这个问题。使用https://stackoverflow.com/a/20462684/5053952防止了错误,但 Wav 文件仍然无法播放。转换为 MP3 完全解决了这个问题。
(IE11 on Win10)
(Win10 上的 IE11)