Skip to content

Commit 2566743

Browse files
authored
Merge pull request #7395 from Bnyro/master
fix: SponsorBlock segments skipped even if temporarily allowed
2 parents 11704a0 + f4e69ac commit 2566743

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ object PlayerHelper {
510510
* Create a basic player, that is used for all types of playback situations inside the app
511511
*/
512512
@OptIn(androidx.media3.common.util.UnstableApi::class)
513-
fun createPlayer(context: Context, trackSelector: DefaultTrackSelector, ): ExoPlayer {
513+
fun createPlayer(context: Context, trackSelector: DefaultTrackSelector): ExoPlayer {
514514
val dataSourceFactory = DefaultDataSource.Factory(context)
515515
val audioAttributes = AudioAttributes.Builder()
516516
.setUsage(C.USAGE_MEDIA)
@@ -589,7 +589,7 @@ object PlayerHelper {
589589
* @param segments List of the SponsorBlock segments
590590
* @return If segment found and should skip manually, the end position of the segment in ms, otherwise null
591591
*/
592-
fun Player.checkForSegments(
592+
fun Player.getCurrentSegment(
593593
segments: List<Segment>,
594594
sponsorBlockConfig: MutableMap<String, SbSkipOptions>,
595595
): Pair<Segment, SbSkipOptions>? {
@@ -610,14 +610,6 @@ object PlayerHelper {
610610
return null
611611
}
612612

613-
fun Player.isInSegment(segments: List<Segment>): Boolean {
614-
return segments.any {
615-
val (start, end) = it.segmentStartAndEnd
616-
val (segmentStart, segmentEnd) = (start * 1000f).toLong() to (end * 1000f).toLong()
617-
currentPosition in segmentStart..segmentEnd
618-
}
619-
}
620-
621613
/**
622614
* Get the name of the currently played chapter
623615
*/

app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import com.github.libretube.extensions.toastFromMainDispatcher
2828
import com.github.libretube.extensions.toastFromMainThread
2929
import com.github.libretube.extensions.updateParameters
3030
import com.github.libretube.helpers.PlayerHelper
31-
import com.github.libretube.helpers.PlayerHelper.checkForSegments
31+
import com.github.libretube.helpers.PlayerHelper.getCurrentSegment
3232
import com.github.libretube.helpers.PlayerHelper.getSubtitleRoleFlags
3333
import com.github.libretube.helpers.PreferenceHelper
3434
import com.github.libretube.helpers.ProxyHelper
@@ -236,12 +236,12 @@ open class OnlinePlayerService : AbstractPlayerService() {
236236
private fun checkForSegments() {
237237
handler.postDelayed(this::checkForSegments, 100)
238238

239-
val (currentSegment, sbSkipOption) = exoPlayer?.checkForSegments(
239+
val (currentSegment, sbSkipOption) = exoPlayer?.getCurrentSegment(
240240
sponsorBlockSegments,
241241
sponsorBlockConfig
242242
) ?: return
243243

244-
if (sbSkipOption in arrayOf(SbSkipOptions.AUTOMATIC, SbSkipOptions.AUTOMATIC_ONCE)) {
244+
if (sbSkipOption in arrayOf(SbSkipOptions.AUTOMATIC, SbSkipOptions.AUTOMATIC_ONCE) && sponsorBlockAutoSkip) {
245245
exoPlayer?.seekTo(currentSegment.segmentStartAndEnd.second.toLong() * 1000)
246246
currentSegment.skipped = true
247247

app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ import com.github.libretube.helpers.IntentHelper
7878
import com.github.libretube.helpers.NavBarHelper
7979
import com.github.libretube.helpers.NavigationHelper
8080
import com.github.libretube.helpers.PlayerHelper
81-
import com.github.libretube.helpers.PlayerHelper.checkForSegments
82-
import com.github.libretube.helpers.PlayerHelper.isInSegment
81+
import com.github.libretube.helpers.PlayerHelper.getCurrentSegment
8382
import com.github.libretube.helpers.PreferenceHelper
8483
import com.github.libretube.helpers.ProxyHelper
8584
import com.github.libretube.helpers.ThemeHelper
@@ -1007,23 +1006,29 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
10071006
handler.postDelayed(this::checkForSegments, 100)
10081007
if (viewModel.segments.value.isNullOrEmpty()) return
10091008

1010-
playerController.checkForSegments(
1009+
val segmentData = playerController.getCurrentSegment(
10111010
viewModel.segments.value.orEmpty(),
10121011
viewModel.sponsorBlockConfig
1013-
)?.let { (segment, sbSkipOption) ->
1014-
if (commonPlayerViewModel.isMiniPlayerVisible.value == true) return@let
1012+
)
1013+
1014+
if (segmentData != null && commonPlayerViewModel.isMiniPlayerVisible.value != true) {
1015+
val (segment, sbSkipOption) = segmentData
10151016

1016-
if (sbSkipOption in arrayOf(SbSkipOptions.AUTOMATIC_ONCE, SbSkipOptions.MANUAL)) {
1017+
val autoSkipTemporarilyDisabled = !binding.player.sponsorBlockAutoSkip &&
1018+
sbSkipOption !in arrayOf(SbSkipOptions.OFF, SbSkipOptions.VISIBLE)
1019+
1020+
if (sbSkipOption in arrayOf(
1021+
SbSkipOptions.AUTOMATIC_ONCE,
1022+
SbSkipOptions.MANUAL
1023+
) || autoSkipTemporarilyDisabled
1024+
) {
10171025
binding.sbSkipBtn.isVisible = true
10181026
binding.sbSkipBtn.setOnClickListener {
10191027
playerController.seekTo((segment.segmentStartAndEnd.second * 1000f).toLong())
10201028
segment.skipped = true
10211029
}
10221030
}
1023-
return
1024-
}
1025-
1026-
if (!playerController.isInSegment(viewModel.segments.value.orEmpty())) {
1031+
} else {
10271032
binding.sbSkipBtn.isGone = true
10281033
}
10291034
}

app/src/main/java/com/github/libretube/ui/views/OnlinePlayerView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class OnlinePlayerView(
5252
var currentWindow: Window? = null
5353

5454
var selectedResolution: Int? = null
55-
private var sponsorBlockAutoSkip = true
55+
var sponsorBlockAutoSkip = true
5656

5757
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
5858
override fun getOptionsMenuItems(): List<BottomSheetItem> {

0 commit comments

Comments
 (0)