Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : implement binary search for quick subtitle navigation #46

Merged
merged 6 commits into from
Dec 2, 2024

Conversation

smosco
Copy link
Owner

@smosco smosco commented Dec 2, 2024

📄 Description of the PR

🔧 What has been changed?

  • Binary Search: Implemented binary search to quickly find the current subtitle, reducing buffering when navigating.
  • Smooth Time Updates: Used requestAnimationFrame to update the current playback time smoothly, ensuring synchronization with the browser's refresh rate.
  • Focus Button Fix: Resolved the focus button click issue by using React.cloneElement to properly attach the click handler.

📸 Screenshots / GIFs (if applicable)

before
https://github.com/user-attachments/assets/ff084002-3d90-4fc7-aee5-fd61a70f3e29

after
https://github.com/user-attachments/assets/4ced8993-c771-4cb4-afe6-c573843fea18

Subtitle Player Screenshot

⚠️ Precaution & Known Issues

✅ Checklist

  • Confirm with the UI branch for visual issues.
  • Verify function and variable names are descriptive.

이 PR은 주요 변경 사항을 간결하게 요약하여 팀원이 쉽게 이해할 수 있도록 작성되었습니다.

@smosco smosco requested a review from godhyzzang December 2, 2024 07:54
@smosco smosco self-assigned this Dec 2, 2024
@smosco smosco linked an issue Dec 2, 2024 that may be closed by this pull request
3 tasks
Copy link

vercel bot commented Dec 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-player-plugin-prompter-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 2, 2024 7:54am

Copy link
Collaborator

@godhyzzang godhyzzang left a comment

Choose a reason for hiding this comment

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

Good. Two things that Figuring out why only cloneElement works t and covert focusButton to props are left are our next goal before deployment.

Comment on lines +17 to 22
isFocused,
setIsFocused,
}: {
isFocus: boolean;
setIsFocus: React.Dispatch<React.SetStateAction<boolean>>;
isFocused: boolean;
setIsFocused: React.Dispatch<React.SetStateAction<boolean>>;
}) => JSX.Element;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of passing the focus button itself, it would be better to pass isFocus and setIsFocused as props. I'll try later.

Comment on lines +32 to +37
const seekTo = (timeInSeconds: number) => {
setIsSeeking(true);
playerRef.current?.seekTo(timeInSeconds, 'seconds');

setTimeout(() => setIsSeeking(false), 50);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like setIsSeeking functions similarly to the focus functionality of the focusButton. Although the focus attribute is only visible in blockview, it overlaps with setIsSeeking, so it would be better to manage them together.

Copy link
Owner Author

Choose a reason for hiding this comment

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

great idea!

volume={volume}
controls={false}
playbackRate={playbackRate}
progressInterval={1000}
onSeek={(seconds) => setCurrentTime(seconds)} // 사용자가 직접 탐색할 때 호출되어 현재 시간 업데이트
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I thought the only way to find subtitles was to use progressInterval, which causes un-necessary re-rendefing at least every second, but it seems I've found a way to solve that.👍

Comment on lines +54 to +68
useEffect(() => {
let animationFrameId: number;

const updateTime = () => {
if (playerRef.current && !isSeeking) {
setCurrentTime(playerRef.current.getCurrentTime() || 0);
}
animationFrameId = requestAnimationFrame(updateTime);
};

animationFrameId = requestAnimationFrame(updateTime);

return () => cancelAnimationFrame(animationFrameId);
}, [isSeeking]);

Copy link
Collaborator

Choose a reason for hiding this comment

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

wow, there's a way to smoothing animation behaviors. Good

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is my first time implementing this concept. It seems to bring a slight performance improvement for navigating subtitles.

@smosco smosco merged commit c87224e into develop Dec 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fix] subtitle skip buttons are not clickable
2 participants