Hooked up view with play button

Set up data structures for holding and playing music
This commit is contained in:
watsonb8 2019-05-22 10:30:41 -04:00
parent 65d56a838c
commit a4276a0d5d
7 changed files with 88 additions and 31 deletions

View File

@ -33,6 +33,7 @@
<Folder Include="Backend\Utils\" />
<Folder Include="Backend\Models\" />
<Folder Include="Backend\Services\" />
<Folder Include="Backend\Services\PlayerService\" />
</ItemGroup>
<ItemGroup>
<Compile Update="Frontend\Components\MusicPlayer\Player.xaml.cs">

View File

@ -1,10 +1,16 @@
using System;
using System.IO;
namespace Aurora.Backend.Models
{
public abstract class BaseSong
{
private bool _loaded;
private Stream _stream;
public BaseSong()
{
_loaded = false;
Id = Guid.NewGuid().ToString();
}
@ -41,16 +47,41 @@ namespace Aurora.Backend.Models
/// <value></value>
public object Metadata { get; set; }
#endregion Properties
#region Methods
public virtual void Load()
{
_loaded = true;
}
public virtual void Unload()
{
_loaded = false;
}
/// <summary>
/// Play this instance.
/// Gets or sets the data stream that holds the song.
/// </summary>
public abstract void Play();
#endregion
/// <value>The data stream.</value>
public Stream DataStream
{
get
{
//if (!_loaded)
//{
// throw new InvalidOperationException("Must be loaded first");
//}
return _stream;
}
protected set
{
if (value != _stream)
{
_stream = value;
}
}
}
}
}

View File

@ -15,12 +15,25 @@ namespace Aurora.Backend.Models
#endregion Properties
#region Methods
public override void Play()
public override void Load()
{
throw new NotImplementedException();
if (this.DataStream != null)
{
DataStream.Close();
DataStream = null;
}
this.DataStream = System.IO.File.OpenRead(File.FullName);
base.Load();
}
#endregion Methods
public override void Unload()
{
if (this.DataStream != null)
{
DataStream.Close();
DataStream = null;
}
base.Unload();
}
}
}

View File

@ -4,13 +4,23 @@ using System.Runtime.CompilerServices;
namespace Aurora.Frontend.Views
{
public class BaseViewModel
public class BaseViewModel : INotifyPropertyChanged
{
public BaseViewModel()
{
}
#region INotifyPropertyChanged Implementation
public bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Object.Equals(storage, value))
return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
{

View File

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:songs="clr-namespace:Aurora.Frontend.Views.Songs"
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
x:Class="Aurora.Frontend.Views.Songs.SongsView">
<ContentPage.BindingContext>
<songs:SongsViewModel x:Name="songsViewModel"/>
</ContentPage.BindingContext>
<ContentPage.Content>
<dg:DataGrid ItemsSource="{Binding SongsList}" SelectionEnabled="True" SelectedItem="{Binding SelectedSong}"
RowHeight="30" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8" >
@ -18,6 +23,13 @@
<!-- Columns -->
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="" Width="40">
<dg:DataGridColumn.CellTemplate>
<DataTemplate>
<Button Text="Play" Command="{Binding PlayCommand}" BindingContext="{x:Reference songsViewModel}" />
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn Title="Title" PropertyName="Title" Width="2*" />
<dg:DataGridColumn Title="Album" PropertyName="Album" Width="0.95*"/>
<dg:DataGridColumn Title="Artist" PropertyName="Artist" Width="1*"/>

View File

@ -10,7 +10,6 @@ namespace Aurora.Frontend.Views.Songs
public SongsView()
{
InitializeComponent();
BindingContext = new SongsViewModel();
}
}
}

View File

@ -1,6 +1,8 @@
using System.Collections.ObjectModel;
using Aurora.Backend.Models;
using Aurora.Backend.Services;
using Aurora.Backend.Services.PlayerService;
using Xamarin.Forms;
namespace Aurora.Frontend.Views.Songs
{
@ -16,6 +18,7 @@ namespace Aurora.Frontend.Views.Songs
public SongsViewModel()
{
_songsList = new ObservableCollection<BaseSong>();
PlayCommand = new Command(PlayExecute);
Initialize();
}
@ -25,29 +28,17 @@ namespace Aurora.Frontend.Views.Songs
public ObservableCollection<BaseSong> SongsList
{
get { return _songsList; }
set
{
if (value != _songsList)
{
_songsList = value;
OnPropertyChanged("SongList");
}
}
set { SetProperty(ref _songsList, value); }
}
public BaseSong SelectedSong
{
get { return _selectedSong; }
set
{
if (value != _selectedSong)
{
_selectedSong = value;
OnPropertyChanged("SelectedSong");
}
}
set { SetProperty(ref _selectedSong, value); }
}
public Command PlayCommand { get; private set; }
#endregion Properties
#region Methods