Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().

解决方法:
audio.load()
let playPromise = audio.play()
if (playPromise !== undefined) {
    playPromise.then(() => {
        audio.play()
    }).catch(()=> {

    })
}

原因:
从Chrome50开始,对<video>或<audio>元素的play()调用返回一个Promise。
一个异步返回单个结果的函数。如果回放成功,Promise就会实现,而play事件也会同时触发,对应执行.then。
如果回放失败,Promise将被拒绝,同时会有一个错误消息解释失败,对应执行.catch。

错误发生的过程为:
1.media.play() 开始异步加载video/audio内容。
2.media.pause() 在video/audio没有准备好时中断加载。
3.media.play() 此时进行继续播放,报错。

原文地址:https://www.cnblogs.com/Man-Dream-Necessary/p/9952415.html

时间: 2024-08-01 09:56:47

Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().的相关文章

关于 Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() 错误

最近在做项目的时候发现一个如题的控制台报错. 一看右侧的报错文件是undefined 这下苦恼了,定位不到问题所在. 今天解决了这个问题,就来分享一下. 问题的关键所在是在执行了play()方法以后立即执行pause()方法.反之亦然 以下贴出代码 HTML: <button id="btn1">test</button> JS: var music=new Audio();music.src="/1.mp3";//这里替换成一个有效的音频文

Uncaught (in promise) DOMException: play() failed because the user didn&#39;t interact with the document first.

最近在开发一个网站时,有个需要是 如果有新预警信息要在网页中播放提示音.页面打开会请求是否有新信息,有则播放提示音.在Chrome的最新浏览器中,播放会报错,控制台显示Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.搜索发现Chrome 66为了避免标签产生随机噪音禁止没有交互前使用js进行播放.最后解决方案为 在chrome地址栏

Uncaught (in promise)

如果promise中 reject的错误没有被catch出来就会报这个错误 // Uncaught (in promise) let a = new Promise((resove,reject)=>{ reject(1) } // ok let a = new Promise((resove,reject)=>{ reject(1) }.then((res)=>{},(err)=>{}) // Uncaught (in promise) let b = new Promise((

使用promise封装微信we.request进行数据请求

wx.request的进一步加工 先来看一下主要目录结构 siteinfo.js中的内容为接口基本信息 // siteinfo.js module.exports = { name: '接口说明', // 可不写 site_root: '公共接口' // 公共接口地址 如:http://123.123.123.123:3000 } request.js中为使用promise封装的wx.request // request /** * * @param {参数} params */ functio

Vue ElementUI Axios报错: Uncaught (in promise) TypeError: Cannot read property &#39;$message&#39; of undefined

从头再来!!! 出错的代码如下: login() { this.loading = true let userInfo = {account: this.loginForm.account, password: this.loginForm.password, captcha: this.loginForm.chptcha} this.$api.login.login(userInfo).then( function(res) { if (res.msg != null) { this.$mes

基于Promise封装uni-app的request方法,实现类似axios形式的请求

https://my.oschina.net/u/2428630/blog/3004860 uni-app框架中 安装(项目根目录下运行) npm install uni-request --save 文件中引用 import uniRequest from 'uni-request'; 使用方法 请求方法的别名 uniRequest.request(config) uniRequest.get(url[, config]) uniRequest.delete(url[, config]) un

vue-router点击菜单栏同一个模块报错 ———— Uncaught(in promise) NavigationDuplicated error .......

在做移动端底部导航时,鼠标双击各个选项会报如下错误,但是单击时不会出现任何问题. 出现这个bug的原因就是vue-router版本问题,vue-router 3.0版本以上的回调形式是promise api的形式,返回的是一个promise,如果没有捕获到错误,控制台始终会出现上图的警告: 解决方法之可以是安装低版本的vue-router或者捕获抛出放入错误: 解决方法大概包括以下3种解决方法: 1)删除node_modules文件夹,然后使用“cnpm install”重新安装依赖(ps:尝试

vue router 报错: Uncaught (in promise) NavigationDuplicated {_name:&quot;&quot;NavigationDuplicated&quot;... 的解决方法

今天在写vue-music的时候,发现每次跳转路由都会出现这个错误,于是上网查了一下解决的方法 在main.js中添加 import Router from 'vue-router' const originalPush = Router.prototype.push Router.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) } 原文地址

Chrome浏览器视频自动播放报Uncaught(in promise)DOMException

先看代码 用jquery 实现视频的自动播放 $(function () { var vList = ['video/zykj.mp4']; // 初始化播放列表 var vLen = vList.length; // 播放列表的长度 var curr = 0; // 当前播放的视频 var video = document.getElementById("myvideo"); video.addEventListener('ended', play1);//监听 play1(); f