Flutter - 自定义排序当前播放列表(just_audio)

Flutter - Customly Sort the Current Playing Playlist ( just_audio)

我一直在尝试找到一种方法来根据使用 flutter_media_metadata 提取的每个元数据对当前播放的播放列表进行排序,但到目前为止没有成功。

有没有办法使用 just_audio 来做到这一点?

编辑:媒体数据的输入方式如下:

1: Creating the playlist

2: Set the playlist to the player

这可能是您需要自己添加的内容。您可以获取播放列表中的歌曲列表并编写函数以根据每个 属性.

对它们进行排序

例如:

List<Songs> sortByTitle(List<Songs> playlist, bool isDescending = True) {
  if(isDescending) {
    playlist = playlist.sort((b, a) => a.compareTo(b));
  } else {
    playlist = playlist.sort((a, b) => a.compareTo(b));
  }
  return playlist;
}

您传入的列表是标题列表或您尝试作为排序依据的任何元数据。

有关排序方法的详细信息,请参阅 https://api.dart.dev/stable/2.17.0/dart-core/List/sort.html

我能够通过添加排序函数 in this abstract class (ShuffleOrder) and then implementing it here (DefaultShuffleOrder). I also added a sort function in this absctract class (AudioSource) and I implemented it in this class (ConcatenatingAudioSource) 来解决问题,最后在 AudioPlayer class 我添加了这个排序函数:

Future<void> sort(List<Song> songs, PlaylistSorting playlistSorting, {SortingOrder sortingOrder = SortingOrder.ascending}) async {
    if (_disposed) return;
    if (audioSource == null) return;
    _audioSource!._sort(songs, playlistSorting, sortingOrder: sortingOrder);
    _updateShuffleIndices();
    await (await _platform).setShuffleOrder(SetShuffleOrderRequest(audioSourceMessage: _audioSource!._toMessage()));
}