9

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.

audio.currentTime = 10;

The error looks like:

SCRIPT5022: InvalidStateError

This script works good in Chrome and Firefox. According to this page it is should work.

user2998173
  • 337
  • 2
  • 5
  • 10
  • 3
    Since IE doesn't really support anything properly, the fastest solution I came up with was putting a try/catch on my audio function. IE users shouldn't be allowed to have sound if they still use this browser... – Jester Feb 06 '18 at 21:25

3 Answers3

23

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.

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:

    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

Tom G
  • 3,650
  • 1
  • 20
  • 19
19

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.

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

Hope this helps someone.

vinesh
  • 4,745
  • 6
  • 41
  • 45
0

Just wanted to add that converting the Wav file to MP3 solved the issue for me. Using https://stackoverflow.com/a/20462684/5053952 prevented the error but the Wav file still would not play. Converting to MP3 solved the issue completely.

(IE11 on Win10)

alwin
  • 1