Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Playing Audio Clips on Android

I have been working with our R&D team on the samples and snippets for RAD Studio XE5. Our mobile snippets are designed to showcase key functionality with just a couple of lines of code.

Today I thought I would highlight our AudioPlayBack snippet.

This snippet consists of the following 4 components:

The toolbar Align property has been set to alTop. The first SpeedButton (the one to stop the playback) has been set to alLeft, with a Left Margin on 5. The second SpeedButton (the one to play the audio clip) has been set to alRight, with a Right Margin on 5.

Setting alignments and margins for the toolbar buttons automatically centers them vertically which ensures that your UI looks good on both Android and iOS.

For this snippet, I want to be able to play back an existing mp3 file I recorded.

To deploy an audio file with your application, you need to do the following:

Android

iOS

I also created two on-click events for playing the audio clip and stopping playback.

uses

System.iOUtils;

procedure TAudioPlayBackForm.btnPlayClick(Sender: TObject);

begin

MediaPlayer1.FileName := TPath.GetDocumentsPath + PathDelim + ‘soundsample.mp3’;

MediaPlayer1.Play;

end;

procedure TAudioPlayBackForm.btnStopClick(Sender: TObject);

begin

MediaPlayer1.Stop;

end;

end.

Sincerely,

Sarina

Exit mobile version