Skip to content

fix: end quietly when Plex closes the player and ride out MSE quota - #9

Merged
InfinityPacer merged 1 commit into
mainfrom
fix/plex-close-and-mse-quota
Oct 6, 2026
Merged

InfinityPacer merged 1 commit into
mainfrom
fix/plex-close-and-mse-quota

Conversation

@InfinityPacer

Copy link
Copy Markdown
Owner

用户影响

  • 在 Plex Web 里点「关闭播放器」后,画面上方常会弹出「ShimWeave 播放已中断,播放未能继续,请关闭后重新播放(playback_failed)」,播放本身并没有出错。
  • 高码率音轨的片源播放中途可能因浏览器缓冲配额耗尽而中断,提示 buffer_quota。

原因

  • Plex Web 关闭播放器时直接移除 video 并清空 src,Hook 只拦截 Shaka load,扩展收不到 takeover-stop。MSE 控制器下一次操作 SourceBuffer 抛出未映射的 InvalidStateError,Host 按播放失败处理并提示中断。
  • Chrome 按轨限制 SourceBuffer,默认音频 12 MB、视频 150 MB。现有预算是前向 90 秒加至少 30 秒历史与总计 128 MB,音频轨在码率较高时会先于这些预算触顶,且历史缓冲已被浏览器回收时没有可淘汰的数据,直接失败。

改动

  • mse-controller 在失败时检查媒体元素是否仍指向本会话的 MediaSource,被外部接走则改抛 MseMediaDetachedError,并且无论 src 是否已被替换都释放 object URL。
  • plex-native-host 把 MseMediaDetachedError 当作正常结束,记为 detached,不提示失败或中断,并发 takeover-error: media_detached 让 Hook 释放会话。不发这条消息时,同一媒体再次 load 会复用已结束的接管,播放器一直转圈。
  • 配额满且淘汰旧缓冲后仍写不进时,把前向窗口收窄到当前前向缓冲的八成,等播放推进后重试同一块;只有前向缓冲不足 5 秒时才报 MseBufferQuotaExceededError。
  • 播放观测把 MseMediaDetachedError 归为 cancelled,不记作网络失败。

验证

pnpm build       通过
pnpm test        Test Files 51 passed (51)  Tests 378 passed (378)
pnpm typecheck   通过
biome check      改动文件通过
  • 新增测试覆盖配额满时等待播放推进后重试、外部清掉 src 后归为外部卸载并只释放一次 object URL、Host 对外部卸载静默收尾并通知 Hook。
  • 在调试 Chrome 中加载本分支构建,播放一个 STRM 剧集(Plex Web 4.160)。点「关闭播放器」后 video 记为 detached,页面没有中断提示;随后再次点播放,扩展重新接管且进度正常推进。
  • 配额路径只有单元测试,尚未用高码率音轨片源在真实页面复现。

🤖 Generated with Claude Code

Closing the player in Plex Web clears the video src before any
takeover-stop arrives, so the next SourceBuffer call threw an unmapped
InvalidStateError and users saw "playback_failed" right after they
stopped. A detached media element now ends the session as a normal
stop and tells the hook to release the takeover.

Chrome limits each SourceBuffer track separately (12 MB audio by
default), so high-bitrate audio could exhaust the quota inside the
90 s window and end playback with buffer_quota. A quota hit now narrows
the forward window and retries once playback frees space, failing only
when the buffer cannot hold a few seconds ahead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@InfinityPacer
InfinityPacer merged commit e0668ec into main Oct 6, 2026
1 check passed
@InfinityPacer
InfinityPacer deleted the fix/plex-close-and-mse-quota branch October 6, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant