Skip to content

fix(lyrics): 修复AM歌词页跳转行位置的问题#893

Open
laoshuikaixue wants to merge 1 commit intoimsyy:devfrom
laoshuikaixue:patch-1
Open

fix(lyrics): 修复AM歌词页跳转行位置的问题#893
laoshuikaixue wants to merge 1 commit intoimsyy:devfrom
laoshuikaixue:patch-1

Conversation

@laoshuikaixue
Copy link

  • 将 watchEffect 替换为 watch 以更好地控制时间变化响应
  • 添加跳转检测逻辑,当时间变化超过 1000ms 时视为跳转操作
  • 针对 v0.2.0 版本实现临时修复,手动处理跳转时的滚动状态重置
  • 强制重置缓冲行和滚动位置以确保正确的歌词显示
  • 保留非跳转情况下的正常时间设置逻辑

Closed #889

- 将 watchEffect 替换为 watch 以更好地控制时间变化响应
- 添加跳转检测逻辑,当时间变化超过 1000ms 时视为跳转操作
- 针对 v0.2.0 版本实现临时修复,手动处理跳转时的滚动状态重置
- 强制重置缓冲行和滚动位置以确保正确的歌词显示
- 保留非跳转情况下的正常时间设置逻辑
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @laoshuikaixue, 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!

此拉取请求旨在解决 AM 歌词页在播放时间跳转时滚动位置不准确的问题。通过将时间监听器从 watchEffect 更改为 watch,并引入了跳转检测机制,当检测到大幅度时间跳跃时,会手动重置歌词播放器的滚动状态和缓冲行,从而确保歌词在跳转后能够正确显示和同步,尤其修复了特定版本中核心库缺失跳转逻辑的问题。

Highlights

  • 时间监听器优化: 将 watchEffect 替换为 watch,以更好地控制时间变化响应。
  • 跳转检测逻辑: 添加了跳转检测逻辑,当时间变化超过 1000ms 时视为跳转操作。
  • v0.2.0 版本临时修复: 针对 v0.2.0 版本实现了临时修复,手动处理跳转时的滚动状态重置。
  • 强制重置滚动状态: 强制重置缓冲行和滚动位置,以确保正确的歌词显示。
  • 非跳转情况处理: 保留了非跳转情况下的正常时间设置逻辑。
Changelog
  • src/components/AMLL/LyricPlayer.vue
    • currentTime 的监听从 watchEffect 更改为 watch
    • 实现了基于时间差(超过 1000ms)的跳转检测逻辑。
    • 在检测到跳转时,手动调用 player.setCurrentTime(time, true) 并强制清除 bufferedLines,重新计算 scrollToIndex,并调用 player.resetScroll()player.calcLayout() 来重置滚动状态。
    • 在非跳转情况下,保持原有的 playerRef.value?.setCurrentTime(time, false) 逻辑。
Activity
  • 目前没有人类活动。
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 通过将 watchEffect 替换为 watch,并增加了跳转检测逻辑,修复了 AM 歌词页在跳转播放时行位置不正确的问题。这是一个很好的修复,特别是手动处理滚动状态重置的临时方案,解决了核心库的缺陷。

代码整体实现清晰,但有两点可以改进以提高代码质量和可维护性:

  1. 将用于检测跳转的魔术数字 1000 提取为常量。
  2. 避免使用 any 类型,通过定义接口或交叉类型来为临时修复中用到的内部属性提供类型定义,以增强类型安全。

() => props.currentTime,
(time, oldTime) => {
if (time === undefined) return;
const isSeek = oldTime !== undefined && Math.abs(time - oldTime) > 1000;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

为了提高代码的可读性和可维护性,建议将魔术数字 1000 提取为具名常量,例如 SEEK_THRESHOLD_MS。你可以在 <script setup> 的顶部定义 const SEEK_THRESHOLD_MS = 1000;,然后在此处使用该常量。

Comment on lines +296 to +311
const player = playerRef.value as any;
if (player) {
player.setCurrentTime(time, true);

// 强制重置缓冲行和滚动位置
if (player.bufferedLines && player.hotLines && player.processedLines) {
player.bufferedLines.clear();
for (const v of player.hotLines) {
player.bufferedLines.add(v);
}

if (player.bufferedLines.size > 0) {
player.scrollToIndex = Math.min(...player.bufferedLines);
} else {
const foundIndex = player.processedLines.findIndex(
(line: any) => line.startTime >= time
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

在多处使用了 as any (L296) 和 (line: any) (L311),这会完全绕过 TypeScript 的类型检查,降低代码的可维护性。虽然注释说明这是临时修复,但最好还是提供一个更具体的类型。

建议在组件顶部定义一个接口来描述这些额外的属性,例如:

interface PatchedLyricPlayer extends CoreLyricPlayer {
  bufferedLines: Set<number>;
  hotLines: Set<number>;
  processedLines: (LyricLine & { startTime: number })[];
  scrollToIndex: number;
  resetScroll: () => void;
  calcLayout: () => void;
}

然后使用 const player = playerRef.value as PatchedLyricPlayer。这能增强类型安全,并能移除对 (line: any) 的需要,让 TypeScript 正确推断 line 的类型。

@laoshuikaixue
Copy link
Author

laoshuikaixue commented Feb 16, 2026

现在是针对npm未发版的解决方案,后续npm更新修复了内部的 Seek 逻辑后,可以移除本 PR 中 if (isSeek) { ... } 块内的手动重置逻辑,直接调用 playerRef.value?.setCurrentTime(time, isSeek) 即可

@laoshuikaixue
Copy link
Author

2026-02-16.19-58-05.mp4

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.

[BUG]: 使用Apple Music-like Lyrics 点击歌词跳转后没有定位到正确的位置

1 participant

Comments