Skip to content

修复 YouTube Music 歌曲在非 YouTube 服务器激活时播放失败#10

Merged
openlyst merged 2 commits into
mainfrom
fix/ytm-playback-routing
Jul 20, 2026
Merged

修复 YouTube Music 歌曲在非 YouTube 服务器激活时播放失败#10
openlyst merged 2 commits into
mainfrom
fix/ytm-playback-routing

Conversation

@openlyst

@openlyst openlyst commented Jul 20, 2026

Copy link
Copy Markdown
Owner

GitLab MR: !90

Original: https://gitlab.com/Openlyst/doudou/-/merge_requests/90

问题 切换到 Subsonic/Jellyfin/Plex 服务器后, 播放收藏夹/最近播放里的 YouTube Music 歌曲会失败, 日志里反复出现: {"message":"Failed to find specified track","name":"TrackNotFound","statusCode":404} ## 原因 YouTube Music 后端从不给歌曲打 serverId 标签。_serverTypeForExtrasMediaItemBuilder._inferBackendTypeFromServer 在缺少 serverId 时会回退到当前激活的服务器类型。于是当激活服务器是 Subsonic 时, YouTube 视频 ID 被当成 Subsonic track ID 拼进 rest/stream.view?id=... 请求, 远端查不到就返回 404。 ## 修复 - audio_handler._serverTypeForExtras: 只在歌曲显式携带 serverId 时才解析后端类型, 否则返回 null (走 YouTube Music 路径) - MediaItemBuilder._inferBackendTypeFromServer: 只从显式 serverId 推断 backendType, 不再回退到激活服务器 这样未打标签的歌曲一律按 YouTube Music 处理, 不受当前激活服务器影响。已经带 serverId 的 Subsonic/Jellyfin/Plex 歌曲不受影响。 #### 验证 - flutter analyze lib/services/audio_handler.dart lib/models/media_Item_builder.dart 无问题 ## Summary by CodeRabbit * Bug Fixes * Improved desktop playback reliability when starting songs or switching tracks. * Fixed playback interruptions caused by timing issues during media loading. * Prevented untagged song identifiers from being incorrectly routed through the currently active server. * Unspecified song identifiers now retain YouTube Music behavior by default.

YouTube Music 后端不给歌曲打 serverId 标签, 之前 _serverTypeForExtras
和 _inferBackendTypeFromServer 在缺少 serverId 时会回退到当前激活服务器.
当用户切换到 Subsonic/Jellyfin/Plex 后, 收藏夹里的 YouTube 歌曲会被
错误地路由到这些后端, 视频 ID 在远端查不到就返回 TrackNotFound 404.

现在只在歌曲显式携带 serverId 时才解析后端类型, 没有标签的歌曲一律
走 YouTube Music 路径, 不再受激活服务器影响.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

三个问题叠加导致桌面端所有后端的歌曲都无法播放:

1. play() 重写在桌面端检查 _player.duration, 如果为 0 就重走
   playByIndex, 但 media_kit 异步报告 duration, 导致用户点播放时
   反复重载歌曲却始终不播放。改为只在 currentSongUrl 为 null 时
   才走 playByIndex。

2. playByIndex 和 setSourceNPlay 无条件调用 _player.stop(), 在
   media_kit 上 stop+clear+open(new source) 后 play() 无法启动
   播放。stop() 当初是为了修复自动切歌时 player 卡在 completed
   状态, 现在改为只在 completed 时才 stop。

3. just_audio_media_kit 的 load() 内部调用 _player.pause() 没有
   await, 这个 pause 可能在 play() 之后才到达 MPV, 导致播放器最终
   处于暂停状态。新增 _ensurePlaybackStarted() 在桌面端延迟 300ms
   后检查播放器状态, 如果没在播放就重新发 play()。
@openlyst
openlyst merged commit 946aa68 into main Jul 20, 2026
14 checks passed
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