Remote playback almost working

This commit is contained in:
watsonb8
2019-11-03 23:17:34 -05:00
parent a13e491a7e
commit a537edd657
14 changed files with 296 additions and 136 deletions

View File

@ -12,6 +12,10 @@
HeaderHeight="40"
BorderColor="#CCCCCC"
HeaderBackground="#E0E6F8">
<dg:DataGrid.GestureRecognizers>
<TapGestureRecognizer
NumberOfTapsRequired="2"/>
</dg:DataGrid.GestureRecognizers>
<dg:DataGrid.HeaderFontSize>
<OnIdiom
x:TypeArguments="x:Double">

View File

@ -12,6 +12,10 @@ namespace Aurora.Design.Components.Queue
public Queue()
{
InitializeComponent();
this.QueueDataGrid.ItemSelected += (sender, e) =>
{
this.SelectedItem = e.SelectedItem;
};
}
#region ItemsSource Property
@ -69,8 +73,7 @@ namespace Aurora.Design.Components.Queue
BindableProperty.Create(propertyName: "SelectedItem",
returnType: typeof(object),
declaringType: typeof(Queue),
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: OnSelectedItemChanged);
defaultBindingMode: BindingMode.TwoWay);
/// <summary>
/// Backing property for the SelectedItem property.
@ -88,22 +91,58 @@ namespace Aurora.Design.Components.Queue
}
}
/// <summary>
/// Handles selection change events.
/// Bindable property for the item double clicked command
/// </summary>
/// <param name="bindable">The bindable object.</param>
/// <param name=""SelectedItem""></param>
/// <param name="typeof(BaseMetadata"></param>
/// <returns></returns>
public static readonly BindableProperty ItemDoubleClickedProperty =
BindableProperty.Create(propertyName: "ItemDoubleClicked",
returnType: typeof(Command),
declaringType: typeof(Queue),
propertyChanged: OnDoubleClickPropertyChanged);
/// <summary>
/// Public backing property
/// </summary>
/// <value></value>
public Command ItemDoubleClicked
{
get
{
return (Command)GetValue(ItemDoubleClickedProperty);
}
set
{
SetValue(ItemDoubleClickedProperty, value);
}
}
/// <summary>
/// Event handler for double click property. Adds command execute handler.
/// </summary>
/// <param name="bindable"></param>
/// <param name="newValue"></param>
/// <param name="oldValue"></param>
private static void OnSelectedItemChanged(BindableObject bindable, object newValue, object oldValue)
private static void OnDoubleClickPropertyChanged(BindableObject bindable, object newValue, object oldValue)
{
Queue control = bindable as Queue;
var queueDataGrid = control.FindByName("QueueDataGrid") as DataGrid;
IEnumerable<object> source = (IEnumerable<object>)queueDataGrid.ItemsSource;
if (source.Contains(newValue))
if (queueDataGrid.GestureRecognizers.Count > 0)
{
queueDataGrid.SelectedItem = newValue;
}
var gestureRecognizer = queueDataGrid.GestureRecognizers.First();
if (gestureRecognizer is TapGestureRecognizer)
{
TapGestureRecognizer tap = gestureRecognizer as TapGestureRecognizer;
tap.Tapped += (sender, e) =>
{
control.ItemDoubleClicked.Execute(null);
};
}
}
}
}
}

View File

@ -24,7 +24,9 @@
<Label
Text="Queue"/>
<qu:Queue
ItemsSource="{Binding Queue}"/>
ItemsSource="{Binding Queue}"
SelectedItem="{Binding SelectedSong}"
ItemDoubleClicked="{Binding PlayCommand}"/>
</StackLayout>
<hs:HostSelector
Grid.Row="0"

View File

@ -8,6 +8,7 @@ using Aurora.Proto.General;
using Aurora.Proto.Party;
using Aurora.Proto.Events;
using Aurora.Services.ClientService;
using Aurora.Services.PlayerService;
using Aurora.Models.Media;
namespace Aurora.Design.Views.Party
@ -24,8 +25,8 @@ namespace Aurora.Design.Views.Party
private PartyState _state;
private string _hostname;
private ObservableCollection<PartyMember> _members;
private ObservableCollection<RemoteMediaData> _queue;
private ObservableCollection<BaseMedia> _queue;
private BaseMedia _selectedSong;
public PartyViewModel()
{
@ -33,10 +34,12 @@ namespace Aurora.Design.Views.Party
this.HostCommand = new Command(OnHostExecute, CanHostExecute);
_members = new ObservableCollection<PartyMember>();
_queue = new ObservableCollection<RemoteMediaData>();
_queue = new ObservableCollection<BaseMedia>();
SetState(PartyState.SelectingHost);
PlayCommand = new Command(PlayExecute);
//Hook up event handler
ClientService.Instance.EventReceived += this.OnEventReceived;
}
@ -70,7 +73,7 @@ namespace Aurora.Design.Views.Party
get { return _state != PartyState.SelectingHost; }
}
public ObservableCollection<RemoteMediaData> Queue
public ObservableCollection<BaseMedia> Queue
{
get
{
@ -94,6 +97,14 @@ namespace Aurora.Design.Views.Party
set { SetProperty(ref _hostname, value); }
}
public BaseMedia SelectedSong
{
get { return _selectedSong; }
set { SetProperty(ref _selectedSong, value); }
}
public Command PlayCommand { get; private set; }
#endregion Properties
#region Events
@ -209,9 +220,21 @@ namespace Aurora.Design.Views.Party
QueueResponse queueResponse = ClientService.Instance.RemotePartyClient.GetQueue(new Empty());
Queue.Clear();
//Convert received data to remote audio models
foreach (RemoteMediaData data in queueResponse.MediaList)
{
Queue.Add(data);
//Assign received metadata (since this can't be aquired from a file)
AudioMetadata meta = new AudioMetadata();
meta.Title = data.Title;
meta.Album = data.Album;
meta.Artist = data.Artist;
meta.Duration = data.Duration;
RemoteAudio remote = new RemoteAudio(data.Id,
meta,
ClientService.Instance.RemotePartyClient);
Queue.Add(remote);
}
}
catch (Exception ex)
@ -245,6 +268,11 @@ namespace Aurora.Design.Views.Party
Members.Add(member);
}
public void PlayExecute()
{
PlayerService.Instance.LoadMedia(_selectedSong);
PlayerService.Instance.Play();
}
#endregion Private Methods
}
}