Web video player errors All In One
Web video player errors All In One
errors
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 new load request.
<video id="video" preload="none" src="https://example.com/file.mp4"></video>
<script>
video.play(); // <-- This is asynchronous!
video.pause();
</script>
solutions
Autoplay
<video id="video" preload="none" src="https://example.com/file.mp4"></video>
// Show loading animation.
var playPromise = video.play();
if (playPromise !== undefined) {
playPromise.then(_ => {
// Automatic playback started!
// Show playing UI.
})
.catch(error => {
// Auto-play was prevented
// Show paused UI.
});
}
Play & Pause
<video id="video" preload="none" src="https://example.com/file.mp4"></video>
// Show loading animation.
var playPromise = video.play();
if (playPromise !== undefined) {
playPromise.then(_ => {
// Automatic playback started!
// Show playing UI.
// We can now safely pause video... ✅
video.pause();
})
.catch(error => {
// Auto-play was prevented
// Show paused UI.
});
}
demos
Fetch & Play
<video id="video" src=""></video>
<button id="button"></button>
button.addEventListener('click', onButtonClick);
function onButtonClick() {
// This will allow us to play video later...
video.load();
fetchVideoAndPlay();
}
function fetchVideoAndPlay() {
fetch('https://example.com/file.mp4')
.then(response => response.blob())
.then(blob => {
// blob ✅
video.srcObject = blob;
// Promise
return video.play();
})
.then(_ => {
// Video playback started ;)
})
.catch(e => {
// Video playback failed ;(
})
}
Danger zone
<source>
within <video>
makes play() promise never rejects
For <video src="not-existing-video.mp4"\>
, the play() promise rejects as expected
as the video doesn't exist
.
For <video><source src="not-existing-video.mp4" type='video/mp4'></video>
, the play() promise never rejects
.
It only happens if there are no valid sources
.
refs
https://developer.chrome.com/blog/play-request-was-interrupted
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/18428913
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2023-09-24 Tesla Bot All In One
2022-09-24 GoPro 钓鱼 All In One
2022-09-24 中国原生鱼 & 鳑鲏鱼 All In One
2022-09-24 老赖信息查询系统 All In One
2021-09-24 Linux System Variables All In One
2020-09-24 MDN Browser Compatibility Report 2020
2020-09-24 how to check SVG type in js