Fix "Lanjutkan" resume button to jump to saved position

- Change jumpToTime to check video.seekable instead of adiloPlayer.isReady
- Wait for canplay event if video is not seekable yet
- This fixes issue where resume button started from 00:00 instead of saved position
- Added better console logging for debugging

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-01-04 11:56:12 +07:00
parent 8fc31b402d
commit 71d6da4530

View File

@@ -229,25 +229,36 @@ export const VideoPlayerWithChapters = forwardRef<VideoPlayerRef, VideoPlayerWit
}, [isYouTube, findCurrentChapter, onChapterChange, onTimeUpdate, chapters, saveProgressDebounced]);
// Jump to specific time using Plyr API or Adilo player
const jumpToTime = (time: number) => {
const jumpToTime = useCallback((time: number) => {
if (isAdilo) {
const video = adiloPlayer.videoRef.current;
if (video && adiloPlayer.isReady) {
if (!video) {
console.warn('Video element not available for jump');
return;
}
// Try to jump immediately if video is seekable
if (video.seekable && video.seekable.length > 0) {
console.log(`🎯 Jumping to ${time}s (video seekable)`);
video.currentTime = time;
const wasPlaying = !video.paused;
if (wasPlaying) {
video.play().catch((err) => {
if (err.name !== 'AbortError') {
console.error('Jump failed:', err);
}
});
}
} else {
// Video not seekable yet, wait for it to be ready
console.log(`⏳ Video not seekable yet, waiting to jump to ${time}s`);
const onCanPlay = () => {
console.log(`🎯 Video seekable now, jumping to ${time}s`);
video.currentTime = time;
video.removeEventListener('canplay', onCanPlay);
};
video.addEventListener('canplay', onCanPlay, { once: true });
}
} else if (playerInstance) {
playerInstance.currentTime = time;
playerInstance.play();
}
};
}, [isAdilo, adiloPlayer.videoRef, playerInstance]);
const getCurrentTime = () => {
return currentTime;