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 Sydney | Samples and then navigate to either of the following folders:
- CPP\RTL\Tethering\MediaPlayer
- Object Pascal\RTL\Tethering\MediaPlayer
- 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
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 (
n
xn
px) and the duration (n
s) 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 Projects Window:
- 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.Filter
to the return value ofTMediaCodecManager.GetFilterString
. - Displays
OpenDialog1
. If you select a file:- Enables
PauseButton
andClearButton
. - Changes the value of
MediaPlayer1.FileName
toOpenDialog1.FileName
. - If
MediaPlayer1
successfully loads the selected media file into itsMedia
property:- Fills
Label1.Text
with "X
xY
pxZ
s", where: - Changes the value of
TrackBar1.Max
toMediaPlayer1.Media.Duration
. - Changes the value of
VolumeTrack.Value
toMediaPlayer1.Media.Volume
. - Starts playing the specified media file.
- Fills
- Enables
- Changes the value of
acPlayPauseExecute
. If the State ofMediaPlayer1
is Playing,acPlayPauseExecute
changes the Text of thePauseButton
to "Play" and stops the playback. If the media player is paused,acPlayPauseExecute
changes the text of thePauseButton
to "Pause" and resumes the playback.acClearExecute
clears the media player and disablesPauseButton
andClearButton
.CheckBox1Change
changesMediaPlayerControl1
.Visible to the value ofCheckBox1
.IsChecked.FMXAppProfileResourceReceived
changes the value ofVolumeTrack.Value
to the value of the incoming remote resource.Timer1Timer
changes the value ofTrackBar1.Value
toMediaPlayer1.CurrentTime
.TrackBar1Change
changes the value ofMediaPlayer1.CurrentTime
toTrackBar1.Value
.VolumeTrackChange
changes the value ofMediaPlayer1.Volume
based on the value ofVolumeTrack.Value
.
- The application defines the following nonvisual components:
ActionList1
defines the following actions:acPlayPause
, which executesacPlayPauseExecute
.acClear
, which executesacClearExecute
.
FMXManager.Password
is "1234".FMXAppProfile
:Actions
contains two local actions that are associated with the actions inActionList1
and are shared with remote profiles.Manager
isFMXManager
.Text
is "FMXMediaPlayer".
MediaPlayer1
.MediaPlayerControl1
.OpenDialog1
.Timer1
executesTimer1Timer
each 100 ms.
- The application defines the following controls:
OpenButton
executesOpenButtonClick
when clicked.PauseButton
executesacPlayPause
when clicked.ClearButton
executesacClear
when clicked.CheckBox1
(Visible) executesCheckBox1Change
when toggled.VolumeTrack
executesVolumeTrackChange
when the user changes its value.Label1
.TrackBar1
executesTrackBar1Change
when the user changes its value.
FireMonkey Client Application
- The application defines the following methods:
CheckMediaPlayers
returnsTrue
if there is an item selected inlbPlayers
. If there is no selected item,CheckMediaPlayers
returnsFalse
and shows a message.
- The application defines the following event handlers:
- If
CheckMediaPlayers
returnsTrue
,Button1Click
runs theacPlayPause
action on the remote media player selected inlbPlayers
. Button2Click
clearslbPlayers
and callsCommandManager.DiscoverManagers
.CommandManager.DiscoverManagers
eventually triggersCommandManagerEndManagersDiscovery
.CommandManagerEndManagersDiscovery
attempts 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
lbPlayers
is not empty, selects the first remote profile in the the list and connects to it.
- Clears
CommandManagerRequestManagerPassword
provides the password of the remote server application: "1234".lbPlayersItemClick
connects to the remote profile selected inlbPlayers
.VolumeTrackChange
sendsVolumeTrack.Value
to the remote profile selected inlbPlayers
.
- If
- The application defines the following nonvisual components:
CommandManager
:OnEndManagersDiscovery
is handled byCommandManagerEndManagersDiscovery
.OnEndProfilesDiscovery
is handled byCommandManagerEndProfilesDiscovery
.OnRequestManagerPassword
is handled byCommandManagerRequestManagerPassword
.
CommandApp
:Manager
isCommandManager
.
- The application defines the following controls:
VCL Client Application
- The application defines the following methods:
CheckMediaPlayers
returnsTrue
if there is an item selected inlbPlayers
. If there is no selected item,CheckMediaPlayers
returnsFalse
and shows a message.
- The application defines the following event handlers:
- If
CheckMediaPlayers
returnsTrue
,Button1Click
runs theacPlayPause
action on the remote media player selected inlbPlayers
. Button2Click
clearslbPlayers
and callsCommandManager.DiscoverManagers
.CommandManager.DiscoverManagers
eventually triggersCommandManagerEndManagersDiscovery
.CommandManagerEndManagersDiscovery
attempts 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
lbPlayers
is not empty, selects the first remote profile in the the list and connects to it.
- Clears
CommandManagerRequestManagerPassword
provides the password of the remote server application: "1234".VolumeTrackChange
sendsVolumeTrack.Value
to the remote profile selected inlbPlayers
.
- If
- The application defines the following nonvisual components:
CommandManager
:OnEndManagersDiscovery
is handled byCommandManagerEndManagersDiscovery
.OnEndProfilesDiscovery
is handled byCommandManagerEndProfilesDiscovery
.OnRequestManagerPassword
is handled byCommandManagerRequestManagerPassword
.
VCLCommandApp
:Manager
isCommandManager
.
- The application defines the following controls:
lbPlayers
.Button2
(Find Players) executesButton2Click
when clicked.Button1
(Play/Pause) executesButton1Click
when clicked.VolumeTrack
executesVolumeTrackChange
when 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
- VideoPlayback sample
- BDShoppingList sample
- DesktopCast sample
- PhotoWall sample