Exemple #1
0
 public TrackViewModel(string artistName, Album album, Song song, DispatchingObservableCollection<LocationCommandMapping> trackLocationCommandMappings)
 {
     _song = song;
     ArtistName = artistName;
     Album = album;
     TrackLocationCommandMappings = trackLocationCommandMappings;
 }
Exemple #2
0
        private async Task<bool> ScanMusicLibraryFolder(StorageFolder parentFolder, IList<Artist> artists)
        {
            var newData = false;
            foreach (var folder in await parentFolder.GetFoldersAsync())
            {
                foreach (var f in await folder.GetFilesAsync(CommonFileQuery.OrderByMusicProperties))
                {
                    var fileProps = await f.Properties.GetMusicPropertiesAsync();

                    if (string.IsNullOrWhiteSpace(fileProps.Artist) == false)
                    {
                        var artist = artists.FirstOrDefault(x => string.Compare(x.Name, fileProps.Artist, StringComparison.CurrentCultureIgnoreCase) == 0);
                        if (artist == null)
                        {
                            artist = new Artist
                                            {
                                                Name = fileProps.Artist
                                            };
                            newData = true;
                            artists.Add(artist);
                        }
                        var album = artist.Albums.FirstOrDefault(x =>
                                string.Compare(x.Title, fileProps.Album, StringComparison.CurrentCultureIgnoreCase) == 0);
                        if (album == null)
                        {
                            var relativeFolder = folder.FolderRelativeId.Substring(folder.FolderRelativeId.IndexOf(@"\") + 1);
                            album = new Album
                                {
                                    Title = fileProps.Album,
                                    Folder = Path.Combine(relativeFolder, fileProps.Album.RemoveIllegalChars())
                                };
                            artist.Albums.Add(album);
                            newData = true;
                        }

                        uint discNumber = 1;
                        if (f.Name[1] == '-')
                        {
                            discNumber = Convert.ToUInt32(f.Name.Substring(0, 1));
                        }

                        var song = album.Songs.FirstOrDefault(s => s.DiscNumber == discNumber && s.TrackNumber == fileProps.TrackNumber);
                        if (song == null)
                        {
                            song = new Song
                                       {
                                           Title = fileProps.Title,
                                           DiscNumber = discNumber,
                                           TrackNumber = fileProps.TrackNumber,
                                           Path = f.Path,
                                           Duration = fileProps.Duration
                                       };
                            album.Songs.Add(song);
                            newData = true;
                            await _presentationBus.Publish(new SongLoadedEvent(album, song));
                            // save new entry to app storage
                        }
                        song.SetStorageFile(f);
                    }
                }
                newData |= await ScanMusicLibraryFolder(folder, artists);
            }
            return newData;
        }
Exemple #3
0
 public SongLoadedEvent(Album album, Song song)
 {
     Album = album;
     Song = song;
 }