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 &&