FMX.MusicPlayer Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample illustrates basic music player functionality in a Multi-Device Application.

Location

You can find the MusicPlayer sample project at:

Description

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.

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.

    IMG 0016.PNG
  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 Settings SpeedButton.
    • Check an item from the Repeat Modes list: All, One, None, or Default.

    IMG 0017.PNG
    • 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

File Contains

MediaPlayerU

Contains the base form.

MediaPlayer

The project itself.

Classes

TFMXMusicPlayerFrm is the form of the application. This class contains objects like: TActionList, TTabControl, TTimer, TSpeedButton, 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.

Uses

See Also

Samples

Personal tools
Assistance