0.5.3 - Download fixes, shuffle fix, sorting in library
This commit is contained in:
parent
952cf0f508
commit
2f471268c6
18 changed files with 556 additions and 167 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'package:freezer/api/deezer.dart';
|
||||
import 'package:freezer/api/definitions.dart';
|
||||
import 'package:freezer/ui/details_screens.dart';
|
||||
import 'package:freezer/ui/library.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
@ -30,6 +31,14 @@ class Cache {
|
|||
@JsonKey(defaultValue: {})
|
||||
Map<String, SortType> playlistSort;
|
||||
|
||||
//Sort
|
||||
@JsonKey(defaultValue: AlbumSortType.DEFAULT)
|
||||
AlbumSortType albumSort;
|
||||
@JsonKey(defaultValue: ArtistSortType.DEFAULT)
|
||||
ArtistSortType artistSort;
|
||||
@JsonKey(defaultValue: PlaylistSortType.DEFAULT)
|
||||
PlaylistSortType libraryPlaylistSort;
|
||||
|
||||
|
||||
Cache({this.libraryTracks});
|
||||
|
||||
|
|
|
@ -19,7 +19,16 @@ Cache _$CacheFromJson(Map<String, dynamic> json) {
|
|||
..playlistSort = (json['playlistSort'] as Map<String, dynamic>)?.map(
|
||||
(k, e) => MapEntry(k, _$enumDecodeNullable(_$SortTypeEnumMap, e)),
|
||||
) ??
|
||||
{};
|
||||
{}
|
||||
..albumSort =
|
||||
_$enumDecodeNullable(_$AlbumSortTypeEnumMap, json['albumSort']) ??
|
||||
AlbumSortType.DEFAULT
|
||||
..artistSort =
|
||||
_$enumDecodeNullable(_$ArtistSortTypeEnumMap, json['artistSort']) ??
|
||||
ArtistSortType.DEFAULT
|
||||
..libraryPlaylistSort = _$enumDecodeNullable(
|
||||
_$PlaylistSortTypeEnumMap, json['libraryPlaylistSort']) ??
|
||||
PlaylistSortType.DEFAULT;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$CacheToJson(Cache instance) => <String, dynamic>{
|
||||
|
@ -27,6 +36,10 @@ Map<String, dynamic> _$CacheToJson(Cache instance) => <String, dynamic>{
|
|||
'history': instance.history,
|
||||
'playlistSort': instance.playlistSort
|
||||
?.map((k, e) => MapEntry(k, _$SortTypeEnumMap[e])),
|
||||
'albumSort': _$AlbumSortTypeEnumMap[instance.albumSort],
|
||||
'artistSort': _$ArtistSortTypeEnumMap[instance.artistSort],
|
||||
'libraryPlaylistSort':
|
||||
_$PlaylistSortTypeEnumMap[instance.libraryPlaylistSort],
|
||||
};
|
||||
|
||||
T _$enumDecode<T>(
|
||||
|
@ -67,3 +80,25 @@ const _$SortTypeEnumMap = {
|
|||
SortType.ALPHABETIC: 'ALPHABETIC',
|
||||
SortType.ARTIST: 'ARTIST',
|
||||
};
|
||||
|
||||
const _$AlbumSortTypeEnumMap = {
|
||||
AlbumSortType.DEFAULT: 'DEFAULT',
|
||||
AlbumSortType.REVERSE: 'REVERSE',
|
||||
AlbumSortType.ALPHABETIC: 'ALPHABETIC',
|
||||
AlbumSortType.ARTIST: 'ARTIST',
|
||||
};
|
||||
|
||||
const _$ArtistSortTypeEnumMap = {
|
||||
ArtistSortType.DEFAULT: 'DEFAULT',
|
||||
ArtistSortType.REVERSE: 'REVERSE',
|
||||
ArtistSortType.POPULARITY: 'POPULARITY',
|
||||
ArtistSortType.ALPHABETIC: 'ALPHABETIC',
|
||||
};
|
||||
|
||||
const _$PlaylistSortTypeEnumMap = {
|
||||
PlaylistSortType.DEFAULT: 'DEFAULT',
|
||||
PlaylistSortType.REVERSE: 'REVERSE',
|
||||
PlaylistSortType.ALPHABETIC: 'ALPHABETIC',
|
||||
PlaylistSortType.USER: 'USER',
|
||||
PlaylistSortType.TRACK_COUNT: 'TRACK_COUNT',
|
||||
};
|
||||
|
|
|
@ -246,6 +246,7 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
|||
|
||||
//Queue
|
||||
List<MediaItem> _queue = <MediaItem>[];
|
||||
List<int> _shuffleHistory = [];
|
||||
int _queueIndex = 0;
|
||||
ConcatenatingAudioSource _audioSource;
|
||||
|
||||
|
@ -363,13 +364,15 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
|||
Future<void> onSkipToNext() async {
|
||||
//Shuffle
|
||||
if (_player.shuffleModeEnabled??false) {
|
||||
int newIndex = Random().nextInt(_queue.length)-1;
|
||||
int newIndex = Random().nextInt(_queue.length-1);
|
||||
//Update state
|
||||
_skipState = newIndex > _queueIndex
|
||||
? AudioProcessingState.skippingToNext
|
||||
: AudioProcessingState.skippingToPrevious;
|
||||
|
||||
if (_shuffleHistory.length == 0) _shuffleHistory.add(_queueIndex);
|
||||
_queueIndex = newIndex;
|
||||
_shuffleHistory.add(newIndex);
|
||||
await _player.seek(Duration.zero, index: _queueIndex);
|
||||
_skipState = null;
|
||||
return;
|
||||
|
@ -385,9 +388,24 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
|||
|
||||
@override
|
||||
Future<void> onSkipToPrevious() async {
|
||||
if (_queueIndex == 0) return;
|
||||
if (_queueIndex == 0 && !(_player.shuffleModeEnabled??false)) return;
|
||||
//Update buffering state
|
||||
_skipState = AudioProcessingState.skippingToPrevious;
|
||||
|
||||
//Shuffle history
|
||||
if ((_player.shuffleModeEnabled??false) && _shuffleHistory.length > 1) {
|
||||
_shuffleHistory.removeLast();
|
||||
if (_shuffleHistory.last < _queue.length) {
|
||||
_queueIndex = _shuffleHistory.last;
|
||||
await _player.seek(Duration.zero, index: _queueIndex);
|
||||
_skipState = null;
|
||||
return;
|
||||
} else {
|
||||
_shuffleHistory = [];
|
||||
}
|
||||
}
|
||||
|
||||
//Normal skip to previous
|
||||
_queueIndex--;
|
||||
await _player.seekToPrevious();
|
||||
_skipState = null;
|
||||
|
@ -553,9 +571,11 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
|||
if (name == 'repeatType') {
|
||||
_player.setLoopMode(LoopMode.values[args]);
|
||||
}
|
||||
if (name == 'saveQueue') await this._saveQueue();
|
||||
if (name == 'saveQueue')
|
||||
await this._saveQueue();
|
||||
//Load queue after some initialization in frontend
|
||||
if (name == 'load') await this._loadQueueFile();
|
||||
if (name == 'load')
|
||||
await this._loadQueueFile();
|
||||
//Shuffle
|
||||
if (name == 'shuffle') {
|
||||
await _player.setShuffleModeEnabled(args);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue