class sampleUIVideoPlayer extends inkLogicController
{
	editable var videoWidgetPath : CName;
	editable var counterWidgetPath : CName;
	editable var lastFramePath : CName;
	editable var currentFramePath : CName;
	private var videoWidget : weak< inkVideo >;
	private var framesToSkipCounterWidget : weak< inkText >;
	private var lastFrameWidget : weak< inkText >;
	private var currentFrameWidget : weak< inkText >;
	private var m_numberOfFrames : Uint32;

	protected event OnInitialize()
	{
		videoWidget = ( ( inkVideo )( GetWidget( videoWidgetPath ) ) );
		framesToSkipCounterWidget = ( ( inkText )( GetWidget( counterWidgetPath ) ) );
		lastFrameWidget = ( ( inkText )( GetWidget( lastFramePath ) ) );
		currentFrameWidget = ( ( inkText )( GetWidget( currentFramePath ) ) );
		UpdateCounter();
		UpdateTextWidgets();
	}

	public function PlayPauseVideo( e : inkPointerEvent )
	{
		if( videoWidget.IsPlayingVideo() )
		{
			if( videoWidget.IsPaused() )
			{
				videoWidget.Resume();
			}
			else
			{
				videoWidget.Pause();
			}
		}
		else
		{
			videoWidget.Play();
		}
		UpdateTextWidgets();
	}

	public function StopVideo( e : inkPointerEvent )
	{
		videoWidget.Stop();
	}

	public function PauseVideo( e : inkPointerEvent )
	{
		videoWidget.Pause();
		UpdateTextWidgets();
	}

	public function ResumeVideo( e : inkPointerEvent )
	{
		videoWidget.Resume();
		UpdateTextWidgets();
	}

	public function Rewind( e : inkPointerEvent )
	{
		videoWidget.RewindTo( m_numberOfFrames );
		UpdateTextWidgets();
	}

	public function FastForward( e : inkPointerEvent )
	{
		videoWidget.FastForwardTo( m_numberOfFrames );
		UpdateTextWidgets();
	}

	public function JumpToFrame( e : inkPointerEvent )
	{
		videoWidget.JumpToFrame( m_numberOfFrames );
		UpdateTextWidgets();
	}

	public function JumpToTime( e : inkPointerEvent )
	{
		videoWidget.JumpToTime( ( ( Float )( m_numberOfFrames ) ) );
		UpdateTextWidgets();
	}

	public function RiseFramesCounter( e : inkPointerEvent )
	{
		m_numberOfFrames += ( ( Uint32 )( 1 ) );
		UpdateCounter();
	}

	public function LowerFramesCounter( e : inkPointerEvent )
	{
		m_numberOfFrames -= ( ( Uint32 )( 1 ) );
		UpdateCounter();
	}

	private function UpdateTextWidgets()
	{
		var videoSummary : VideoWidgetSummary;
		videoSummary = videoWidget.GetVideoWidgetSummary();
		currentFrameWidget.SetText( ( ( String )( videoSummary.currentFrame ) ) );
		lastFrameWidget.SetText( ( ( String )( videoSummary.totalFrames ) ) );
	}

	private function UpdateCounter()
	{
		framesToSkipCounterWidget.SetText( ( ( String )( m_numberOfFrames ) ) );
	}

}

