This repository has been archived on 2020-12-20. You can view files and clone it, but cannot push or open issues or pull requests.
aurora-sharp-desktop/Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs
watsonb8 93be6dc100 See commit description for changes
Added PageContainer to dynamically load pages within the main content. Added player component to control music playback(Half functional). Added playback changed event not the player service.
2019-05-24 10:27:19 -04:00

109 lines
2.8 KiB
C#

using System;
using Xamarin.Forms;
using Aurora.Frontend.Views;
using Aurora.Backend.Services.PlayerService;
namespace Aurora.Frontend.Components.MediaPlayer
{
public class PlayerViewModel : BaseViewModel
{
PlayerService _playerService;
public PlayerViewModel()
{
_playerService = PlayerService.Instance;
_playerService.PlaybackStateChanged += OnPlaybackStateChanged;
PlayCommand = new Command(OnPlayExecute, CanPlayExecute);
PreviousCommand = new Command(OnPreviousExecute, CanPreviousExecute);
NextCommand = new Command(OnNextExecute, CanNextExecute);
}
~PlayerViewModel()
{
}
#region Public Properties
public Command PlayCommand { get; private set; }
public Command NextCommand { get; private set; }
public Command PreviousCommand { get; private set; }
public string PlayButtonText
{
get { return PlayerService.Instance.PlaybackState == PlaybackState.Buffering ? "Play" : "Pause"; }
}
#endregion Public Properties
#region Public Methods
public bool CanPreviousExecute()
{
return true;
}
public void OnPreviousExecute()
{
}
public bool CanPlayExecute()
{
switch (_playerService.PlaybackState)
{
case PlaybackState.Buffering:
{
return true;
}
case PlaybackState.Playing:
{
return true;
}
case PlaybackState.Stopped:
{
return false;
}
}
return false;
}
public void OnPlayExecute()
{
switch (_playerService.PlaybackState)
{
case PlaybackState.Buffering:
{
_playerService.Play();
break;
}
case PlaybackState.Playing:
{
_playerService.Pause();
break;
}
}
}
public bool CanNextExecute()
{
return true;
}
public void OnNextExecute()
{
}
#endregion public Methods
#region EventHandlers
public void OnPlaybackStateChanged(object sender, PlaybackStateChangedEventArgs args)
{
OnPropertyChanged("PlayButtonText");
PlayCommand.ChangeCanExecute();
NextCommand.ChangeCanExecute();
PreviousCommand.ChangeCanExecute();
}
#endregion EventHandlers
}
}