Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class AudioPlayerViewModel: INotifyPropertyChanged
  2. {
  3. private IAudioPlayerService _audioPlayer;
  4. private bool _isStopped;
  5. public event PropertyChangedEventHandler PropertyChanged;
  6.  
  7. public AudioPlayerViewModel(IAudioPlayerService audioPlayer)
  8. {
  9. _audioPlayer = audioPlayer;
  10. _audioPlayer.OnFinishedPlaying = () => {
  11. _isStopped = true;
  12. CommandText = "Play";
  13. };
  14. CommandText = "Play";
  15. _isStopped = true;
  16. }
  17.  
  18. private string _commandText;
  19. public string CommandText
  20. {
  21. get { return _commandText;}
  22. set
  23. {
  24. _commandText = value;
  25. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CommandText"));
  26. }
  27. }
  28.  
  29. private ICommand _playPauseCommand;
  30. public ICommand PlayPauseCommand
  31. {
  32. get
  33. {
  34. return _playPauseCommand ?? (_playPauseCommand = new Command(
  35. (obj) =>
  36. {
  37. if (CommandText == "Play")
  38. {
  39. if (_isStopped)
  40. {
  41. _isStopped = false;
  42. _audioPlayer.Play("Galway.mp3");
  43. }
  44. else
  45. {
  46. _audioPlayer.Play();
  47. }
  48. CommandText = "Pause";
  49. }
  50. else
  51. {
  52. _audioPlayer.Pause();
  53. CommandText = "Play";
  54. }
  55. }));
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement