Moved music playing controls from individual viewmodels to main view
This commit is contained in:
@ -6,8 +6,8 @@
|
||||
x:Class="Aurora.Design.Views.Songs.SongsView">
|
||||
<ContentView.Content>
|
||||
<library:Library
|
||||
ItemsSource="{Binding SongsList}"
|
||||
SelectedItem="{Binding SelectedSong}"
|
||||
ItemDoubleClicked="{Binding PlayCommand}"/>
|
||||
ItemsSource="{Binding SongsList}"
|
||||
SelectedItem="{Binding SelectedSong}"
|
||||
ItemDoubleClicked="{Binding DoubleClickCommand}"/>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
@ -1,7 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Aurora.Models.Media;
|
||||
using Aurora.Services;
|
||||
using Aurora.Services.PlayerService;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Design.Views.Songs
|
||||
@ -11,16 +10,14 @@ namespace Aurora.Design.Views.Songs
|
||||
#region Fields
|
||||
private ObservableCollection<BaseMedia> _songsList;
|
||||
private BaseMedia _selectedSong;
|
||||
private PlayerService _player;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Constructor
|
||||
public SongsViewModel()
|
||||
{
|
||||
_player = PlayerService.Instance;
|
||||
_songsList = new ObservableCollection<BaseMedia>();
|
||||
PlayCommand = new Command(OnPlayButtonExecute, CanPlayButtonExecute);
|
||||
DoubleClickCommand = new Command(OnDoubleClickExecute, OnDoubleClickCanExecute);
|
||||
|
||||
Initialize();
|
||||
}
|
||||
@ -40,7 +37,7 @@ namespace Aurora.Design.Views.Songs
|
||||
set { SetProperty(ref _selectedSong, value); }
|
||||
}
|
||||
|
||||
public Command PlayCommand { get; private set; }
|
||||
public Command DoubleClickCommand { get; private set; }
|
||||
|
||||
#endregion Properties
|
||||
|
||||
@ -65,57 +62,24 @@ namespace Aurora.Design.Views.Songs
|
||||
|
||||
public override bool CanPlayButtonExecute()
|
||||
{
|
||||
switch (_player.PlaybackState)
|
||||
{
|
||||
case PlaybackState.Buffering:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
case PlaybackState.Playing:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
case PlaybackState.Stopped:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public async override void OnPlayButtonExecute()
|
||||
public override void OnPlayButtonExecute()
|
||||
{
|
||||
if (_selectedSong == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
base.Media = _selectedSong;
|
||||
if (!_player.IsMediaLoaded(base.Media))
|
||||
if (base.IsPlaying())
|
||||
{
|
||||
await _player.LoadMedia(base.Media).ConfigureAwait(true);
|
||||
base.ChangePlayerState(_selectedSong, Main.PlayAction.Pause);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ChangePlayerState(_selectedSong, Main.PlayAction.Play);
|
||||
}
|
||||
|
||||
switch (_player.PlaybackState)
|
||||
{
|
||||
case PlaybackState.Buffering:
|
||||
{
|
||||
_player.Play();
|
||||
SetIsPlaying(true);
|
||||
break;
|
||||
}
|
||||
case PlaybackState.Playing:
|
||||
{
|
||||
_player.Pause();
|
||||
SetIsPlaying(false);
|
||||
break;
|
||||
}
|
||||
case PlaybackState.Stopped:
|
||||
{
|
||||
_player.Play();
|
||||
SetIsPlaying(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanNextButtonExecute()
|
||||
@ -128,6 +92,21 @@ namespace Aurora.Design.Views.Songs
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void OnDoubleClickExecute()
|
||||
{
|
||||
if (_selectedSong == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.ChangePlayerState(_selectedSong, Main.PlayAction.Play);
|
||||
}
|
||||
|
||||
public bool OnDoubleClickCanExecute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endregion Commands
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user