Skip to content

Instantly share code, notes, and snippets.

View rdelrosario's full-sized avatar

Rendy Del Rosario rdelrosario

View GitHub Profile
<?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}"
public class MainViewModel : INotifyPropertyChanged {
...
public TimeSpan Position { get; set; }
public MainViewModel() {
...
_videoPlayerStateMachine.Configure(VideoState.Playing)
.OnActivate(OnStateEntry)
.OnEntry(OnStateEntry)
.Permit(VideoTrigger.Pause, VideoState.Paused)
public enum VideoTrigger
{
Play,
Stop,
Pause,
Forward,
Rewind
}
<?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">
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);
}
public MainViewModel()
{
...
_videoPlayerStateMachine.Activate();
}
public class MainViewModel
{
public ICommand TriggerCommand { get; }
public ICommand VideoActionCommand { get; set; }
public MainViewModel()
{
...
TriggerCommand = new Command<VideoTrigger>(OnTrigger);;
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);
public class MainViewModel
{
public MainViewModel()
{
_videoPlayerStateMachine = new StateMachine<VideoState, VideoTrigger>(CanAutoPlay ? VideoState.Playing: VideoState.Idle);
}
private StateMachine<VideoState, VideoTrigger> _videoPlayerStateMachine;
}
}
public enum VideoTrigger
{
Play,
Stop,
Pause,
Forward,
Rewind
}