Skip to content

Commit

Permalink
chore: save last played track index
Browse files Browse the repository at this point in the history
instead of path
  • Loading branch information
MSOB7YY committed Oct 26, 2023
1 parent d761003 commit 0ab0292
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/controller/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
startSleepAfterMinCount();
startCounterToAListen(pi);
increaseListenTime();
settings.save(lastPlayedTrackPath: tr.path);
settings.save(lastPlayedTrackIndex: index);
Lyrics.inst.updateLyrics(tr);
}

Expand Down
6 changes: 2 additions & 4 deletions lib/controller/queue_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,10 @@ class QueueController {

if (latestQueue.isEmpty) return;

final latestTrack = settings.lastPlayedTrackPath.value.toTrack();

final index = latestQueue.indexOf(latestTrack).toIf(0, -1);
final index = settings.lastPlayedTrackIndex.value;

await Player.inst.playOrPause(
index,
index > latestQueue.length - 1 ? 0 : index,
latestQueue,
QueueSource.playerQueue,
startPlaying: false,
Expand Down
12 changes: 6 additions & 6 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class SettingsController {
final RxInt playerPlayFadeDurInMilli = 300.obs;
final RxInt playerPauseFadeDurInMilli = 300.obs;
final RxInt minTrackDurationToRestoreLastPosInMinutes = 5.obs;
final RxString lastPlayedTrackPath = ''.obs;
final RxInt lastPlayedTrackIndex = 0.obs;
final RxBool displayFavouriteButtonInNotification = false.obs;
final RxBool enableSearchCleanup = true.obs;
final RxBool enableBottomNavBar = true.obs;
Expand Down Expand Up @@ -384,7 +384,7 @@ class SettingsController {
playerPlayFadeDurInMilli.value = json['playerPlayFadeDurInMilli'] ?? playerPlayFadeDurInMilli.value;
playerPauseFadeDurInMilli.value = json['playerPauseFadeDurInMilli'] as int? ?? playerPauseFadeDurInMilli.value;
minTrackDurationToRestoreLastPosInMinutes.value = json['minTrackDurationToRestoreLastPosInMinutes'] ?? minTrackDurationToRestoreLastPosInMinutes.value;
lastPlayedTrackPath.value = json['lastPlayedTrackPath'] ?? lastPlayedTrackPath.value;
lastPlayedTrackIndex.value = json['lastPlayedTrackIndex'] ?? lastPlayedTrackIndex.value;
displayFavouriteButtonInNotification.value = json['displayFavouriteButtonInNotification'] ?? displayFavouriteButtonInNotification.value;
enableSearchCleanup.value = json['enableSearchCleanup'] ?? enableSearchCleanup.value;
enableBottomNavBar.value = json['enableBottomNavBar'] ?? enableBottomNavBar.value;
Expand Down Expand Up @@ -581,7 +581,7 @@ class SettingsController {
'playerPlayFadeDurInMilli': playerPlayFadeDurInMilli.value,
'playerPauseFadeDurInMilli': playerPauseFadeDurInMilli.value,
'minTrackDurationToRestoreLastPosInMinutes': minTrackDurationToRestoreLastPosInMinutes.value,
'lastPlayedTrackPath': lastPlayedTrackPath.value,
'lastPlayedTrackIndex': lastPlayedTrackIndex.value,
'displayFavouriteButtonInNotification': displayFavouriteButtonInNotification.value,
'enableSearchCleanup': enableSearchCleanup.value,
'enableBottomNavBar': enableBottomNavBar.value,
Expand Down Expand Up @@ -749,7 +749,7 @@ class SettingsController {
int? playerPlayFadeDurInMilli,
int? playerPauseFadeDurInMilli,
int? minTrackDurationToRestoreLastPosInMinutes,
String? lastPlayedTrackPath,
int? lastPlayedTrackIndex,
bool? displayFavouriteButtonInNotification,
bool? enableSearchCleanup,
bool? enableBottomNavBar,
Expand Down Expand Up @@ -1135,8 +1135,8 @@ class SettingsController {
if (minTrackDurationToRestoreLastPosInMinutes != null) {
this.minTrackDurationToRestoreLastPosInMinutes.value = minTrackDurationToRestoreLastPosInMinutes;
}
if (lastPlayedTrackPath != null) {
this.lastPlayedTrackPath.value = lastPlayedTrackPath;
if (lastPlayedTrackIndex != null) {
this.lastPlayedTrackIndex.value = lastPlayedTrackIndex;
}
if (displayFavouriteButtonInNotification != null) {
this.displayFavouriteButtonInNotification.value = displayFavouriteButtonInNotification;
Expand Down

0 comments on commit 0ab0292

Please sign in to comment.