mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
fix: jump to track going to wrong track
This commit is contained in:
parent
d239d641ff
commit
190df17adc
@ -86,13 +86,14 @@ mixin NextFetcher on StateNotifier<ProxyPlaylist> {
|
||||
} else if (track is LocalTrack) {
|
||||
return track.path;
|
||||
} else {
|
||||
return "https://youtube.com/unplayable.m4a?id=${track.id}&title=${track.name?.replaceAll(
|
||||
RegExp(r'\s+', caseSensitive: false),
|
||||
'-',
|
||||
)}";
|
||||
return trackToUnplayableSource(track);
|
||||
}
|
||||
}
|
||||
|
||||
String trackToUnplayableSource(Track track) {
|
||||
return "https://youtube.com/unplayable.m4a?id=${track.id}&title=${Uri.encodeComponent(track.name!)}";
|
||||
}
|
||||
|
||||
List<Track> mapSourcesToTracks(List<String> sources) {
|
||||
return sources
|
||||
.map((source) {
|
||||
|
@ -336,15 +336,18 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
Future<void> jumpTo(int index) async {
|
||||
final oldTrack =
|
||||
mapSourcesToTracks([audioPlayer.currentSource!]).firstOrNull;
|
||||
|
||||
state = state.copyWith(active: index);
|
||||
await audioPlayer.pause();
|
||||
final track = await ensureSourcePlayable(audioPlayer.sources[index]);
|
||||
|
||||
if (track != null) {
|
||||
state = state.copyWith(
|
||||
tracks: mergeTracks([track], state.tracks),
|
||||
active: index,
|
||||
);
|
||||
}
|
||||
|
||||
await audioPlayer.jumpTo(index);
|
||||
|
||||
if (oldTrack != null || track != null) {
|
||||
|
@ -159,7 +159,7 @@ class MkPlayerWithState extends Player {
|
||||
|
||||
@override
|
||||
Future<void> next() async {
|
||||
if (_playlist == null || _playlist!.index + 1 >= _playlist!.medias.length) {
|
||||
if (_playlist == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ class MkPlayerWithState extends Player {
|
||||
@override
|
||||
Future<void> jump(int index) async {
|
||||
if (_playlist == null || index < 0 || index >= _playlist!.medias.length) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
playlist = _playlist!.copyWith(index: index);
|
||||
|
@ -67,7 +67,7 @@ abstract class TypeConversionUtils {
|
||||
if (onRouteChange != null) {
|
||||
onRouteChange("/artist/${artist.value.id}");
|
||||
} else {
|
||||
ServiceUtils.navigate(
|
||||
ServiceUtils.push(
|
||||
context,
|
||||
"/artist/${artist.value.id}",
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user