Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!

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:

  • TToolbar
  • 2 TSpeedButtons parented to the toolbar
  • TMediaPlayer

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:

    • Put the mp3 file into the same directory as the project
    • Go to Project-> Deployment and selected ‘All Configurations – iOS Device Platform/iOS Simulator Platform/Android Platform’
    • Click on the ‘Add Files’ icon

      • Browse to your mp3 file
      • Set the Remote Path for your mp3 file



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



      procedure TAudioPlayBackForm.btnPlayClick(Sender: TObject);


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



      procedure TAudioPlayBackForm.btnStopClick(Sender: TObject);







      Coding Boot Camp

      Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
      Design. Code. Compile. Deploy.
      Start Free Trial   Upgrade Today

         Free Delphi Community Edition   Free C++Builder Community Edition

      About author

      Director of Product Management, Developer Tools Idera, Inc.
      Related posts
      C++CodeIDERAD Studio

      How To Compile And Run A C Program In Terminal


      Coding BootCamp 2022

      C++CodeDatabaseDelphiIDERAD Studio

      Windows 10 Mobile App Development Tutorial For Beginners

      CodeDelphiTech Partner

      This Is How To Store Cross Platform App Settings In JSON

      Leave a Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.