From 400c950bb79d88bafb6652ae45c0fbb24c844af8 Mon Sep 17 00:00:00 2001 From: raizasafeel <89463672+raizasafeel@users.noreply.github.com> Date: Tue, 24 Mar 2026 15:33:53 +0530 Subject: [PATCH] fix: progress updated on video completion --- frontend/src/pages/Lesson.vue | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/frontend/src/pages/Lesson.vue b/frontend/src/pages/Lesson.vue index 0f3a9856..0f2d8b8a 100644 --- a/frontend/src/pages/Lesson.vue +++ b/frontend/src/pages/Lesson.vue @@ -700,6 +700,31 @@ const updateVideoWatchDuration = () => { } }) } + attachVideoEndedListeners() +} + +const attachVideoEndedListeners = () => { + const onVideoEnded = () => { + markProgress() + trackVideoWatchDuration() + } + + document.querySelectorAll('video').forEach((video) => { + if (!video._lmsEndedAttached) { + video.addEventListener('ended', onVideoEnded) + video._lmsEndedAttached = true + } + }) + + plyrSources.value.forEach((plyrSource) => { + if (!plyrSource._lmsEndedAttached) { + plyrSource.on('ended', onVideoEnded) + plyrSource.on('statechange', (event) => { + if (event.detail?.code === 0) onVideoEnded() + }) + plyrSource._lmsEndedAttached = true + } + }) } const updatePlyrVideoTime = (video) => {