nico/5-mar-26/fix-musik-fix-apbdes #75

Merged
nicoarya20 merged 8 commits from nico/5-mar-26/fix-musik-fix-apbdes into staggingweb 2026-03-05 16:38:08 +08:00
8 changed files with 170 additions and 32 deletions
Showing only changes of commit ce46d3b5f7 - Show all commits

View File

@@ -82,6 +82,12 @@ export function MusicProvider({ children }: { children: ReactNode }) {
const audioRef = useRef<HTMLAudioElement | null>(null);
const isSeekingRef = useRef(false);
const animationFrameRef = useRef<number | null>(null);
const isRepeatRef = useRef(false); // Ref untuk avoid stale closure
// Sync ref dengan state
useEffect(() => {
isRepeatRef.current = isRepeat;
}, [isRepeat]);
// Load musik data
const loadMusikData = useCallback(async () => {
@@ -111,7 +117,8 @@ export function MusicProvider({ children }: { children: ReactNode }) {
});
audioRef.current.addEventListener('ended', () => {
if (isRepeat) {
// Gunakan ref untuk avoid stale closure
if (isRepeatRef.current) {
audioRef.current!.currentTime = 0;
audioRef.current!.play();
} else {
@@ -132,7 +139,7 @@ export function MusicProvider({ children }: { children: ReactNode }) {
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps -- playNext is intentionally not in deps to avoid circular dependency
}, [loadMusikData, isRepeat]);
}, [loadMusikData]); // Remove isRepeat dari deps karena sudah pakai ref
// Update time with requestAnimationFrame for smooth progress
const updateTime = useCallback(() => {