aurora/Aurora/Frontend/Views/Songs/SongsViewModel.cs
watsonb8 1fcaffb9b1 First pass at songs view
Using data grid for songs view. Added FileSystemUtil for async folder traversal
2019-05-19 17:25:42 -04:00

78 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using Aurora.Frontend.Utils;
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;
#endregion Fields
#region Constructor
public SongsViewModel()
{
_songsList = new ObservableCollection<Song>();
Initialize();
}
#endregion Constructor
#region Properties
public ObservableCollection<Song> SongsList
{
get { return _songsList; }
set
{
if (value != _songsList)
{
_songsList = value;
OnPropertyChanged("SongList");
}
}
}
public Song SelectedSong
{
get { return _selectedSong; }
set
{
if (value != _selectedSong)
{
_selectedSong = value;
OnPropertyChanged("SelectedSong");
}
}
}
#endregion Properties
#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
});
}
}
#endregion Methods
}
}