Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created August 12, 2021 15:40
Show Gist options
  • Save rdelrosario/978063d3e79f4d7bc6ef2ae99a258a60 to your computer and use it in GitHub Desktop.
Save rdelrosario/978063d3e79f4d7bc6ef2ae99a258a60 to your computer and use it in GitHub Desktop.
public class MainViewModel
{
public MainViewModel()
{
_videoPlayerStateMachine = new StateMachine<VideoState, VideoTrigger>(CanAutoPlay ? VideoState.Playing: VideoState.Idle);
_videoPlayerStateMachine.Configure(VideoState.Idle)
.OnActivate(OnStateEntry)
.OnEntry(OnStateEntry)
.Permit(VideoTrigger.Play, VideoState.Playing);
_videoPlayerStateMachine.Configure(VideoState.Playing)
.OnActivate(OnStateEntry)
.OnEntry(OnStateEntry)
.Permit(VideoTrigger.Pause, VideoState.Paused)
.Permit(VideoTrigger.Stop, VideoState.Stopped);
_videoPlayerStateMachine.Configure(VideoState.Paused)
.OnEntry(OnStateEntry)
.Permit(VideoTrigger.Play, VideoState.Playing)
.Permit(VideoTrigger.Stop, VideoState.Stopped);
_videoPlayerStateMachine.Configure(VideoState.Stopped)
.OnEntry(OnStateEntry)
.Permit(VideoTrigger.Play, VideoState.Playing);
}
private void OnStateEntry()
{
Status = $"{_videoPlayerStateMachine.State}";
CanPlay = _videoPlayerStateMachine.CanFire(VideoTrigger.Play);
CanPause = _videoPlayerStateMachine.CanFire(VideoTrigger.Pause);
CanStop = _videoPlayerStateMachine.CanFire(VideoTrigger.Stop);
}
private StateMachine<VideoState, VideoTrigger> _videoPlayerStateMachine;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment