Created
August 12, 2021 15:40
-
-
Save rdelrosario/978063d3e79f4d7bc6ef2ae99a258a60 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 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