fix(playback): not skipping track's sponsorblock segments

This commit is contained in:
Kingkor Roy Tirtho 2023-03-05 10:54:31 +06:00
parent 2ebcbc4cea
commit 60a5847ae6
2 changed files with 14 additions and 1 deletions

View File

@ -140,7 +140,7 @@ extension GetSkipSegments on Video {
return List.castFrom<dynamic, Map<String, int>>([]); return List.castFrom<dynamic, Map<String, int>>([]);
} }
final data = jsonDecode(res.body); final data = jsonDecode(res.body) as List;
final segments = data.map((obj) { final segments = data.map((obj) {
return Map.castFrom<String, dynamic, String, int>({ return Map.castFrom<String, dynamic, String, int>({
"start": obj["segment"].first.toInt(), "start": obj["segment"].first.toInt(),

View File

@ -188,6 +188,19 @@ class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {
await linuxService?.player.updateProperties(); await linuxService?.player.updateProperties();
final currentDuration = await audioPlayer.getDuration() ?? Duration.zero; 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 // when the track progress is above 80%, track isn't the last
// and is not already fetched and nothing is fetching currently // and is not already fetched and nothing is fetching currently
if (pos.inSeconds > currentDuration.inSeconds * .8 && if (pos.inSeconds > currentDuration.inSeconds * .8 &&