diff --git a/Aurora.gtk/Aurora.gtk.csproj b/Aurora.gtk/Aurora.gtk.csproj index dfeca64..17c6f46 100644 --- a/Aurora.gtk/Aurora.gtk.csproj +++ b/Aurora.gtk/Aurora.gtk.csproj @@ -81,6 +81,10 @@ ..\packages\Xamarin.Forms.DataGrid.3.1.0\lib\netstandard2.0\Xamarin.Forms.DataGrid.dll + + ..\packages\NAudio.1.9.0\lib\net35\NAudio.dll + + diff --git a/Aurora.gtk/packages.config b/Aurora.gtk/packages.config index e160d7a..99db055 100644 --- a/Aurora.gtk/packages.config +++ b/Aurora.gtk/packages.config @@ -1,5 +1,6 @@  + diff --git a/Aurora/Aurora.csproj b/Aurora/Aurora.csproj index 0825bec..122adea 100644 --- a/Aurora/Aurora.csproj +++ b/Aurora/Aurora.csproj @@ -15,6 +15,7 @@ + @@ -28,5 +29,14 @@ + + + + + + + + Player.xaml + \ No newline at end of file diff --git a/Aurora/Frontend/Models/Song.cs b/Aurora/Backend/Models/BaseSong.cs similarity index 66% rename from Aurora/Frontend/Models/Song.cs rename to Aurora/Backend/Models/BaseSong.cs index bf17f18..ca2156d 100644 --- a/Aurora/Frontend/Models/Song.cs +++ b/Aurora/Backend/Models/BaseSong.cs @@ -1,13 +1,16 @@ -using System; - -namespace Aurora.Frontend.Views.Songs +using System; +namespace Aurora.Backend.Models { - public class Song + public abstract class BaseSong { - public Song() + public BaseSong() { + Id = Guid.NewGuid().ToString(); } + #region Properties + public string Id { get; private set; } + /// /// The title of the song. /// @@ -37,5 +40,17 @@ namespace Aurora.Frontend.Views.Songs /// /// public object Metadata { get; set; } + + + #endregion Properties + + #region Methods + /// + /// Play this instance. + /// + public abstract void Play(); + + #endregion } -} \ No newline at end of file + +} diff --git a/Aurora/Backend/Models/LocalSong.cs b/Aurora/Backend/Models/LocalSong.cs new file mode 100644 index 0000000..21405bb --- /dev/null +++ b/Aurora/Backend/Models/LocalSong.cs @@ -0,0 +1,26 @@ +using System; +using System.IO; + +namespace Aurora.Backend.Models +{ + public class LocalSong : BaseSong + { + public LocalSong(FileInfo fileInfo) + { + File = fileInfo; + } + + #region Properties + public FileInfo File { get; private set; } + + #endregion Properties + + #region Methods + public override void Play() + { + throw new NotImplementedException(); + } + + #endregion Methods + } +} \ No newline at end of file diff --git a/Aurora/Backend/Services/BaseService.cs b/Aurora/Backend/Services/BaseService.cs new file mode 100644 index 0000000..c7523d8 --- /dev/null +++ b/Aurora/Backend/Services/BaseService.cs @@ -0,0 +1,22 @@ +using System; + +namespace Aurora.Backend.Services +{ + public abstract class BaseService where T : class + { + private static volatile Lazy _instance = new Lazy(() => CreateInstanceOfT()); + + public static T Instance + { + get { return _instance.Value; } + } + + private static T CreateInstanceOfT() + { + + return Activator.CreateInstance(typeof(T), true) as T; + + } + } +} + diff --git a/Aurora/Backend/Services/LibraryService.cs b/Aurora/Backend/Services/LibraryService.cs new file mode 100644 index 0000000..e9a1b3d --- /dev/null +++ b/Aurora/Backend/Services/LibraryService.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using Aurora.Backend.Models; +using Aurora.Backend.Utils; +using NAudio.Wave; + +namespace Aurora.Backend.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; + } + + /// + /// 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); + + Song song = new Song(file) + { + Title = tagFile.Tag.Title, + Album = tagFile.Tag.Album, + Artist = tagFile.Tag.FirstAlbumArtist + }; + + _library.Add(song.Id, song); + } + } + } +} diff --git a/Aurora/Frontend/Utils/FileSystemUtils.cs b/Aurora/Backend/Utils/FileSystemUtils.cs similarity index 98% rename from Aurora/Frontend/Utils/FileSystemUtils.cs rename to Aurora/Backend/Utils/FileSystemUtils.cs index b951088..6049256 100644 --- a/Aurora/Frontend/Utils/FileSystemUtils.cs +++ b/Aurora/Backend/Utils/FileSystemUtils.cs @@ -5,7 +5,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -namespace Aurora.Frontend.Utils +namespace Aurora.Backend.Utils { public class FileSystemUtils { diff --git a/Aurora/Frontend/Components/MusicPlayer/Player.xaml b/Aurora/Frontend/Components/MusicPlayer/Player.xaml new file mode 100644 index 0000000..3df65c5 --- /dev/null +++ b/Aurora/Frontend/Components/MusicPlayer/Player.xaml @@ -0,0 +1,5 @@ + + + + + diff --git a/Aurora/Frontend/Components/MusicPlayer/Player.xaml.cs b/Aurora/Frontend/Components/MusicPlayer/Player.xaml.cs new file mode 100644 index 0000000..a706029 --- /dev/null +++ b/Aurora/Frontend/Components/MusicPlayer/Player.xaml.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms; + +namespace Aurora.Frontend.Components.MusicPlayer +{ + public partial class Player : ContentView + { + public Player() + { + InitializeComponent(); + } + } +} diff --git a/Aurora/Frontend/Converters/InverseBoolConverter.cs b/Aurora/Frontend/Converters/InverseBoolConverter.cs old mode 100755 new mode 100644 diff --git a/Aurora/Frontend/Converters/ToUpperConverter.cs b/Aurora/Frontend/Converters/ToUpperConverter.cs old mode 100755 new mode 100644 diff --git a/Aurora/Frontend/Views/Artists/ArtistsView.xaml b/Aurora/Frontend/Views/Artists/ArtistsView.xaml index da15e25..aa817a7 100644 --- a/Aurora/Frontend/Views/Artists/ArtistsView.xaml +++ b/Aurora/Frontend/Views/Artists/ArtistsView.xaml @@ -1,4 +1,4 @@ - + diff --git a/Aurora/Frontend/Views/MainView/MainView.xaml b/Aurora/Frontend/Views/MainView/MainView.xaml index 7098895..0096f56 100644 --- a/Aurora/Frontend/Views/MainView/MainView.xaml +++ b/Aurora/Frontend/Views/MainView/MainView.xaml @@ -1,6 +1,5 @@ - _songsList; private Song _selectedSong; @@ -57,18 +53,8 @@ namespace Aurora.Frontend.Views.Songs #region Methods public void Initialize() { - List musicFiles = FileSystemUtils.TraverseFoldersAsync(_pathName, _extensions); - foreach (FileInfo file in musicFiles) - { - TagLib.File tagFile = TagLib.File.Create(file.FullName); - _songsList.Add(new Song() - { - Title = tagFile.Tag.Title, - Album = tagFile.Tag.Album, - Artist = tagFile.Tag.FirstAlbumArtist - }); - } + SongsList = LibraryService.Instance.GetLibrary(); } #endregion Methods