Hooked up view with play button
Set up data structures for holding and playing music
This commit is contained in:
parent
65d56a838c
commit
a4276a0d5d
@ -33,6 +33,7 @@
|
|||||||
<Folder Include="Backend\Utils\" />
|
<Folder Include="Backend\Utils\" />
|
||||||
<Folder Include="Backend\Models\" />
|
<Folder Include="Backend\Models\" />
|
||||||
<Folder Include="Backend\Services\" />
|
<Folder Include="Backend\Services\" />
|
||||||
|
<Folder Include="Backend\Services\PlayerService\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Frontend\Components\MusicPlayer\Player.xaml.cs">
|
<Compile Update="Frontend\Components\MusicPlayer\Player.xaml.cs">
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Aurora.Backend.Models
|
namespace Aurora.Backend.Models
|
||||||
{
|
{
|
||||||
public abstract class BaseSong
|
public abstract class BaseSong
|
||||||
{
|
{
|
||||||
|
private bool _loaded;
|
||||||
|
private Stream _stream;
|
||||||
|
|
||||||
public BaseSong()
|
public BaseSong()
|
||||||
{
|
{
|
||||||
|
_loaded = false;
|
||||||
Id = Guid.NewGuid().ToString();
|
Id = Guid.NewGuid().ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,16 +47,41 @@ namespace Aurora.Backend.Models
|
|||||||
/// <value></value>
|
/// <value></value>
|
||||||
public object Metadata { get; set; }
|
public object Metadata { get; set; }
|
||||||
|
|
||||||
|
|
||||||
#endregion Properties
|
#endregion Properties
|
||||||
|
|
||||||
#region Methods
|
public virtual void Load()
|
||||||
/// <summary>
|
{
|
||||||
/// Play this instance.
|
_loaded = true;
|
||||||
/// </summary>
|
}
|
||||||
public abstract void Play();
|
|
||||||
|
public virtual void Unload()
|
||||||
|
{
|
||||||
|
_loaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the data stream that holds the song.
|
||||||
|
/// </summary>
|
||||||
|
/// <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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,25 @@ namespace Aurora.Backend.Models
|
|||||||
|
|
||||||
#endregion Properties
|
#endregion Properties
|
||||||
|
|
||||||
#region Methods
|
public override void Load()
|
||||||
public override void Play()
|
|
||||||
{
|
{
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,13 +4,23 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace Aurora.Frontend.Views
|
namespace Aurora.Frontend.Views
|
||||||
{
|
{
|
||||||
public class BaseViewModel
|
public class BaseViewModel : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public BaseViewModel()
|
public BaseViewModel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#region INotifyPropertyChanged Implementation
|
#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 event PropertyChangedEventHandler PropertyChanged;
|
||||||
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
||||||
{
|
{
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage 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:songs="clr-namespace:Aurora.Frontend.Views.Songs"
|
||||||
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
|
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
|
||||||
x:Class="Aurora.Frontend.Views.Songs.SongsView">
|
x:Class="Aurora.Frontend.Views.Songs.SongsView">
|
||||||
|
<ContentPage.BindingContext>
|
||||||
|
<songs:SongsViewModel x:Name="songsViewModel"/>
|
||||||
|
</ContentPage.BindingContext>
|
||||||
|
|
||||||
<ContentPage.Content>
|
<ContentPage.Content>
|
||||||
<dg:DataGrid ItemsSource="{Binding SongsList}" SelectionEnabled="True" SelectedItem="{Binding SelectedSong}"
|
<dg:DataGrid ItemsSource="{Binding SongsList}" SelectionEnabled="True" SelectedItem="{Binding SelectedSong}"
|
||||||
RowHeight="30" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8">
|
RowHeight="30" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8" >
|
||||||
|
|
||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
<dg:DataGrid.HeaderFontSize>
|
<dg:DataGrid.HeaderFontSize>
|
||||||
@ -18,7 +23,14 @@
|
|||||||
|
|
||||||
<!-- Columns -->
|
<!-- Columns -->
|
||||||
<dg:DataGrid.Columns>
|
<dg:DataGrid.Columns>
|
||||||
<dg:DataGridColumn Title="Title" PropertyName="Title" Width="2*"/>
|
<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="Album" PropertyName="Album" Width="0.95*"/>
|
||||||
<dg:DataGridColumn Title="Artist" PropertyName="Artist" Width="1*"/>
|
<dg:DataGridColumn Title="Artist" PropertyName="Artist" Width="1*"/>
|
||||||
<dg:DataGridColumn Title="Duration" PropertyName="Duration"/>
|
<dg:DataGridColumn Title="Duration" PropertyName="Duration"/>
|
||||||
|
@ -10,7 +10,6 @@ namespace Aurora.Frontend.Views.Songs
|
|||||||
public SongsView()
|
public SongsView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
BindingContext = new SongsViewModel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using Aurora.Backend.Models;
|
using Aurora.Backend.Models;
|
||||||
using Aurora.Backend.Services;
|
using Aurora.Backend.Services;
|
||||||
|
using Aurora.Backend.Services.PlayerService;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Aurora.Frontend.Views.Songs
|
namespace Aurora.Frontend.Views.Songs
|
||||||
{
|
{
|
||||||
@ -16,6 +18,7 @@ namespace Aurora.Frontend.Views.Songs
|
|||||||
public SongsViewModel()
|
public SongsViewModel()
|
||||||
{
|
{
|
||||||
_songsList = new ObservableCollection<BaseSong>();
|
_songsList = new ObservableCollection<BaseSong>();
|
||||||
|
PlayCommand = new Command(PlayExecute);
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,29 +28,17 @@ namespace Aurora.Frontend.Views.Songs
|
|||||||
public ObservableCollection<BaseSong> SongsList
|
public ObservableCollection<BaseSong> SongsList
|
||||||
{
|
{
|
||||||
get { return _songsList; }
|
get { return _songsList; }
|
||||||
set
|
set { SetProperty(ref _songsList, value); }
|
||||||
{
|
|
||||||
if (value != _songsList)
|
|
||||||
{
|
|
||||||
_songsList = value;
|
|
||||||
OnPropertyChanged("SongList");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseSong SelectedSong
|
public BaseSong SelectedSong
|
||||||
{
|
{
|
||||||
get { return _selectedSong; }
|
get { return _selectedSong; }
|
||||||
set
|
set { SetProperty(ref _selectedSong, value); }
|
||||||
{
|
|
||||||
if (value != _selectedSong)
|
|
||||||
{
|
|
||||||
_selectedSong = value;
|
|
||||||
OnPropertyChanged("SelectedSong");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Command PlayCommand { get; private set; }
|
||||||
|
|
||||||
#endregion Properties
|
#endregion Properties
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
Reference in New Issue
Block a user