Skip to content

Commit

Permalink
fix: save track info file after updating duration
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Dec 30, 2023
1 parent 40fa467 commit 5dd1b5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/controller/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,8 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
tr.toAudioSource(currentIndex, currentQueue.length),
startPlaying: startPlaying,
);
if (tr.duration == 0) {
tr.duration = dur?.inSeconds ?? 0;
}
Indexer.inst.updateTrackDuration(tr, dur);

refreshNotification(currentItem);
}

Expand Down
8 changes: 8 additions & 0 deletions lib/controller/indexer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,14 @@ class Indexer {
await File(AppPaths.TRACKS).writeAsJson(tracksInfoList.map((key) => allTracksMappedByPath[key]?.toJson()).toList());
}

Future<void> updateTrackDuration(Track track, Duration? dur) async {
final durInSeconds = dur?.inSeconds ?? 0;
if (track.duration == 0 && durInSeconds > 0) {
track.duration = durInSeconds;
}
await _saveTrackFileToStorage();
}

/// Returns new [TrackStats].
Future<TrackStats> updateTrackStats(
Track track, {
Expand Down

0 comments on commit 5dd1b5d

Please sign in to comment.