From 60a5847ae68836bbbeef748254c674c81fa5c3ea Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sun, 5 Mar 2023 10:54:31 +0600 Subject: [PATCH] fix(playback): not skipping track's sponsorblock segments --- lib/extensions/video.dart | 2 +- lib/provider/playlist_queue_provider.dart | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/extensions/video.dart b/lib/extensions/video.dart index 36fee1b8c..81d43c87a 100644 --- a/lib/extensions/video.dart +++ b/lib/extensions/video.dart @@ -140,7 +140,7 @@ extension GetSkipSegments on Video { return List.castFrom>([]); } - final data = jsonDecode(res.body); + final data = jsonDecode(res.body) as List; final segments = data.map((obj) { return Map.castFrom({ "start": obj["segment"].first.toInt(), diff --git a/lib/provider/playlist_queue_provider.dart b/lib/provider/playlist_queue_provider.dart index 2a332f929..1a8713464 100644 --- a/lib/provider/playlist_queue_provider.dart +++ b/lib/provider/playlist_queue_provider.dart @@ -188,6 +188,19 @@ class PlaylistQueueNotifier extends PersistedStateNotifier { await linuxService?.player.updateProperties(); final currentDuration = await audioPlayer.getDuration() ?? Duration.zero; + // skip all the activeTrack.skipSegments + if (state?.isLoading != true && + (state?.activeTrack as SpotubeTrack).skipSegments.isNotEmpty && + preferences.skipSponsorSegments) { + for (final segment + in (state!.activeTrack as SpotubeTrack).skipSegments) { + if ((pos.inSeconds >= segment["start"]! && + pos.inSeconds < segment["end"]!)) { + await audioPlayer.seek(Duration(seconds: segment["end"]!)); + } + } + } + // when the track progress is above 80%, track isn't the last // and is not already fetched and nothing is fetching currently if (pos.inSeconds > currentDuration.inSeconds * .8 &&