From 4e9a7ca7f340283ddece52c6fa907b1302fc11be Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sun, 11 May 2014 17:02:04 +1000 Subject: [PATCH] Load all the metadata for the first song, so the duration will appear properly when it starts playing. --- src/playlist/songloaderinserter.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/playlist/songloaderinserter.cpp b/src/playlist/songloaderinserter.cpp index c513810cd..b11114d4e 100644 --- a/src/playlist/songloaderinserter.cpp +++ b/src/playlist/songloaderinserter.cpp @@ -119,15 +119,21 @@ void SongLoaderInserter::InsertSongs() { } void SongLoaderInserter::AsyncLoad() { - // First, quick load raw songs. int async_progress = 0; int async_load_id = task_manager_->StartTask(tr("Loading tracks")); task_manager_->SetTaskProgress(async_load_id, async_progress, pending_.count()); - for (SongLoader* loader : pending_) { + for (int i = 0; i < pending_.count(); ++i) { + SongLoader* loader = pending_[i]; loader->LoadFilenamesBlocking(); task_manager_->SetTaskProgress(async_load_id, ++async_progress); + if (i == 0) { + // Load everything from the first song. It'll start playing as soon as + // we emit PreloadFinished, so it needs to have the duration set to show + // properly in the UI. + loader->LoadMetadataBlocking(); + } songs_ << loader->songs(); } task_manager_->SetTaskFinished(async_load_id); @@ -138,8 +144,12 @@ void SongLoaderInserter::AsyncLoad() { async_load_id = task_manager_->StartTask(tr("Loading tracks info")); task_manager_->SetTaskProgress(async_load_id, async_progress, songs_.count()); SongList songs; - for (SongLoader* loader : pending_) { - loader->LoadMetadataBlocking(); + for (int i = 0; i < pending_.count(); ++i) { + SongLoader* loader = pending_[i]; + if (i != 0) { + // We already did this earlier for the first song. + loader->LoadMetadataBlocking(); + } songs << loader->songs(); task_manager_->SetTaskProgress(async_load_id, songs.count()); }