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
<?xml version="1.0" encoding="utf-8" ?> | |
<ContentPage | |
...> | |
<Label | |
Text="{Binding Position, StringFormat='{}{0:hh\\:mm\\:ss}'}"/> | |
<controls:VideoPlayer | |
AutoPlay="{Binding CanAutoPlay}" | |
Command="{Binding VideoActionCommand}" | |
Position="{Binding Position, Mode=TwoWay}" |
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 : INotifyPropertyChanged { | |
... | |
public TimeSpan Position { get; set; } | |
public MainViewModel() { | |
... | |
_videoPlayerStateMachine.Configure(VideoState.Playing) | |
.OnActivate(OnStateEntry) | |
.OnEntry(OnStateEntry) | |
.Permit(VideoTrigger.Pause, VideoState.Paused) |
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 enum VideoTrigger | |
{ | |
Play, | |
Stop, | |
Pause, | |
Forward, | |
Rewind | |
} |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<ContentPage | |
x:Class="VideoPlayerStateMachine.MainPage" | |
xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:controls="clr-namespace:VideoPlayerStateMachine.Controls" | |
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" | |
xmlns:local="clr-namespace:VideoPlayerStateMachine" | |
xmlns:viewModels="clr-namespace:VideoPlayerStateMachine.ViewModels" | |
ios:Page.UseSafeArea="true"> |
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 VideoPlayer : MediaElement | |
{ | |
public static readonly BindableProperty CommandProperty = | |
BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(VideoPlayer), defaultBindingMode: BindingMode.OneWayToSource); | |
public ICommand Command | |
{ | |
get => (ICommand) GetValue(CommandProperty); | |
set => SetValue(CommandProperty, value); | |
} |
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 MainViewModel() | |
{ | |
... | |
_videoPlayerStateMachine.Activate(); | |
} |
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 ICommand TriggerCommand { get; } | |
public ICommand VideoActionCommand { get; set; } | |
public MainViewModel() | |
{ | |
... | |
TriggerCommand = new Command<VideoTrigger>(OnTrigger);; |
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); |
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); | |
} | |
private StateMachine<VideoState, VideoTrigger> _videoPlayerStateMachine; | |
} | |
} |
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 enum VideoTrigger | |
{ | |
Play, | |
Stop, | |
Pause, | |
Forward, | |
Rewind | |
} |