Advertisement
Vladislav8653

код вьетнамца с игта

May 26th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. {
  2. TDDung - Vietnam, Oct 2021
  3. }
  4.  
  5. unit Main;
  6.  
  7. interface
  8.  
  9. uses
  10. System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  11. FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  12. FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects;
  13.  
  14. type
  15. TForm1 = class(TForm)
  16. Button1: TButton;
  17. Button2: TButton;
  18. Button3: TButton;
  19. Rectangle1: TRectangle;
  20. procedure FormCreate(Sender: TObject);
  21. procedure FormDestroy(Sender: TObject);
  22. procedure Button1Click(Sender: TObject);
  23. procedure Button2Click(Sender: TObject);
  24. procedure Button3Click(Sender: TObject);
  25. private
  26. { Private declarations }
  27. public
  28. { Public declarations }
  29. end;
  30.  
  31. var
  32. Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.fmx}
  37.  
  38. uses StrUtils, Bass, BassEnc, BassEnc_MP3;
  39.  
  40. var
  41. Channel: HRECORD;
  42. FilePath: string;
  43.  
  44. function RecordingCallback(Handle: HRECORD; buffer: Pointer; length: DWORD; user: Pointer): boolean; stdcall;
  45. begin
  46. Result := True;
  47. end;
  48.  
  49. procedure TForm1.FormCreate(Sender: TObject);
  50. begin
  51. {$IFDEF ANDROID}
  52. if PermissionsService.IsPermissionGranted('android.permission.RECORD_AUDIO') then
  53. Button1.Enabled:= True
  54. else
  55. PermissionsService.RequestPermissions(['android.permission.RECORD_AUDIO'],
  56. procedure(const APermissions: TArray<string>; const AGrantResults: TArray<TPermissionStatus>)
  57. begin
  58. if Length(AGrantResults) = 1 then
  59. case AGrantResults[0] of
  60. TPermissionStatus.Granted: Button1.Enabled:= True;
  61. TPermissionStatus.Denied:
  62. TDialogService.ShowMessage('Cannot record audio without the relevant permission being granted');
  63. TPermissionStatus.PermanentlyDenied:
  64. TDialogService.ShowMessage('If you decide you wish to use the audio recording feature of this app, please go to app settings and enable the microphone permission');
  65. end
  66. else
  67. TDialogService.ShowMessage('Something went wrong with the permission checking');
  68. end,
  69. procedure(const APermissions: TArray<string>; const APostRationaleProc: TProc)
  70. begin
  71. TDialogService.ShowMessage('We first need to be given permission to record audio with your device',
  72. procedure(const AResult: TModalResult)
  73. begin
  74. APostRationaleProc;
  75. end);
  76. end);
  77. {$ELSE}
  78. Button1.Enabled:= True;
  79. {$ENDIF}
  80.  
  81. FilePath:= '';
  82. {$IF DEFINED(ANDROID) OR DEFINED(MACOS)}
  83. FilePath:= IncludeTrailingPathDelimiter(TPath.GetPublicPath);
  84. {$ENDIF}
  85. {$IF DEFINED(IOS)}
  86. FilePath:= IncludeTrailingPathDelimiter(TPath.GetHomePath) + 'Documents/';
  87. {$ENDIF}
  88. end;
  89.  
  90. procedure TForm1.FormDestroy(Sender: TObject);
  91. begin
  92. BASS_RecordFree;
  93. BASS_Free;
  94. end;
  95.  
  96. procedure TForm1.Button1Click(Sender: TObject);
  97. begin
  98. Button1.Enabled:= False;
  99. if BASS_IsAvailable and BassEncMP3_IsAvailable then
  100. Rectangle1.Enabled:= True
  101. else
  102. Button1.Text:= 'FAILED';
  103. end;
  104.  
  105. procedure TForm1.Button2Click(Sender: TObject);
  106. begin
  107. Button2.Enabled:= False;
  108. if not BASS_RecordInit(-1) then
  109. ShowMessage('Cannot start default recording device!')
  110. else
  111. begin
  112. Channel:= BASS_RecordStart(44100, 2, 0, @RecordingCallback, nil);
  113. if Channel = 0 then
  114. ShowMessage('Couldn''t start recording!')
  115. else
  116. begin
  117. BASS_Encode_MP3_StartFile(Channel, '', BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar(FilePath + 'MP3Rec.mp3'));
  118. Button3.Enabled:= True;
  119. end;
  120. end;
  121. end;
  122.  
  123. procedure TForm1.Button3Click(Sender: TObject);
  124. begin
  125. BASS_ChannelStop(Channel);
  126. BASS_RecordFree;
  127. Button3.Enabled:= False;
  128. Button2.Enabled:= True;
  129. end;
  130.  
  131. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement