RTL.MediaPlayer Sample
MediaPlayer is a sample application with a client-server architecture where:
- A client application is a remote control that can find media players (server applications) reachable using app tethering and control them (play/pause and volume control).
- A server application is a media player that you can control from the application itself or remotely using a remote control (client application).
The server application is a FireMonkey application, and the client application is available both as a VCL application and as a FireMonkey application.
The server application is based on the MediaPlayerHD sample application.
Contents
Location
You can find the MediaPlayer project at:
- Start | Programs | Embarcadero RAD Studio 10 Seattle | Samples and then navigate to either of the following folders:
- CPP\RTL\Tethering\MediaPlayer
- Object Pascal\RTL\Tethering\MediaPlayer
- Subversion Repository:
Description
This sample applications folder provides two client projects (VCL and FireMonkey) and a server project. The projects are designed so that you can run any number of instances of each at the same time. Many remote controls (client applications) may connect to the same media player (server application), and any remote control may connect to multiple media players, as long as they are reachable using app tethering.
In the server application (MediaPlayerHD) you have the following controls:
- Load… lets you load a file to play. See Audio-Video in FireMonkey for file support information.
- Play pauses the playback, Pause resumes the playback.
- Clear unloads the currently-loaded media file.
- If Visible is checked, the applications shows the video area. If Visible is not checked, the video is not visible.
- The volume bar lets you adjust the playback volume.
- The top-right corner shows information about the dimensions (
nxnpx) and the duration (ns) of the loaded media file.
In the client application (MediaPlayerCommand or MediaPlayerVCLCommand) you have the following controls:
- You can click Find Players to fill the list on top with reachable media players (server applications).
- On the media player selected on the top list:
- Play pauses the playback, Pause resumes the playback.
- The volume bar lets you adjust the playback volume.
How to Use the Sample
- Navigate to the location given above and open MediaPlayerHD\MediaPlayerHD.dproj or MediaPlayerHD\MediaPlayerHD.cbproj.
- On the Project Manager:
- Double click the server application entry MediaPlayerHD.
- Select Run > Run to run the server application.
- Double click one of the client application entries, MediaPlayerCommand or MediaPlayerVCLCommand.
- Select Run > Run to run the selected client application.
- Note: You can run any number of instances of each project at the same time.
Files
Each application in the project group contains a single source file that contains the class for the main form of the application.
Classes
Each application defines a single class that implements the main form of the application.
Implementation
Server Application
- The application defines the following event handlers:
OpenButtonClick:- Changes the value of
OpenDialog1.Filterto the return value ofTMediaCodecManager.GetFilterString. - Displays
OpenDialog1. If you select a file:- Enables
PauseButtonandClearButton. - Changes the value of
MediaPlayer1.FileNametoOpenDialog1.FileName. - If
MediaPlayer1successfully loads the selected media file into itsMediaproperty:- Fills
Label1.Textwith "XxYpxZs", where: - Changes the value of
TrackBar1.MaxtoMediaPlayer1.Media.Duration. - Changes the value of
VolumeTrack.ValuetoMediaPlayer1.Media.Volume. - Starts playing the specified media file.
- Fills
- Enables
- Changes the value of
acPlayPauseExecute. If the State ofMediaPlayer1is Playing,acPlayPauseExecutechanges the Text of thePauseButtonto "Play" and stops the playback. If the media player is paused,acPlayPauseExecutechanges the text of thePauseButtonto "Pause" and resumes the playback.acClearExecuteclears the media player and disablesPauseButtonandClearButton.CheckBox1ChangechangesMediaPlayerControl1.Visible to the value ofCheckBox1.IsChecked.FMXAppProfileResourceReceivedchanges the value ofVolumeTrack.Valueto the value of the incoming remote resource.Timer1Timerchanges the value ofTrackBar1.ValuetoMediaPlayer1.CurrentTime.TrackBar1Changechanges the value ofMediaPlayer1.CurrentTimetoTrackBar1.Value.VolumeTrackChangechanges the value ofMediaPlayer1.Volumebased on the value ofVolumeTrack.Value.
- The application defines the following nonvisual components:
ActionList1defines the following actions:acPlayPause, which executesacPlayPauseExecute.acClear, which executesacClearExecute.
FMXManager.Passwordis "1234".FMXAppProfile:Actionscontains two local actions that are associated with the actions inActionList1and are shared with remote profiles.ManagerisFMXManager.Textis "FMXMediaPlayer".
MediaPlayer1.MediaPlayerControl1.OpenDialog1.Timer1executesTimer1Timereach 100 ms.
- The application defines the following controls:
OpenButtonexecutesOpenButtonClickwhen clicked.PauseButtonexecutesacPlayPausewhen clicked.ClearButtonexecutesacClearwhen clicked.CheckBox1(Visible) executesCheckBox1Changewhen toggled.VolumeTrackexecutesVolumeTrackChangewhen the user changes its value.Label1.TrackBar1executesTrackBar1Changewhen the user changes its value.
FireMonkey Client Application
- The application defines the following methods:
CheckMediaPlayersreturnsTrueif there is an item selected inlbPlayers. If there is no selected item,CheckMediaPlayersreturnsFalseand shows a message.
- The application defines the following event handlers:
- If
CheckMediaPlayersreturnsTrue,Button1Clickruns theacPlayPauseaction on the remote media player selected inlbPlayers. Button2ClickclearslbPlayersand callsCommandManager.DiscoverManagers.CommandManager.DiscoverManagerseventually triggersCommandManagerEndManagersDiscovery.CommandManagerEndManagersDiscoveryattempts to pair with any remote manager, and if successful triggersCommandManagerEndProfilesDiscovery.CommandManagerEndProfilesDiscovery:- Clears
lbPlayers. - If there is a discovered remote profile with "FMXMediaPlayer" as description, adds the profile to
lbPlayers. - If
lbPlayersis not empty, selects the first remote profile in the the list and connects to it.
- Clears
CommandManagerRequestManagerPasswordprovides the password of the remote server application: "1234".lbPlayersItemClickconnects to the remote profile selected inlbPlayers.VolumeTrackChangesendsVolumeTrack.Valueto the remote profile selected inlbPlayers.
- If
- The application defines the following nonvisual components:
CommandManager:OnEndManagersDiscoveryis handled byCommandManagerEndManagersDiscovery.OnEndProfilesDiscoveryis handled byCommandManagerEndProfilesDiscovery.OnRequestManagerPasswordis handled byCommandManagerRequestManagerPassword.
CommandApp:ManagerisCommandManager.
- The application defines the following controls:
VCL Client Application
- The application defines the following methods:
CheckMediaPlayersreturnsTrueif there is an item selected inlbPlayers. If there is no selected item,CheckMediaPlayersreturnsFalseand shows a message.
- The application defines the following event handlers:
- If
CheckMediaPlayersreturnsTrue,Button1Clickruns theacPlayPauseaction on the remote media player selected inlbPlayers. Button2ClickclearslbPlayersand callsCommandManager.DiscoverManagers.CommandManager.DiscoverManagerseventually triggersCommandManagerEndManagersDiscovery.CommandManagerEndManagersDiscoveryattempts to pair with any remote manager, and if successful triggersCommandManagerEndProfilesDiscovery.CommandManagerEndProfilesDiscovery:- Clears
lbPlayers. - If there is a discovered remote profile with "FMXMediaPlayer" as description, adds the profile to
lbPlayers. - If
lbPlayersis not empty, selects the first remote profile in the the list and connects to it.
- Clears
CommandManagerRequestManagerPasswordprovides the password of the remote server application: "1234".VolumeTrackChangesendsVolumeTrack.Valueto the remote profile selected inlbPlayers.
- If
- The application defines the following nonvisual components:
CommandManager:OnEndManagersDiscoveryis handled byCommandManagerEndManagersDiscovery.OnEndProfilesDiscoveryis handled byCommandManagerEndProfilesDiscovery.OnRequestManagerPasswordis handled byCommandManagerRequestManagerPassword.
VCLCommandApp:ManagerisCommandManager.
- The application defines the following controls:
lbPlayers.Button2(Find Players) executesButton2Clickwhen clicked.Button1(Play/Pause) executesButton1Clickwhen clicked.VolumeTrackexecutesVolumeTrackChangewhen the user changes its value.
Uses
- System.Tether.AppProfile.TTetheringAppProfile
- System.Tether.AppProfile.TTetheringAppProfile.Actions
- System.Tether.AppProfile.TTetheringAppProfile.Connect
- System.Tether.AppProfile.TTetheringAppProfile.Manager
- System.Tether.AppProfile.TTetheringAppProfile.RunRemoteAction
- System.Tether.AppProfile.TTetheringAppProfile.SendString
- System.Tether.AppProfile.TTetheringAppProfile.Text
- System.Tether.Manager.TTetheringManager
- System.Tether.Manager.TTetheringManager.DiscoverManagers
- System.Tether.Manager.TTetheringManager.OnEndManagersDiscovery
- System.Tether.Manager.TTetheringManager.OnEndProfilesDiscovery
- System.Tether.Manager.TTetheringManager.OnRequestManagerPassword
- System.Tether.Manager.TTetheringManager.PairManager
- System.Tether.Manager.TTetheringManager.Password
- FMX.Media.TMediaPlayer
- FMX.Media.TMediaPlayer.Clear
- FMX.Media.TMediaPlayer.CurrentTime
- FMX.Media.TMediaPlayer.Media
- FMX.Media.TMediaPlayer.Play
- FMX.Media.TMediaPlayer.State
- FMX.Media.TMediaPlayer.Stop
See Also
- System.Tether unit
- MediaPlayerHD sample
- BDShoppingList sample
- DesktopCast sample
- PhotoWall sample

