Skip to content

Commit 0c75d40

Browse files
author
theweavrs
committed
added auto library loading on first start.
1 parent dfea8ac commit 0c75d40

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

BreadPlayer.Core/ViewModels/LibraryViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ You should have received a copy of the GNU General Public License
3737
using BreadPlayer.Common;
3838
using BreadPlayer.Messengers;
3939
using Windows.ApplicationModel.DataTransfer;
40+
using Windows.Storage.Search;
4041

4142
namespace BreadPlayer.ViewModels
4243
{
@@ -424,7 +425,7 @@ async void Init(object para)
424425
#endregion
425426

426427
#region Methods
427-
428+
428429
async Task RefreshSourceAsync()
429430
{
430431
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
@@ -449,7 +450,7 @@ void ChangeView(string header, bool group, object src)
449450
grouped = group;
450451
source = src;
451452
libgrouped = ViewSource.IsSourceGrouped;
452-
if((src as ThreadSafeObservableCollection<Mediafile>)?.Any() == true && Player.CurrentlyPlayingFile != null)
453+
if((src as ThreadSafeObservableCollection<Mediafile>)?.Any() == true && Player.CurrentlyPlayingFile != null && (src as ThreadSafeObservableCollection<Mediafile>).FirstOrDefault(t => t.Path == Player.CurrentlyPlayingFile?.Path) != null)
453454
(src as ThreadSafeObservableCollection<Mediafile>).FirstOrDefault(t => t.Path == Player.CurrentlyPlayingFile?.Path).State = PlayerState.Playing;
454455
}
455456
async Task LoadCollectionAsync(Func<Mediafile, string> sortFunc, bool group)

BreadPlayer.Core/ViewModels/SettingsViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ public SettingsViewModel()
105105
}
106106
public static GroupedObservableCollection<string, Mediafile> TracksCollection
107107
{ get; set; }
108-
private void HandleMessage(Message message)
108+
private async void HandleMessage(Message message)
109109
{
110110
if(message.Payload is List<object>)
111111
{
112112
TracksCollection = (message.Payload as List<object>)[0] as GroupedObservableCollection<string, Mediafile>;
113+
if (TracksCollection.Count <= 0)
114+
await AutoLoadMusicLibrary().ConfigureAwait(false);
113115
if (TracksCollection != null)
114116
{
115117
message.HandledStatus = MessageHandledStatus.HandledContinue;
@@ -190,6 +192,15 @@ public ThreadSafeObservableCollection<StorageFolder> LibraryFoldersCollection
190192
return _LibraryFoldersCollection; }
191193
set { Set(ref _LibraryFoldersCollection, value); }
192194
}
195+
async Task AutoLoadMusicLibrary()
196+
{
197+
var options = Common.DirectoryWalker.GetQueryOptions();
198+
//this is the query result which we recieve after querying in the folder
199+
StorageFileQueryResult queryResult = KnownFolders.MusicLibrary.CreateFileQueryWithOptions(options);
200+
//the event for files changed
201+
queryResult.ContentsChanged += QueryResult_ContentsChanged;
202+
await AddFolderToLibraryAsync(queryResult);
203+
}
193204
/// <summary>
194205
/// Loads songs from a specified folder into the library. <seealso cref="LoadCommand"/>
195206
/// </summary>

0 commit comments

Comments
 (0)