using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using Aurora.Models.Media; using Aurora.Utils; namespace Aurora.Services { public class LibraryService : BaseService { #region Fields private string _pathName = "/Users/brandonwatson/Music/iTunes/iTunes Media/Music"; private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma"; private Dictionary _library; #endregion Fields public LibraryService() { _library = new Dictionary(); LoadLibrary(); } /// /// Gets the songs. /// /// The songs. public ObservableCollection GetLibrary() { ObservableCollection collection = new ObservableCollection(); foreach (KeyValuePair pair in _library) { collection.Add(pair.Value); } return collection; } public BaseMedia GetSong(string Id) { _library.TryGetValue(Id, out BaseMedia song); return song; } /// /// Loads library from files. /// private void LoadLibrary() { //Get songs List musicFiles = FileSystemUtils.TraverseFoldersAsync(_pathName, _extensions); foreach (FileInfo file in musicFiles) { TagLib.File tagFile = TagLib.File.Create(file.FullName); BaseMedia song = new LocalAudio(file); _library.Add(song.Id, song); } } } }