FMX.AudioRecPlay Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to record some sound via the microphone of your device and then playback it using the device speakers or headphones.

Location

You can find the AudioRecPlay sample project at:

  • Start | Programs | Embarcadero RAD Studio Rio | Samples and then navigate to:
    • Object Pascal\Mobile Snippets\AudioRecPlay
    • CPP\Mobile Snippets\AudioRecPlay
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

The AudioRecPlay sample shows you how to record some sound via the microphone of your iOS or Android device. Then you can reproduce the recorded sound. The sample uses the TAudioCaptureDevice class and its methods StartCapture and StopCapture to record the sound. Moreover, it uses the nonvisual TMediaPlayer component to playback the recorded sound.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: AudioRecPlay.dproj.
    • C++: AudioRecPlay.cbproj.
  2. Select the target platform, iOS and Android supported.
  3. Press F9 or choose Run > Run.
  4. Interact with the sample:
    • Click on the Start Recording button to start recording some sound.
    • Click on the Stop Recording button to stop the recording.
    • Click on the Play button to reproduce the recorded sound.
    • Click on the Stop button to stop the reproduction of the recorded sound.

Files

File in Delphi File in C++ Contains

AudioRecPlay.dproj

AudioRecPlay.cbproj

The project itself.

AudioRecPlay.fmx

AudioRecPlay.fmx

The main form where the components are located.

uMain.pas

AudioRecPlayPCH.h, AudioRecPlay.cpp

Used to define and implement the sample.

Information.txt

Information.txt

Further information about the sample.

Classes

TAudioRecPlayForm is the main form that represents the main window of the sample. It contains the following components:

Implementation

  • The sample uses TActionList to maintain a list of actions that can be used by other components (tool buttons in this sample).
  • The sample uses TButton to implement four buttons to enable and disable the recording or the playback of audio files.
  • The sample uses TAudioCaptureDevice to define an audio capture device. TAudioCaptureDevice extends the TCaptureDevice implementation to add specific behavior for audio capturing devices (like microphones).
  • The sample uses TMediaPlayer component for easy access to media files.
    • The sample uses Play to start playing a media file.
    • The sample uses Stop to stop or pause a running media file.

When you run the aplication, the sample shows a picture of a microphone and two ToolBars, one aligned at the bottom and the other aligned at the top of your FireMonkey form. Each ToolBar contains two TButtons. The bottom aligned ToolBar contains the Start Recording and Stop Recording buttons, while the top aligned ToolBar contains the Play and Stop buttons. When you click on the Start Recording button, the StartCapture method starts capturing data until you click on the Stop Recording button. Then if you press the Play button, the sample starts to playback the recorded sound. Finally you can press the Stop button to stop the playback of the recording sound.

Uses

See Also

Samples