Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -997,15 +997,16 @@ private void triggerCheckForSponsorBlockSegments(final int currentProgress,

// show/hide manual skip buttons
if (showManualButtons && secondaryMode != SponsorBlockSecondaryMode.HIGHLIGHT) {
if (currentProgress < sponsorBlockSegment.endTime
&& currentProgress > sponsorBlockSegment.startTime) {
if (currentProgress < getChainSkipEndTime(sponsorBlockSegment)
&& currentProgress > getChainStartTime(sponsorBlockSegment)) {
UIs.call(PlayerUi::showAutoSkip);
} else {
UIs.call(PlayerUi::hideAutoSkip);
}

if (currentProgress > sponsorBlockSegment.startTime
&& currentProgress < sponsorBlockSegment.endTime + UNSKIP_WINDOW_MILLIS) {
if (currentProgress > getChainStartTime(sponsorBlockSegment)
&& currentProgress < getChainSkipEndTime(sponsorBlockSegment)
+ UNSKIP_WINDOW_MILLIS) {
UIs.call(PlayerUi::showAutoUnskip);
} else {
UIs.call(PlayerUi::hideAutoUnskip);
Expand Down Expand Up @@ -1041,8 +1042,8 @@ private void triggerCheckForSponsorBlockSegments(final int currentProgress,
}

int skipTarget = isRewind
? (int) Math.ceil((sponsorBlockSegment.startTime)) - 1
: (int) Math.ceil((sponsorBlockSegment.endTime));
? (int) Math.ceil(getChainStartTime(sponsorBlockSegment)) - 1
: (int) Math.ceil(getChainSkipEndTime(sponsorBlockSegment));

if (skipTarget < 0) {
skipTarget = 0;
Expand Down Expand Up @@ -2489,11 +2490,11 @@ public Optional<SponsorBlockSegment> getSkippableSponsorBlockSegment(final int p
continue;
}

if (progress < sponsorBlockSegment.startTime) {
if (progress < getChainStartTime(sponsorBlockSegment)) {
continue;
}

if (progress > sponsorBlockSegment.endTime) {
if (progress > getChainSkipEndTime(sponsorBlockSegment)) {
continue;
}

Expand All @@ -2502,13 +2503,13 @@ public Optional<SponsorBlockSegment> getSkippableSponsorBlockSegment(final int p

// fallback on old SponsorBlockSegment (for un-skip)
if (lastSegment != null
&& progress > lastSegment.endTime + UNSKIP_WINDOW_MILLIS) {
&& progress > getChainSkipEndTime(lastSegment) + UNSKIP_WINDOW_MILLIS) {
// un-skip window is over
hideUnskipButtons();
destroyUnskipVars();
} else if (lastSegment != null
&& progress < lastSegment.endTime + UNSKIP_WINDOW_MILLIS
&& progress >= lastSegment.startTime) {
&& progress < getChainSkipEndTime(lastSegment) + UNSKIP_WINDOW_MILLIS
&& progress >= getChainStartTime(lastSegment)) {
// use old sponsorBlockSegment if exists AND currentProgress in bounds
return lastSegment;
}
Expand All @@ -2518,6 +2519,36 @@ public Optional<SponsorBlockSegment> getSkippableSponsorBlockSegment(final int p
});
}

public double getChainStartTime(final SponsorBlockSegment segment) {
if (segment.chain.isEmpty()) {
return segment.startTime;
} else {
for (int i = segment.chain.indexOf(segment) - 1; i >= 0; i--) {
// look for automatically skipped segments before this one
if (segment.chain.get(i).action != SponsorBlockAction.SKIP
|| getSecondaryMode(segment) != SponsorBlockSecondaryMode.ENABLED) {
return segment.chain.get(i + 1).endTime;
}
}
return segment.chain.get(0).startTime;
}
}

public double getChainSkipEndTime(final SponsorBlockSegment segment) {
if (segment.chain.isEmpty()) {
return segment.endTime;
} else {
for (int i = segment.chain.indexOf(segment) + 1; i < segment.chain.size(); i++) {
// look for automatically skipped segments after this one
if (segment.chain.get(i).action != SponsorBlockAction.SKIP
|| getSecondaryMode(segment) != SponsorBlockSecondaryMode.ENABLED) {
return segment.chain.get(i - 1).endTime;
}
}
return segment.chain.get(segment.chain.size() - 1).endTime;
}
}

private void hideUnskipButtons() {
if (DEBUG) {
Log.d("SPONSOR_BLOCK", "Hiding manual skip buttons (UNSKIP)");
Expand Down
Loading