unit uMain;

interface

{$I DPF.iOS.Defs.inc}

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  FMX.Types,
  FMX.Forms,
  FMX.Controls,
  FMX.Dialogs,

{$IFDEF DELPHIXE5} FMX.Graphics, {$ENDIF}
  DPF.iOS.Common,
  DPF.iOS.BaseControl,
  DPF.iOS.UIView,
  DPF.iOS.UIButton,
  DPF.iOS.Media,
  DPF.iOS.UIToolbar,
  DPF.iOS.UIImageView,
  DPF.iOS.MPMoviePlayerViewController,
  DPF.iOS.UIProgressView, DPF.iOS.UISwitch, DPF.iOS.UILabel;

type
  TFLabels = class( TForm )
    DPFUIView1: TDPFUIView;
    DPFCamera1: TDPFCamera;
    DPFUIViewPreview: TDPFUIView;
    DPFToolbar1: TDPFToolbar;
    DPFButtonStart: TDPFButton;
    DPFButtonStop: TDPFButton;
    DPFMPMoviePlayerViewController1: TDPFMPMoviePlayerViewController;
    DPFButton1: TDPFButton;
    DPFProgress1: TDPFProgress;
    DPFSwitch1: TDPFSwitch;
    DPFLabel1: TDPFLabel;
    procedure DPFButtonStartClick( Sender: TObject );
    procedure DPFButtonStopClick( Sender: TObject );
    procedure DPFButton1Click( Sender: TObject );
    procedure DPFCamera1ConvertComplete( Sender: TObject; Status: Integer );
    procedure DPFCamera1ConvertProgress( Sender: TObject; Progress: Single );
    procedure DPFSwitch1Changed( Sender: TObject; ISON: Boolean );
  private
    { Private declarations }
  protected
    procedure PaintRects( const UpdateRects: array of TRectF ); override;
  public
    { Public declarations }
  end;

var
  FLabels: TFLabels;

implementation

{$R *.fmx}

procedure TFLabels.DPFButton1Click( Sender: TObject );
begin
  if DPFCamera1.isRecording then
    exit;

  DPFMPMoviePlayerViewController1.MoviePath := DPFCamera1.OutputFileName;
  DPFMPMoviePlayerViewController1.Play;
end;

procedure TFLabels.DPFButtonStartClick( Sender: TObject );
var
  FileName: string;
begin
  DPFProgress1.Value := 0;
  FileName           := GetTempDirectory;
  ForceDirectories( FileName );
  RemoveFile( FileName + 'temp.mov' );
  DPFCamera1.OutputFileName := FileName + 'temp.mov';
  DPFCamera1.StartRecording;
end;

procedure TFLabels.DPFButtonStopClick( Sender: TObject );
begin
  DPFCamera1.StopRecording;
end;

// ------------------------------------------------------------------------------
// Status:
// 0 = Unknown
// 1 = Waiting
// 2 = Exporting;
// 3 = Completed;
// 4 = Failed
// 5 = Cancelled
// ------------------------------------------------------------------------------
procedure TFLabels.DPFCamera1ConvertComplete( Sender: TObject; Status: Integer );
begin
  if Status = 3 then
    ShowMessage( 'Convert Completed ' )
  else
    ShowMessage( 'Convert Stause: ' + Status.ToString );
end;

procedure TFLabels.DPFCamera1ConvertProgress( Sender: TObject; Progress: Single );
begin
  DPFProgress1.Value := Progress;
end;

procedure TFLabels.DPFSwitch1Changed( Sender: TObject; ISON: Boolean );
begin
  DPFCamera1.ConvertToMP4 := ISON;
end;

procedure TFLabels.PaintRects( const UpdateRects: array of TRectF );
begin
  { }
end;

end.
