Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Tweoss committed Aug 3, 2021
1 parent 30cb7c8 commit 7dc37ed
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions assets/js/seeking.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ var player,
// current index, used to check if segment needs to be updated
current_index = 0,
// current repeat
current_repeat = 0;
current_repeat = 0,
// whether or not a segment was recently jumped to. this allows for coloring while overriding the normal search order
segment_jumped = false;

function onYouTubeIframeAPIReady() {
player = new YT.Player('video-div', {
Expand All @@ -48,9 +50,11 @@ function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED || event.data == YT.PlayerState.PAUSED) {
// if the video is stopped, we need to stop the interval
clearInterval(edge_interval);
console.info("video stopped");
} else if (event.data == YT.PlayerState.PLAYING) {
// if the video is playing, we need to start the interval
edge_interval = setInterval(searchAndHighlight, 500);
console.info("video started");
}
}

Expand Down Expand Up @@ -112,6 +116,11 @@ function rewriteStamps() {
return timeToSeconds(s);
})
player.seekTo(times[0] - buffer_size, true);
// give priority to this segment
current_segment = { start: times[0] - buffer_size, end: times[1] - buffer_size };
current_index = index;
current_repeat = 0;
segment_jumped = true;
player.playVideo();
// youtube slow to update currentTime, so we must need to wait a bit. also don't want to wait half a second for the interval
setTimeout(function() {
Expand All @@ -125,7 +134,7 @@ function rewriteStamps() {
// sets a timeout for when to call again, sets current_segment, current_repeat, current_index
function searchAndHighlight() {
const seconds = player.getCurrentTime();
if (seconds >= current_segment.start && seconds <= current_segment.end) {
if (!segment_jumped && seconds >= current_segment.start && seconds <= current_segment.end) {
console.log("doing nothing", seconds, current_segment);
return;
// } else if (seconds > current_segment.end && seconds < current_segment.end + 2 && current_repeat < repeat_count) {
Expand All @@ -135,6 +144,13 @@ function searchAndHighlight() {

let [index, closest_start] = findContains(time_object, seconds, buffer_size);

// if the segment was recently jumped to, then there is no need to search
if (segment_jumped) {
segment_jumped = false;
index = current_index;
}


document.querySelectorAll("#table-body > tr").forEach(function(row, i) {
if (i != index) {
row.classList.remove("table-success");
Expand Down

0 comments on commit 7dc37ed

Please sign in to comment.