Player working for party view

This commit is contained in:
watsonb8 2019-11-08 20:25:36 -05:00
parent 63efcdad69
commit 426a368385

View File

@ -27,7 +27,8 @@ namespace Aurora.Design.Views.Party
private string _hostname; private string _hostname;
private ObservableCollection<PartyMember> _members; private ObservableCollection<PartyMember> _members;
private ObservableCollection<BaseMedia> _queue; private ObservableCollection<BaseMedia> _queue;
private BaseMedia _selectedSong; private BaseMedia _selectedMedia;
private PlayerService _player;
public PartyViewModel() public PartyViewModel()
{ {
@ -38,6 +39,7 @@ namespace Aurora.Design.Views.Party
_queue = new ObservableCollection<BaseMedia>(); _queue = new ObservableCollection<BaseMedia>();
SetState(PartyState.SelectingHost); SetState(PartyState.SelectingHost);
this._player = PlayerService.Instance;
PlayCommand = new Command(OnPlayExecute); PlayCommand = new Command(OnPlayExecute);
@ -119,8 +121,8 @@ namespace Aurora.Design.Views.Party
/// <value></value> /// <value></value>
public BaseMedia SelectedSong public BaseMedia SelectedSong
{ {
get { return _selectedSong; } get { return _selectedMedia; }
set { SetProperty(ref _selectedSong, value); } set { SetProperty(ref _selectedMedia, value); }
} }
/// <summary> /// <summary>
@ -227,15 +229,13 @@ namespace Aurora.Design.Views.Party
try try
{ {
//Execute task without waiting SetState(PartyState.Hosting);
await ClientService.Instance.GetEvents().ConfigureAwait(false); await ClientService.Instance.GetEvents().ConfigureAwait(true);
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("Exception occurred while receiviing events: ", ex.Message); Console.WriteLine("Exception occurred while receiviing events: ", ex.Message);
} }
SetState(PartyState.Hosting);
} }
private bool CanHostExecute() private bool CanHostExecute()
@ -339,8 +339,26 @@ namespace Aurora.Design.Views.Party
public override async void OnPlayExecute() public override async void OnPlayExecute()
{ {
await PlayerService.Instance.LoadMedia(_selectedSong).ConfigureAwait(true); base.Media = this._selectedMedia;
PlayerService.Instance.Play(); if (!_player.IsMediaLoaded(base.Media))
{
await _player.LoadMedia(base.Media).ConfigureAwait(true);
}
_player.Play();
switch (_player.PlaybackState)
{
case PlaybackState.Buffering:
{
_player.Play();
break;
}
case PlaybackState.Playing:
{
_player.Pause();
break;
}
}
} }
public override bool CanPlayExecute() public override bool CanPlayExecute()