-
Notifications
You must be signed in to change notification settings - Fork 41
Issue#109: Keep the time of a video when switching to questions and back #289
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have noticed that a few errors have sneaked into your code. 🧐
-
you wrote:
if (currentVideoTime < 0) ~than save videoID~
This must be the other way around. You have to replace the less-than sign with a greater-than sign. -
you called the function
removeItem. In my opinion, this function does not exist. And if it did exist, shouldn't there be brackets?
I have written your code a little cleaner and renamed a few variables. Could you perhaps adopt these changes and, above all, understand them? I am looking forward to your opinion. 😊
(unfortunately I don't have the rights to edit your PR directly :-)
Changes
// ...
<video
v-else-if="activeLecture.type == 'mp4'"
:poster="course.image"
controls
playsInline
title="video player"
allowfullscreen
controlsList="nodownload"
oncontextmenu="return false;"
:key="`video-${activeLecture.id}`"
@timeupdate="onTimeUpdate(activeLecture.id, $event)"
@loadstart="onVideoLoad(activeLecture.id, $event)"
>
// ...
// ...
function onTimeUpdate(videoID: string, event: any) {
const videoCookie = useCookie("currentVideo");
const timeCookie = useCookie("currentVideoTime");
const currentVideoTime = event.target.currentTime;
timeCookie.value = currentVideoTime;
if (currentVideoTime > 0) videoCookie.value = videoID;
}
function onVideoLoad(videoID: string, event: any) {
const videoCookie = useCookie("currentVideo");
const timeCookie = useCookie("currentVideoTime");
if (!videoCookie || videoCookie.value == "" || !timeCookie || timeCookie.value == "") return;
if (videoCookie.value !== videoID) {
videoCookie.value = "";
timeCookie.value = "";
return;
}
event.target.currentTime = timeCookie.value;
}
return { videoSRC, refSource, onTimeUpdate, onVideoLoad };
// ...
|
Thank you for the suggestions. :)
Your Code looks far more readable and I couldn't find any problems with it, so I adopted it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have the rights to merge your code, but @Defelo can.
|
It looks like the issue is with the logic in the Here’s what happens in your code:
SolutionTo avoid this, you can reset the
Updated Codefunction onVideoLoad(videoID: string, event: any) {
const videoCookie = useCookie("currentVideo");
const timeCookie = useCookie("currentVideoTime");
if (!videoCookie || videoCookie.value === "" || !timeCookie || timeCookie.value === "") return;
if (videoCookie.value !== videoID) {
// Reset the time cookie to start the new video from the beginning
timeCookie.value = 0;
videoCookie.value = videoID;
} else {
// Set the current video time to the saved cookie value
event.target.currentTime = timeCookie.value;
}
}This adjustment should ensure that only if the video ID matches the previously saved video, it will use the |
91e1892 to
6ed5bb7
Compare
|
Well, this was a mistake, I'll correct that. |
|
Thanks for the suggestions and explanations. I have implemented the updated Code, but I have accidentally force-synced the develop branch with the official develop branch, which lead to this chaos here, sorry. :( |
|
hm, that didnt fix it sadly. Everything works, except for one thing: |
forgot 1 line
|
I think the problem is because i forgot to restore the "key" line. I hope that fixed it now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please first make sure that all checks were successful, which is not the case here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for final review from @Defelo
|
Preview deployed to https://e1927485.academy-preview.pages.dev (total size: 14M) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, tests went well, code approved from my end :)
Description
Added code to keep the current time of a selfhosted video when switching to questions and back. This was resolved by saving the currenttime and currentvideoID as a cookie and comparing if the saved ID is the same as the ID of the playing Video before setting the time of the video to the stored value.
Type of change
Fixes Bootstrap-Academy/Bootstrap-Academy#109
My Bootstrap Academy username: R4bbit