Audio.currentTime invalidStateError IE11, JS, HTML5

I get this error in IE11, I only temporarily changed all the variables to a number, but I cannot get rid of this error.

audio.currentTime = 10; 

The error looks like this:

 SCRIPT5022: InvalidStateError 

This script works well in Chrome and Firefox. According to this page , it should work.

+6
source share
2 answers

I know this question is old, but I just ran into the same problem and wanted to post what I found out.

Has your audio player downloaded audio successfully? If src = "#" or if you gave the player the wrong path to the sound file, the line of code that you specified will throw the error you specified.

I would suggest trying the following code, where audioPlayer is the identifier of the audio element, in order to perform a simple check that the audio file is really loaded:

  if (!isNaN(aud.duration)) { aud.currentTime = vid.currentTime; } 

But of course, if you expect the audio to load, correct the path to the audio file

+14
source

In IE11, this error occurs when accessing the currentTime attribute of a video before loading the video metadata. So the following code solved my error.

 vidEl.addEventListener('loadedmetadata', function() { vidEl.currentTime = someSeekTime; }, false); 

Hope this helps someone.

+9
source

Source: https://habr.com/ru/post/958928/


All Articles