Conversation
kid141252010
commented
Mar 10, 2026
- parseTTML: 新增 extractTtmlLyricOffsetMs 和 applyLyricOffsetToLines
- IPlaybackEngine: 新增 getChannels() 可选方法
- FFmpegAudioPlayer/AudioElementPlayer/MpvPlayer: 实现 getChannels()
- MpvPlayer: 监听 audio-params/channel-count 获取声道数
- MpvService: 观察 audio-params/channel-count 属性
- AudioManager: 暴露 getChannels() 方法
- status store: 新增 currentAudioChannels 状态
- LyricManager: TTML 偏移仅在6声道时应用,修复预加载缓存时序
- PlayerController: canplay 时更新声道数,声道变化时自动重载歌词
- parseTTML: 新增 extractTtmlLyricOffsetMs 和 applyLyricOffsetToLines - IPlaybackEngine: 新增 getChannels() 可选方法 - FFmpegAudioPlayer/AudioElementPlayer/MpvPlayer: 实现 getChannels() - MpvPlayer: 监听 audio-params/channel-count 获取声道数 - MpvService: 观察 audio-params/channel-count 属性 - AudioManager: 暴露 getChannels() 方法 - status store: 新增 currentAudioChannels 状态 - LyricManager: TTML 偏移仅在6声道时应用,修复预加载缓存时序 - PlayerController: canplay 时更新声道数,声道变化时自动重载歌词
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the lyric display accuracy for Dolby Atmos (6-channel) audio by implementing TTML lyric offset support. It involves modifications across multiple components, including playback engines, the AudioManager, and the LyricManager, to ensure correct lyric synchronization based on the audio channel configuration. The changes also address potential issues with pre-loaded lyric caches and ensure that the lyric display is updated dynamically when the audio channel configuration changes. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
本次 PR 主要是为了支持杜比全景声(6声道)TTML歌词的偏移功能。整体实现思路清晰,通过在各个播放引擎中获取声道数,并在 LyricManager 中根据声道数判断是否应用 TTML 文件中定义的偏移,逻辑正确。代码在多个层面进行了修改,包括播放器引擎接口、具体实现、状态管理和播放控制器,覆盖了所需的功能点。
我发现了一些可以改进的地方:
PlayerController中使用setTimeout轮询检查声道数,这种方式不够健壮,建议改为事件驱动的模式。LyricManager中存在几处重复的 TTML 解析逻辑,可以提取为辅助函数以提高代码可维护性。LyricManager中有一处空的catch块,建议添加日志以方便问题排查。
具体的修改建议请见代码评论。
| setTimeout(() => { | ||
| syncChannelsAndRefreshLyric(); | ||
| }, 200); | ||
| setTimeout(() => { | ||
| syncChannelsAndRefreshLyric(); | ||
| }, 600); |
There was a problem hiding this comment.
使用多个 setTimeout 来轮询获取音频声道数的方式不够健壮。它依赖于固定的延迟,如果引擎获取声道数的时间超过 600ms,可能会导致逻辑失败。
建议采用事件驱动的模式来代替轮询:
- 在
IPlaybackEngine接口中增加一个可选的channelschanged事件。 - 在各个播放器引擎实现中(
MpvPlayer,AudioElementPlayer,FFmpegAudioPlayer),当获取到声道数或声道数发生变化时,派发channelschanged事件。 - 在
PlayerController中,监听audioManager的channelschanged事件,并在事件回调中调用syncChannelsAndRefreshLyric。
这种方式可以更及时、可靠地响应声道数的变化,并移除当前的 setTimeout 写法。
| const lyricOffsetMs = this.shouldApplyTtmlOffset() | ||
| ? extractTtmlLyricOffsetMs(ttmlContent) | ||
| : 0; | ||
| const sorted = cleanTTMLTranslations(ttmlContent); | ||
| const parsed = parseTTML(sorted); | ||
| const lines = parsed?.lines || []; | ||
| const lines = applyLyricOffsetToLines(parsed?.lines || [], lyricOffsetMs); |
| } catch { | ||
| // 回退使用预加载结果 | ||
| } |