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

Create Robust Core Music Player Functionality For Windows In Delphi With FMX Sample

The MusicPlayer application uses controls such as TProgressBar, and TTrackBar, and platform-specific technologies such as MPMusicPlayerController for iOS, to show how to create a music player.

Your device needs to have at least one song so that you can see the application functionality. The sample allows the audio files listing and standard media controls like play, pause, and volume.

Note: The FireMonkey library contains a TMediaPlayer component that you can use instead of writing your own media player. The FMX.MediaPlayerHD Sample shows how to use TMediaPlayer.

Location

You can find the MusicPlayer sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and navigate to:
    • Object PascalMulti-Device SamplesMediaMusicPlayer
    • CPPMulti-Device SamplesMediaMusicPlayer
  • 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.

Learn more about AIMP and some of the most inviting features of this audio player and organizer according to its developer.

How to Use the Sample

  1. Navigate to the one of the locations given above, and open:
    • Delphi: FMMusicPlayer.dproj
    • C++: FMMusicPlayer.cbproj
  2. Press F9 or choose Run > Run.
  3. Click an item from the list on your mobile device.
  4. Click the Play button.

5. Click the Pause button to pause the song, or the Stop button to stop playing the song.

6. Click the Previous button, or the Next button to go through the list items.

7. On the top toolbar, click the SettingsSpeedButton.

  • Check an item from the Repeat Modes listAllOneNone, or Default.
  • Check the TSwitch control to enable Shuffle Mode.
  • Use the VolumeTrackBar to adjust the volume for the music player.

8. Click the Back SpeedButton to go back to the song list.

Files

FileContains
MediaPlayerUContains the base form.
MediaPlayerThe project itself.

Classes

TFMXMusicPlayerFrm is the form of the application. This class contains objects like: TActionListTTabControlTTimerTSpeedButton, or TTrackBar.

Implementation

  • The GetSongsFromLibrary procedure is used to populate PlayListBox with the songs from the library device. It shows the title and the artist of each song.
  • The application components are placed on the TabItem1 and TabItem2 pages. You can change between the two pages by setting the ActiveTab property of the TabControl1. Each TabItem of the application has an attached action.
  • The SongProgressBar value is calculated in the OnTimer event of TTimer based on the MPMediaItemPropertyPlaybackDuration and currentPlaybackTime methods results.

Fore more details and more links to other sample, please visit the link below:

Head over and check out the full Delphi source code for a music player on GitHub.

Head over and check out the full C++ source code for a music player on GitHub.

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

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

Leave a Reply

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

IN THE ARTICLES