fix: update PlaySlide info after song's change#159
Conversation
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Walkthrough该改动修改了 Changes
Sequence DiagramsequenceDiagram
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)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
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 })
| const fetchProgress = () => { | ||
| void Promise.all([ | ||
| Orpheus.getPosition(), | ||
| Orpheus.getDuration(), | ||
| Orpheus.getBuffered(), | ||
| ]).then(([pos, dur, buf]) => { | ||
| position.set(pos) | ||
| duration.set(dur) | ||
| buffered.set(buf) | ||
| }) | ||
| } |
There was a problem hiding this comment.
缺少 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.
| 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.
|
感谢贡献! |
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)
一个小 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.