Restructuring. Added services.
This commit is contained in:
parent
1fcaffb9b1
commit
4b7c146041
@ -81,6 +81,10 @@
|
||||
<Reference Include="Xamarin.Forms.DataGrid">
|
||||
<HintPath>..\packages\Xamarin.Forms.DataGrid.3.1.0\lib\netstandard2.0\Xamarin.Forms.DataGrid.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio">
|
||||
<HintPath>..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="gtk-gui\gui.stetic">
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NAudio" version="1.9.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.Runtime.Serialization.Primitives" version="4.3.0" targetFramework="net47" />
|
||||
|
@ -15,6 +15,7 @@
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.0.1" />
|
||||
<PackageReference Include="Xamarin.Forms.DataGrid" Version="3.1.0" />
|
||||
<PackageReference Include="taglib-sharp-netstandard2.0" Version="2.1.0" />
|
||||
<PackageReference Include="NAudio" Version="1.9.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Frontend\" />
|
||||
@ -28,5 +29,14 @@
|
||||
<Folder Include="Frontend\Views\Albums\" />
|
||||
<Folder Include="Frontend\Views\Artists\" />
|
||||
<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>
|
||||
</Project>
|
@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// The title of the song.
|
||||
/// </summary>
|
||||
@ -37,5 +40,17 @@ namespace Aurora.Frontend.Views.Songs
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public object Metadata { get; set; }
|
||||
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Methods
|
||||
/// <summary>
|
||||
/// Play this instance.
|
||||
/// </summary>
|
||||
public abstract void Play();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
}
|
26
Aurora/Backend/Models/LocalSong.cs
Normal file
26
Aurora/Backend/Models/LocalSong.cs
Normal 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
|
||||
}
|
||||
}
|
22
Aurora/Backend/Services/BaseService.cs
Normal file
22
Aurora/Backend/Services/BaseService.cs
Normal 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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
Aurora/Backend/Services/LibraryService.cs
Normal file
65
Aurora/Backend/Services/LibraryService.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
5
Aurora/Frontend/Components/MusicPlayer/Player.xaml
Normal file
5
Aurora/Frontend/Components/MusicPlayer/Player.xaml
Normal 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>
|
14
Aurora/Frontend/Components/MusicPlayer/Player.xaml.cs
Normal file
14
Aurora/Frontend/Components/MusicPlayer/Player.xaml.cs
Normal 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
0
Aurora/Frontend/Converters/InverseBoolConverter.cs
Executable file → Normal file
0
Aurora/Frontend/Converters/ToUpperConverter.cs
Executable file → Normal file
0
Aurora/Frontend/Converters/ToUpperConverter.cs
Executable file → Normal 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.Content>
|
||||
</ContentPage.Content>
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MasterDetailPage
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:views="clr-namespace:Aurora.Frontend.Views.Songs"
|
||||
xmlns:navigation="clr-namespace:Aurora.Frontend.Components.NavigationMenu"
|
||||
|
@ -1,16 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using Aurora.Frontend.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using Aurora.Backend.Models;
|
||||
using Aurora.Backend.Services;
|
||||
|
||||
namespace Aurora.Frontend.Views.Songs
|
||||
{
|
||||
public class SongsViewModel : BaseViewModel
|
||||
{
|
||||
#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 Song _selectedSong;
|
||||
|
||||
@ -57,18 +53,8 @@ namespace Aurora.Frontend.Views.Songs
|
||||
#region Methods
|
||||
public void Initialize()
|
||||
{
|
||||
List<FileInfo> 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
|
||||
|
Reference in New Issue
Block a user