修复 YouTube Music 歌曲在非 YouTube 服务器激活时播放失败#10
Merged
Conversation
YouTube Music 后端不给歌曲打 serverId 标签, 之前 _serverTypeForExtras 和 _inferBackendTypeFromServer 在缺少 serverId 时会回退到当前激活服务器. 当用户切换到 Subsonic/Jellyfin/Plex 后, 收藏夹里的 YouTube 歌曲会被 错误地路由到这些后端, 视频 ID 在远端查不到就返回 TrackNotFound 404. 现在只在歌曲显式携带 serverId 时才解析后端类型, 没有标签的歌曲一律 走 YouTube Music 路径, 不再受激活服务器影响.
三个问题叠加导致桌面端所有后端的歌曲都无法播放: 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()。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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标签。_serverTypeForExtras和MediaItemBuilder._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.