public static Song getSongDetails(string path) { Song song = new Song(); try { TagLib.File tagFile = TagLib.File.Create(path); if (tagFile.Tag.Performers.Length != 0) song.Artist = tagFile.Tag.Performers[0]; song.Album = tagFile.Tag.Album; song.Path = path; song.Length = tagFile.Properties.Duration; if (song.Length.Hours < 1) song.FormattedLength = song.Length.ToString(@"mm\:ss"); else song.FormattedLength = song.Length.ToString(@"hh\:mm\:ss"); if (tagFile.Tag.Title != null) { song.Title = tagFile.Tag.Title; } else { song.Title = Path.GetFileName(tagFile.Name); } if (tagFile.Tag.Pictures.Length != 0) { MemoryStream ms = new MemoryStream(tagFile.Tag.Pictures[0].Data.Data); ms.Seek(0, SeekOrigin.Begin); // ImageSource for System.Windows.Controls.Image BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = ms; bitmap.EndInit(); song.AlbumArt = bitmap; } song.Year = (int) tagFile.Tag.Year; if (tagFile.Tag.AlbumArtists.Length != 0) song.AlbumArtist = tagFile.Tag.AlbumArtists[0]; } catch(CorruptFileException e) { } return song; }
public void GetSongs() { _all_songs = new ObservableCollection<Song>(); _all_albums = new ObservableCollection<Album>(); List<string> songs = FileHandler.getFiles("C:\\Users\\Savatia\\Music"); for (int i = 0; i < songs.Capacity; i++) { bool execute = true; Song song = new Song(); song = SongHelper.getSongDetails(songs[i]); _all_songs.Add(song); for (int y = 0; y < _all_albums.Count; y++) { if (_all_albums[y].AlbumName == song.Album) { _all_albums[y].Length.Add(song.Length); _all_albums[y].AlbumSongs.Add(song); execute = false; break; } } if (execute) { Album album = new Album(); album.AlbumArt = song.AlbumArt; album.AlbumArtist = song.AlbumArtist; album.Year = song.Year; album.AlbumName = song.Album; album.Length = song.Length; album.AlbumSongs.Add(song); _all_albums.Add(album); } execute = true; } }