Skip to content

fix: update PlaySlide info after song's change#159

Merged
roitium merged 1 commit into
bbplayer-app:devfrom
longlin10086:dev
Jan 24, 2026
Merged

fix: update PlaySlide info after song's change#159
roitium merged 1 commit into
bbplayer-app:devfrom
longlin10086:dev

Conversation

@longlin10086
Copy link
Copy Markdown
Contributor

@longlin10086 longlin10086 commented Jan 24, 2026

一个小 bug,暂停状态下切换歌曲时进度条不会更新,新增了一个事件监听器。

修复前:

2026-01-24.17.47.27.mp4

修复后:

2026-01-24.17.47.31.mp4

Summary by CodeRabbit

发布说明

  • 改进
    • 优化了播放器进度跟踪机制,确保在开始播放新曲目时准确更新进度信息。

✏️ Tip: You can customize this high-level summary in your review settings.

@safedep
Copy link
Copy Markdown

safedep Bot commented Jan 24, 2026

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

This report is generated by SafeDep Github App

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 24, 2026

Walkthrough

该改动修改了useAnimatedTrackProgress钩子中播放器进度数据的获取机制。引入异步fetchProgress函数在组件挂载时初始化状态,并为音轨开始事件添加监听器以动态刷新进度数据,同时在卸载时清理监听器。

Changes

Cohort / File(s) 变更摘要
播放进度数据获取工作流
src/hooks/player/useAnimatedTrackProgress.ts
引入异步fetchProgress函数获取position、duration和buffered,在组件挂载时调用以初始化状态。新增onTrackStarted事件监听器通过Orpheus.addListener,在音轨开始时重新获取进度数据。实现卸载时的listener清理逻辑。将之前的一次性Promise.all替换为事件驱动的持续更新机制。

Sequence Diagram

sequenceDiagram
    participant Component as useAnimatedTrackProgress Hook
    participant Orpheus as Orpheus Player
    participant SharedValues as Shared Values
    
    Component->>Component: Component Mount
    Component->>Component: Define fetchProgress function
    Component->>Orpheus: getPosition()
    Orpheus-->>Component: position
    Component->>Orpheus: getDuration()
    Orpheus-->>Component: duration
    Component->>Orpheus: getBuffered()
    Orpheus-->>Component: buffered
    Component->>SharedValues: Update position, duration, buffered
    
    Component->>Orpheus: addListener(onTrackStarted)
    Orpheus-->>Component: listener subscription
    
    Orpheus->>Component: onTrackStarted event
    Component->>Orpheus: getPosition()
    Orpheus-->>Component: position
    Component->>Orpheus: getDuration()
    Orpheus-->>Component: duration
    Component->>Orpheus: getBuffered()
    Orpheus-->>Component: buffered
    Component->>SharedValues: Update position, duration, buffered
    
    Component->>Component: Component Unmount
    Component->>Orpheus: Remove listener (trackStartedSub)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 轨迹在更新,事件来驱动,
音轨启程时,进度数据刷新。
挂载与卸载,生命周期舞蹈,
Orpheus引领,听,播放之音! 🎵

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确地反映了主要变更:修复了在暂停播放时切换歌曲后进度条不更新的问题。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/hooks/player/useAnimatedTrackProgress.ts`:
- Around line 40-50: fetchProgress in useAnimatedTrackProgress calls Promise.all
on Orpheus.getPosition/getDuration/getBuffered without error handling; add a
.catch handler to the Promise chain that logs the error (or reports it to your
logger) and optionally resets/guards position.set, duration.set, buffered.set to
safe defaults so stale data isn’t shown if any call fails.
🧹 Nitpick comments (1)
src/hooks/player/useAnimatedTrackProgress.ts (1)

46-48: SharedValue 更新方式不一致

此处使用 .set() 方法更新 shared values,而第一个 useEffect(28-30 行)使用 .value = 赋值。两种方式在 react-native-reanimated 中都有效,但建议在同一文件内保持一致。

♻️ 统一使用 `.value =` 赋值
   ]).then(([pos, dur, buf]) => {
-    position.set(pos)
-    duration.set(dur)
-    buffered.set(buf)
+    position.value = pos
+    duration.value = dur
+    buffered.value = buf
   })

Comment on lines +40 to +50
const fetchProgress = () => {
void Promise.all([
Orpheus.getPosition(),
Orpheus.getDuration(),
Orpheus.getBuffered(),
]).then(([pos, dur, buf]) => {
position.set(pos)
duration.set(dur)
buffered.set(buf)
})
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

缺少 Promise 错误处理

Promise.all 链没有 .catch() 处理器。如果 Orpheus.getPosition()getDuration()getBuffered() 任一方法失败(例如,没有加载曲目时),错误会被静默吞掉,UI 可能显示过期/不正确的进度数据。

🔧 建议添加错误处理
 const fetchProgress = () => {
   void Promise.all([
     Orpheus.getPosition(),
     Orpheus.getDuration(),
     Orpheus.getBuffered(),
   ]).then(([pos, dur, buf]) => {
     position.set(pos)
     duration.set(dur)
     buffered.set(buf)
+  }).catch((error) => {
+    console.warn('Failed to fetch progress:', error)
   })
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const fetchProgress = () => {
void Promise.all([
Orpheus.getPosition(),
Orpheus.getDuration(),
Orpheus.getBuffered(),
]).then(([pos, dur, buf]) => {
position.set(pos)
duration.set(dur)
buffered.set(buf)
})
}
const fetchProgress = () => {
void Promise.all([
Orpheus.getPosition(),
Orpheus.getDuration(),
Orpheus.getBuffered(),
]).then(([pos, dur, buf]) => {
position.set(pos)
duration.set(dur)
buffered.set(buf)
}).catch((error) => {
console.warn('Failed to fetch progress:', error)
})
}
🤖 Prompt for AI Agents
In `@src/hooks/player/useAnimatedTrackProgress.ts` around lines 40 - 50,
fetchProgress in useAnimatedTrackProgress calls Promise.all on
Orpheus.getPosition/getDuration/getBuffered without error handling; add a .catch
handler to the Promise chain that logs the error (or reports it to your logger)
and optionally resets/guards position.set, duration.set, buffered.set to safe
defaults so stale data isn’t shown if any call fails.

@roitium
Copy link
Copy Markdown
Collaborator

roitium commented Jan 24, 2026

感谢贡献!

@roitium roitium merged commit 8aac622 into bbplayer-app:dev Jan 24, 2026
4 checks passed
roitium added a commit that referenced this pull request Jan 25, 2026
Co-authored-by: roitium <roitium@users.noreply.github.com>
Co-authored-by: Roitium. <65794453+roitium@users.noreply.github.com>
Co-authored-by: longlin li <gnulonglin@gmail.com>
fix: prevent progress bar regression & add debounce to PlayButton (#153)
fix: improve error message for failed lyric providers (BBPLAYER-5Q) (#157)
fix: update PlaySlide info after song's change (#159)
fix: prevent re-playing when click same track. (#168)
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.

2 participants