Skip to content

Commit

Permalink
fix: jump to track going to wrong track
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Aug 25, 2023
1 parent d239d64 commit 190df17
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/provider/proxy_playlist/next_fetcher_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions lib/provider/proxy_playlist/proxy_playlist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/audio_player/mk_state_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/type_conversion_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
);
Expand Down

0 comments on commit 190df17

Please sign in to comment.