ie11中设置audio的currentTime报错InvalidStateError

环境:win7 32位,ie11

要做一个切换歌曲功能:

Sspan.on(downEvent, function () {
    switchTime = au1[0].currentTime;
    curAudio = (curAudio + 1) % 2;
    au1.attr("src", audio2[curAudio]);
    au1[0].play();
    au1[0].currentTime = switchTime;
});
ie报错InvalidStateError,搜索了一下,需等文件加载完毕,解决方案如下

au1.on('loadedmetadata', function () {
    if (switchTime != 0) {
        au1[0].currentTime = switchTime;
        switchTime = 0;
    }
});

参考:

http://stackoverflow.com/questions/20245164/audio-currenttime-invalidstateerror-ie11-js-html5

https://msdn.microsoft.com/zh-cn/library/ff974748%28v=vs.85%29.aspx

你可能感兴趣的:(IE,11,currentTime)