1.9 KiB
1.9 KiB
诊断结论(已核实):
video-player.js:177 是 toggle() 中的 this.video.play()。播放器进入“无可播放源”状态后,点击封面/遮罩触发 toggle(),该 Promise 没有 catch,于是抛出 Uncaught (in promise) NotSupportedError: The element has no supported sources。播放器进入无源状态有四条已确认路径:
.m3u8在 Chrome:hls.js 从cdn.jsdelivr.net懒加载(video-player.js:22),CDN 不可达时loadScript静默失败(promise 也未 catch),<video>始终没有源;.flv同理(flv.js,video-player.js:23);- 直链 mp4 地址 404/编码不支持,源加载失败后
currentSrc为空; .switch-iframe剧集按钮被 video-player 的委托处理器(video-player.js:225)捕获,把 iframe 嵌入页 URL 当 mp4 塞给video.src,必然无源。.switch-iframe本应由runtime/main.js:1351的 iframe 链路处理。
修复方案(单一路径,不引入双路/迁移):
assets/js/video-player.js:toggle():播放前守卫无源状态(video.currentSrc/video.src/this.hls/this.flvPlayer均为空时直接返回),并对play()返回的 Promise 加.catch(),播放失败不再产生未捕获异常;- 两处
loadScript()(hls/flv)加.catch(),CDN 失败被收敛为“无源”状态,不再产生未处理 rejection; - 委托处理器限定为
.switch-video,移除对.switch-iframe的错误接管(iframe 剧集继续由 main.js 既有链路处理,属于删除错误重叠而非新增实现)。
- 契约测试
tests/widget-system/single-cover-height-contract.test.cjs的 video cover 用例追加断言:toggle 守卫 + play catch、loadScript catch、处理器不含.switch-iframe。 - 验证:
node --check播放器文件、运行single-cover-height-contract及相关契约测试、rg复查、git diff --check;不做真实视觉效果验收。