FMX.MusicPlayer Sample
This sample illustrates basic music player functionality in a Multi-Device Application.
Contents
Location
You can find the MusicPlayer sample project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and navigate to:
Object Pascal\Multi-Device Samples\Media\MusicPlayer
CPP\Multi-Device Samples\Media\MusicPlayer
- 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 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
- Navigate to the one of the locations given above, and open:
- Delphi: FMMusicPlayer.dproj
- C++: FMMusicPlayer.cbproj
- Press F9 or choose Run > Run.
- Click an item from the list on your mobile device.
- Click the Play button.
- Click the Pause button to pause the song, or the Stop button to stop playing the song.
- Click the Previous button, or the Next button to go through the list items.
- On the top toolbar, click the Settings SpeedButton.
- Check an item from the Repeat Modes list: All, One, None, or Default.
- Check the TSwitch control to enable Shuffle Mode.
- Use the VolumeTrackBar to adjust the volume for the music player.
- Check an item from the Repeat Modes list: All, One, None, or Default.
- 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
- FireMonkey MobileApplication
- Building a Basic Media Player
- Using Tab Components to Display Pages in an iOS Application
- Using ListBox Components to Display a Table View in an iOS Application
Samples
- FireMonkey Media Player HD sample
- FireMonkey Play Audio File sample
- FireMonkey Audio Rec-Play sample