Reputation: 173
I'm working on a simple music player app for UWP and I have a couple of questions. First of all here's my code
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
StorageFolder folder = KnownFolders.MusicLibrary;
await RetrieveFilesInFolders(folder);
}
private async Task RetrieveFilesInFolders(StorageFolder parent)
{
foreach (var file in await parent.GetFilesAsync())
{
if (file.FileType == ".mp3")
{
var songProperties = await file.Properties.GetMusicPropertiesAsync();
var currentThumb = await file.GetThumbnailAsync(ThumbnailMode.MusicView, 200, ThumbnailOptions.UseCurrentScale);
var albumCover = new BitmapImage();
albumCover.SetSource(currentThumb);
var song = new Song();
song.Title = songProperties.Title;
song.Artist = songProperties.Artist;
song.Album = songProperties.Album;
song.AlbumCover = albumCover;
song.SongFile = file;
song.FileName = file.Name;
SongUC songUc = new SongUC(song);
sp1.Children.Add(songUc);
}
}
foreach (var folder in await parent.GetFoldersAsync())
{
await RetrieveFilesInFolders(folder);
}
}
User control ctor
public SongUC(Song song)
{
this.InitializeComponent();
txtTitle.Text = song.Title;
txtAlbum.Text = song.Album;
txtArtist.Text = song.Artist;
txtName.Text = song.FileName;
imgAlbumArt.Source = song.AlbumCover;
}
RetrieveFilesInFolders
method in the PageLoaded event handler the best way to get all songs. Or will it slow down the app if there's a huge collection of music in the music folderUpvotes: 3
Views: 381
Reputation: 3492
As stated here, take a look at file queries and their ContentsChanged
event.
Upvotes: 1
Reputation: 6292
Use a FileSystemWatcher:
https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx
It allows you to catch events when files are being moved, deleted and renamed.
Upvotes: 0