Skip to content

Commit

Permalink
fix(playback): not skipping track's sponsorblock segments
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Mar 5, 2023
1 parent 2ebcbc4 commit 60a5847
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/extensions/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ extension GetSkipSegments on Video {
return List.castFrom<dynamic, Map<String, int>>([]);
}

final data = jsonDecode(res.body);
final data = jsonDecode(res.body) as List;
final segments = data.map((obj) {
return Map.castFrom<String, dynamic, String, int>({
"start": obj["segment"].first.toInt(),
Expand Down
13 changes: 13 additions & 0 deletions lib/provider/playlist_queue_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {
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 &&
Expand Down

0 comments on commit 60a5847

Please sign in to comment.