javascript - How do I prevent the error "Uncaught (in promise) DOMException: The play() request was interrupted by a ca

I am facing this problem in a chrome browser. When I click on any audio, it throws an exception. My aud

I am facing this problem in a chrome browser. When I click on any audio, it throws an exception. My audio tag is in a loop, and when I click on the audio or refresh it using ajax, then the exception is thrown.

I am facing this problem in a chrome browser. When I click on any audio, it throws an exception. My audio tag is in a loop, and when I click on the audio or refresh it using ajax, then the exception is thrown.

Share edited May 11, 2016 at 13:01 zlog 3,3165 gold badges43 silver badges82 bronze badges asked May 10, 2016 at 10:38 vikas palvikas pal 751 silver badge9 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

I don't know if this will help you, but I still leave my ment so maybe it will help somebody else. I had similar issue, and the solution proposed by @dighan on bountysource./issues/ solved it for me.

So here is the code that solved my problem:

var media = document.getElementById("YourVideo");
const playPromise = media.play();
if (playPromise !== null){
    playPromise.catch(() => { media.play(); })
}

Just add it in document.ready

It still throws an error into console, but at least the video is playing :) I think this should work for audio as well.

I got the same error when my media wasn't loaded. Check these:

  1. Your media has the correct src.
  2. Your media is loaded before you play it.

I've recently noticed this happening on one of my sites that had no problems before, and hasn't been changed at all. It appears to be a known bug in Chrome -- take a look at the issue tracker here: https://bugs.chromium/p/chromium/issues/detail?id=593273

It seems that there is no way to prevent the error until this is fixed by the Chrome team.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744814502a4595241.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信