最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论