Restructuring. Added services.

This commit is contained in:
watsonb8 2019-05-19 20:21:54 -04:00
parent 1fcaffb9b1
commit 4b7c146041
15 changed files with 175 additions and 28 deletions

View File

@ -81,6 +81,10 @@
<Reference Include="Xamarin.Forms.DataGrid"> <Reference Include="Xamarin.Forms.DataGrid">
<HintPath>..\packages\Xamarin.Forms.DataGrid.3.1.0\lib\netstandard2.0\Xamarin.Forms.DataGrid.dll</HintPath> <HintPath>..\packages\Xamarin.Forms.DataGrid.3.1.0\lib\netstandard2.0\Xamarin.Forms.DataGrid.dll</HintPath>
</Reference> </Reference>
<Reference Include="NAudio">
<HintPath>..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic"> <EmbeddedResource Include="gtk-gui\gui.stetic">

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="NAudio" version="1.9.0" targetFramework="net47" />
<package id="System.Reflection" version="4.3.0" targetFramework="net47" /> <package id="System.Reflection" version="4.3.0" targetFramework="net47" />
<package id="System.Reflection.TypeExtensions" version="4.4.0" targetFramework="net47" /> <package id="System.Reflection.TypeExtensions" version="4.4.0" targetFramework="net47" />
<package id="System.Runtime.Serialization.Primitives" version="4.3.0" targetFramework="net47" /> <package id="System.Runtime.Serialization.Primitives" version="4.3.0" targetFramework="net47" />

View File

@ -15,6 +15,7 @@
<PackageReference Include="Xamarin.Essentials" Version="1.0.1" /> <PackageReference Include="Xamarin.Essentials" Version="1.0.1" />
<PackageReference Include="Xamarin.Forms.DataGrid" Version="3.1.0" /> <PackageReference Include="Xamarin.Forms.DataGrid" Version="3.1.0" />
<PackageReference Include="taglib-sharp-netstandard2.0" Version="2.1.0" /> <PackageReference Include="taglib-sharp-netstandard2.0" Version="2.1.0" />
<PackageReference Include="NAudio" Version="1.9.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Frontend\" /> <Folder Include="Frontend\" />
@ -28,5 +29,14 @@
<Folder Include="Frontend\Views\Albums\" /> <Folder Include="Frontend\Views\Albums\" />
<Folder Include="Frontend\Views\Artists\" /> <Folder Include="Frontend\Views\Artists\" />
<Folder Include="Frontend\Views\Stations\" /> <Folder Include="Frontend\Views\Stations\" />
<Folder Include="Frontend\Components\MusicPlayer\" />
<Folder Include="Backend\Utils\" />
<Folder Include="Backend\Models\" />
<Folder Include="Backend\Services\" />
</ItemGroup>
<ItemGroup>
<Compile Update="Frontend\Components\MusicPlayer\Player.xaml.cs">
<DependentUpon>Player.xaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,13 +1,16 @@
using System; using System;
namespace Aurora.Backend.Models
namespace Aurora.Frontend.Views.Songs
{ {
public class Song public abstract class BaseSong
{ {
public Song() public BaseSong()
{ {
Id = Guid.NewGuid().ToString();
} }
#region Properties
public string Id { get; private set; }
/// <summary> /// <summary>
/// The title of the song. /// The title of the song.
/// </summary> /// </summary>
@ -37,5 +40,17 @@ namespace Aurora.Frontend.Views.Songs
/// </summary> /// </summary>
/// <value></value> /// <value></value>
public object Metadata { get; set; } public object Metadata { get; set; }
#endregion Properties
#region Methods
/// <summary>
/// Play this instance.
/// </summary>
public abstract void Play();
#endregion
} }
}
}

View File

@ -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
}
}

View File

@ -0,0 +1,22 @@
using System;
namespace Aurora.Backend.Services
{
public abstract class BaseService<T> where T : class
{
private static volatile Lazy<T> _instance = new Lazy<T>(() => CreateInstanceOfT());
public static T Instance
{
get { return _instance.Value; }
}
private static T CreateInstanceOfT()
{
return Activator.CreateInstance(typeof(T), true) as T;
}
}
}

View File

@ -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<LibraryService>
{
#region Fields
private string _pathName = "/Users/brandonwatson/Music/iTunes/iTunes Media/Music";
private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma";
private Dictionary<string, Song> _library;
#endregion Fields
public LibraryService()
{
_library = new Dictionary<string, Song>();
LoadLibrary();
}
/// <summary>
/// Gets the songs.
/// </summary>
/// <returns>The songs.</returns>
public ObservableCollection<Song> GetLibrary()
{
ObservableCollection<Song> collection = new ObservableCollection<Song>();
foreach (KeyValuePair<string, Song> pair in _library)
{
collection.Add(pair.Value);
}
return collection;
}
/// <summary>
/// Loads library from files.
/// </summary>
private void LoadLibrary()
{
//Get songs
List<FileInfo> 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);
}
}
}
}

View File

@ -5,7 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Aurora.Frontend.Utils namespace Aurora.Backend.Utils
{ {
public class FileSystemUtils public class FileSystemUtils
{ {

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Components.MusicPlayer.Player">
<ContentView.Content>
</ContentView.Content>
</ContentView>

View File

@ -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();
}
}
}

0
Aurora/Frontend/Converters/InverseBoolConverter.cs Executable file → Normal file
View File

0
Aurora/Frontend/Converters/ToUpperConverter.cs Executable file → Normal file
View File

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Artists.ArtistsView"> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Artists.ArtistsView">
<ContentPage.Content> <ContentPage.Content>
</ContentPage.Content> </ContentPage.Content>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<MasterDetailPage <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Aurora.Frontend.Views.Songs" xmlns:views="clr-namespace:Aurora.Frontend.Views.Songs"
xmlns:navigation="clr-namespace:Aurora.Frontend.Components.NavigationMenu" xmlns:navigation="clr-namespace:Aurora.Frontend.Components.NavigationMenu"

View File

@ -1,16 +1,12 @@
using System; using System.Collections.ObjectModel;
using System.Collections.Generic; using Aurora.Backend.Models;
using System.Collections.ObjectModel; using Aurora.Backend.Services;
using System.IO;
using Aurora.Frontend.Utils;
namespace Aurora.Frontend.Views.Songs namespace Aurora.Frontend.Views.Songs
{ {
public class SongsViewModel : BaseViewModel public class SongsViewModel : BaseViewModel
{ {
#region Fields #region Fields
private string _pathName = "/Users/brandonwatson/Music/iTunes/iTunes Media/Music";
private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma";
private ObservableCollection<Song> _songsList; private ObservableCollection<Song> _songsList;
private Song _selectedSong; private Song _selectedSong;
@ -57,18 +53,8 @@ namespace Aurora.Frontend.Views.Songs
#region Methods #region Methods
public void Initialize() public void Initialize()
{ {
List<FileInfo> musicFiles = FileSystemUtils.TraverseFoldersAsync(_pathName, _extensions);
foreach (FileInfo file in musicFiles) SongsList = LibraryService.Instance.GetLibrary();
{
TagLib.File tagFile = TagLib.File.Create(file.FullName);
_songsList.Add(new Song()
{
Title = tagFile.Tag.Title,
Album = tagFile.Tag.Album,
Artist = tagFile.Tag.FirstAlbumArtist
});
}
} }
#endregion Methods #endregion Methods