unit uPlayer;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants, FMX.Styles, IdHTTPWebBrokerBridge, IdGlobal, Web.HTTPApp,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  FMX.Controls.Presentation, FMX.Layouts, FMX.ListBox, uPlayerThread,
  bass_simple, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo, FMX.Edit;

type
  TfPlayer = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    mp: TBassSimple;

    Player: TPlayerThread;
    FServer: TIdHTTPWebBrokerBridge;
    procedure StartServer;
  public
    { Public declarations }
  end;

var
  fPlayer: TfPlayer;

implementation

{$R *.fmx}

function GetPathToTestExe: string; // вернет папку romaming
begin
  Result := GetEnvironmentVariable('APPDATA');
  if Result <> '' then
    Result := IncludeTrailingPathDelimiter(Result);
end;

procedure TfPlayer.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FServer.Active := False;
  FServer.Bindings.Clear;
end;

procedure TfPlayer.FormCreate(Sender: TObject);
var
  theme: string;
begin
  theme := ParamStr(1);
  if theme <> '' then
  begin
    TStyleManager.SetStyleFromFile(GetPathToTestExe + 'TTW_Bot\stl\' + theme);
  end;
  FServer := TIdHTTPWebBrokerBridge.Create(Self);
  StartServer;
end;

procedure TfPlayer.StartServer;
begin
  if not FServer.Active then
  begin
    FServer.Bindings.Clear;
    FServer.DefaultPort := 8088;
    FServer.Active := True;
  end;
end;

end.
