Está en la página 1de 3

Audio Recording - RAD Studio

http://docwiki.embarcadero.com/RADStudio/XE5/en/Audio_Recording

Show: Delphi C++ Display Preferences

Audio Recording
From RAD Studio Go Up to Tutorial: FireMonkey Audio-Video This tutorial demonstrates how to use FireMonkey to capture audio media data.

Contents
1 Supported File Formats 2 Form Design 3 Implementation 4 Run the Application 5 Previous 6 Next 7 See Also

Supported File Formats


We recommend that you save and use media files in the following formats according to the platform:
.wav .caf .3gp

on Windows on iOS and Mac OS X on Android

You also can play other types of media files, such as MP3 files.

Form Design
1. Select File > New > FireMonkey Desktop Application - Delphi > HD FireMonkey Application. 2. Add a TGridLayout to the form. With the layout in focus, make the following settings in the Object Inspector: Align to alMostTop. ItemWidth to half of the total width of the form. 3. Add two TFlowLayout objects to the TGridLayout (the second flow layout will be used in the next tutorial: Playing Audio Files). 4. Add the following to the first TFlowLayout: A TLabel. Set its text to Capturing. A TButton to start recording data. A TButton to stop recording data. 5. Change the name of the two buttons to RecordButton and StopButton. 6. Set the StopButton as disabled by setting the Enable property of the button to False.

1 of 3

12/23/2013 4:55 PM

Audio Recording - RAD Studio

http://docwiki.embarcadero.com/RADStudio/XE5/en/Audio_Recording

7. Add a TSaveDialog to the form. 8. Add a TImage. Set the Bitmap property of the TImage to an image that is suggestive for the recording process. The usual icon used for a recording process is a red circle. The form should look like this:

Implementation
1. Include the FMX.Media unit in the uses section:
// Delphi version of the implementation uses FMX.Media;

2. Declare a TAudioCaptureDevice public member, named Mic, to the TForm1 class:


type TForm1 = class(TForm) // ............... public Mic: TAudioCaptureDevice;

3. Set the Opacity property of the image to 0. The image is visible only when the recording process starts. 4. Double-click the Record button to attach OnClick event handlers to it:
procedure TForm1.RecordButtonClick(Sender: TObject); begin ///Get the default microphone Mic := TCaptureDeviceManager.Current.DefaultAudioCaptureDevice; if Mic <> nil then begin //Set the SaveDialog filter to choose only the supported extension SaveDialog1.Filter := Mic.FilterString; if SaveDialog1.Execute then begin RecordButton.Enabled := false; StopButton.Enabled := true; //Gets the name of the file where to save the recorded data Mic.FileName := SaveDialog1.FileName; Mic.StartCapture; Image1.Opacity:=1; end; end else begin ShowMessage('Audio capturing device not available'); end;

2 of 3

12/23/2013 4:55 PM

Audio Recording - RAD Studio end;

http://docwiki.embarcadero.com/RADStudio/XE5/en/Audio_Recording

5. Double-click the Stop button to attach OnClick event handlers to the Stop button:
procedure TForm1.StopButtonClick(Sender: TObject); begin if (Mic <> nil) and (Mic.State = TCaptureDeviceState.Capturing) then begin Mic.StopCapture; Image1.Opacity := 0; StopButton.Enabled := false; RecordButton.Enabled := true; end; end;

Run the Application


1. To run the project, press F9. 2. To start recording audio data, press the Record button. The SaveDialog opens. 3. Choose a path and a file name to save the recorded data. 4. To stop recording, press the Stop button. If the recording is not ended by calling the StopCapture method, the saved file is not properly decoded when it is played by a media player.

Previous
Video Capturing

Next
Playing Audio Files

See Also
Creating a FireMonkey Component (Delphi) Creating a FireMonkey Component (C++) HD FireMonkey Application FireMonkey Layouts Strategies Audio-Video in FireMonkey Retrieved from "http://docwiki.embarcadero.com/RADStudio/XE5/e/index.php?title=Audio_Recording& oldid=210221" Category: Delphi This page was last modified on 25 October 2013, at 16:58. Help Feedback

3 of 3

12/23/2013 4:55 PM

También podría gustarte