Created
February 19, 2019 09:45
-
-
Save ufukhawk/bee95cc6dc4636ac3b505185e7b559ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AudioPlayerViewModel: INotifyPropertyChanged | |
{ | |
private IAudioPlayerService _audioPlayer; | |
private bool _isStopped; | |
public event PropertyChangedEventHandler PropertyChanged; | |
public AudioPlayerViewModel(IAudioPlayerService audioPlayer) | |
{ | |
_audioPlayer = audioPlayer; | |
_audioPlayer.OnFinishedPlaying = () => { | |
_isStopped = true; | |
CommandText = "Play"; | |
}; | |
CommandText = "Play"; | |
_isStopped = true; | |
} | |
private string _commandText; | |
public string CommandText | |
{ | |
get { return _commandText;} | |
set | |
{ | |
_commandText = value; | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CommandText")); | |
} | |
} | |
private ICommand _playPauseCommand; | |
public ICommand PlayPauseCommand | |
{ | |
get | |
{ | |
return _playPauseCommand ?? (_playPauseCommand = new Command( | |
(obj) => | |
{ | |
if (CommandText == "Play") | |
{ | |
if (_isStopped) | |
{ | |
_isStopped = false; | |
_audioPlayer.Play("Galway.mp3"); | |
} | |
else | |
{ | |
_audioPlayer.Play(); | |
} | |
CommandText = "Pause"; | |
} | |
else | |
{ | |
_audioPlayer.Pause(); | |
CommandText = "Play"; | |
} | |
})); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment