Skip to content

Commit

Permalink
Revert "adding fading option"
Browse files Browse the repository at this point in the history
This reverts commit a797f14.

Conflicts:
	assets/js/seeking.js
  • Loading branch information
Tweoss committed Jul 16, 2022
1 parent 4ee143e commit 0726d49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 57 deletions.
66 changes: 10 additions & 56 deletions assets/js/seeking.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ var player,
// current repeat
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,
// whether or not to fade between jumps
fade_between_jumps = false,
// if currently doing a fade in and out, don't try to do another fade
doing_fade = false;
segment_jumped = false;

function onYouTubeIframeAPIReady() {
player = new YT.Player('video-div', {
Expand Down Expand Up @@ -111,9 +107,6 @@ function onPlayerReady(pEvent) {
document.getElementById("jumpNext").addEventListener("input", function(e) {
jump_next = e.target.checked;
});
document.getElementById("fadeVolume").addEventListener("input", function(e) {
fade_between_jumps = e.target.checked;
});
})
}

Expand Down Expand Up @@ -152,55 +145,22 @@ function searchAndHighlight() {
return;
}
// jump to the start for repeat
else if (seconds > current_segment.end && seconds < current_segment.end + 1 && current_repeat < repeat_count) {
else if (seconds > current_segment.end && seconds < current_segment.end + 2 && current_repeat < repeat_count) {
current_repeat++;
player.seekTo(current_segment.start, true);
const bar = document.querySelector("#repeatProgress > div");
bar.style.width = `${current_repeat * 100 / repeat_count}%`;
bar.textContent = `${current_repeat}/${repeat_count}`;
}
// jump to the next segment
else if (seconds > current_segment.end && seconds < current_segment.end + 1 && jump_next && time_object[current_index + 1]) {
const seconds_to_fade = 0.5;
if (fade_between_jumps) {
let set_volume = player.getVolume(),
running_volume = set_volume,
volume_interval = 5,
is_decreasing = true;
// fade out and in
if (!doing_fade) {
doing_fade = true;
let interval = immediateInterval(() => {
if (is_decreasing) {
running_volume -= volume_interval;
if (running_volume <= 0) {
is_decreasing = false;
running_volume = 0;
}
} else {
running_volume += volume_interval;
if (running_volume >= set_volume) {
clearInterval(interval);
doing_fade = false;
running_volume = set_volume;
}
}
console.log(running_volume, is_decreasing);
player.setVolume(running_volume);
}, 1000 * 2 * seconds_to_fade * volume_interval / set_volume);
}
}

// set the time after the fade out or run immediately if not fading
setTimeout(function() {
player.seekTo(timeToSeconds(time_object[current_index + 1].start) - buffer_size, true);
current_segment = { start: timeToSeconds(time_object[current_index + 1].start) - buffer_size, end: timeToSeconds(time_object[current_index + 1].end) + buffer_size };
// give priority to this segment
current_index = current_index + 1;
current_repeat = 0;
segment_jumped = true;
resetBars();
}, fade_between_jumps ? seconds_to_fade * 1000 : 0);
else if (seconds > current_segment.end && seconds < current_segment.end + 2 && jump_next) {
player.seekTo(timeToSeconds(time_object[current_index + 1].start) - buffer_size, true);
current_segment = { start: timeToSeconds(time_object[current_index + 1].start) - buffer_size, end: timeToSeconds(time_object[current_index + 1].end) + buffer_size };
// give priority to this segment
current_index = current_index + 1;
current_repeat = 0;
segment_jumped = true;
resetBars();
}
// main logic to find and set segments, color, and set progress bars
else {
Expand Down Expand Up @@ -287,9 +247,3 @@ function resetBars() {
repeatBar.style.width = '0%';
repeatBar.textContent = `0/${repeat_count}`;
}

// immediately executes the function, then sets the interval
function immediateInterval(func, interval) {
func();
return setInterval(func, interval);
}
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ <h1 class="text-center text-light">Youtube Times</h1>
<div class="progress" data-bss-hover-animate="rubberBand" id="repeatProgress" style="color: var(--bs-white);">
<div class="progress-bar progress-bar-striped progress-bar-animated" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">0%</div>
</div>
<div class="form-check"><input class="form-check-input" type="checkbox" id="fadeVolume"><label class="form-check-label" for="formCheck-1">Fade Volume when Jumping</label></div>
</div>
<div class="col-4"><label class="form-label"><span>Time Buffer:&nbsp;</span><span id="timeBufferText">0</span><span>&nbsp;seconds</span></label><input class="form-range form-control" type="range" id="bufferSize" value="0" min="0" max="60" step="1">
<div class="progress" data-bss-hover-animate="rubberBand" id="timeProgress" style="color: white;">
Expand Down

0 comments on commit 0726d49

Please sign in to comment.