mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
support for presearch next track
lowers the track change latency
This commit is contained in:
parent
1271a09e00
commit
68b440920c
@ -54,8 +54,8 @@ void useUpdateChecker(WidgetRef ref) {
|
|||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
final url =
|
const url =
|
||||||
"https://github.com/KRTirtho/spotube/releases/tag/v${value.last}";
|
"https://spotube.netlify.app/other-downloads/stable-downloads";
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text("Spotube has an update"),
|
title: const Text("Spotube has an update"),
|
||||||
actions: [
|
actions: [
|
||||||
|
@ -58,6 +58,8 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
// internal stuff
|
// internal stuff
|
||||||
final List<StreamSubscription> _subscriptions;
|
final List<StreamSubscription> _subscriptions;
|
||||||
final _logger = getLogger(Playback);
|
final _logger = getLogger(Playback);
|
||||||
|
// state of preSearch used inside [onPositionChanged]
|
||||||
|
bool _isPreSearching = false;
|
||||||
|
|
||||||
PlaybackStatus status;
|
PlaybackStatus status;
|
||||||
|
|
||||||
@ -110,6 +112,26 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
currentDuration = await player.getDuration() ?? Duration.zero;
|
currentDuration = await player.getDuration() ?? Duration.zero;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final currentTrackIndex =
|
||||||
|
playlist!.tracks.indexWhere((t) => t.id == track?.id);
|
||||||
|
|
||||||
|
// when the track progress is above 80%, track isn't the last
|
||||||
|
// and is not already fetch and nothing is fetching currently
|
||||||
|
if (pos.inSeconds > currentDuration.inSeconds * .8 &&
|
||||||
|
playlist != null &&
|
||||||
|
currentTrackIndex != playlist!.tracks.length - 1 &&
|
||||||
|
playlist!.tracks.elementAt(currentTrackIndex + 1)
|
||||||
|
is! SpotubeTrack &&
|
||||||
|
!_isPreSearching) {
|
||||||
|
_isPreSearching = true;
|
||||||
|
playlist!.tracks[currentTrackIndex + 1] = await toSpotubeTrack(
|
||||||
|
playlist!.tracks[currentTrackIndex + 1],
|
||||||
|
).then((v) {
|
||||||
|
_isPreSearching = false;
|
||||||
|
return v;
|
||||||
|
});
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
}());
|
}());
|
||||||
@ -389,7 +411,9 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
(playlist!.trackIds.indexOf(track!.id!) + 1).toInt();
|
(playlist!.trackIds.indexOf(track!.id!) + 1).toInt();
|
||||||
// checking if there's any track available forward
|
// checking if there's any track available forward
|
||||||
if (nextTrackIndex > (playlist?.tracks.length ?? 0) - 1) return;
|
if (nextTrackIndex > (playlist?.tracks.length ?? 0) - 1) return;
|
||||||
await play(playlist!.tracks.elementAt(nextTrackIndex));
|
await play(playlist!.tracks.elementAt(nextTrackIndex)).then((_) {
|
||||||
|
playlist!.tracks[nextTrackIndex] = track!;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> seekBackward() async {
|
Future<void> seekBackward() async {
|
||||||
@ -398,7 +422,9 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
(playlist!.trackIds.indexOf(track!.id!) - 1).toInt();
|
(playlist!.trackIds.indexOf(track!.id!) - 1).toInt();
|
||||||
// checking if there's any track available behind
|
// checking if there's any track available behind
|
||||||
if (prevTrackIndex < 0) return;
|
if (prevTrackIndex < 0) return;
|
||||||
await play(playlist!.tracks.elementAt(prevTrackIndex));
|
await play(playlist!.tracks.elementAt(prevTrackIndex)).then((_) {
|
||||||
|
playlist!.tracks[prevTrackIndex] = track!;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
Reference in New Issue
Block a user