From 5dd1b5d3dc804ab17994b4ac22cf924aff366c12 Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Sat, 30 Dec 2023 19:05:32 +0200 Subject: [PATCH] fix: save track info file after updating duration --- lib/controller/audio_handler.dart | 5 ++--- lib/controller/indexer_controller.dart | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/controller/audio_handler.dart b/lib/controller/audio_handler.dart index 3281b28a..47a49fc2 100644 --- a/lib/controller/audio_handler.dart +++ b/lib/controller/audio_handler.dart @@ -498,9 +498,8 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { tr.toAudioSource(currentIndex, currentQueue.length), startPlaying: startPlaying, ); - if (tr.duration == 0) { - tr.duration = dur?.inSeconds ?? 0; - } + Indexer.inst.updateTrackDuration(tr, dur); + refreshNotification(currentItem); } diff --git a/lib/controller/indexer_controller.dart b/lib/controller/indexer_controller.dart index e93af03f..6d4ac705 100644 --- a/lib/controller/indexer_controller.dart +++ b/lib/controller/indexer_controller.dart @@ -1008,6 +1008,14 @@ class Indexer { await File(AppPaths.TRACKS).writeAsJson(tracksInfoList.map((key) => allTracksMappedByPath[key]?.toJson()).toList()); } + Future 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 updateTrackStats( Track track, {