FMX.Mobile.VideoPlayback Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates the use of the TMediaPlayer and the TMediaPlayerControl components.


You can find the VideoPlayback sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and navigate to:
    • Object Pascal\Mobile Snippets\VideoPlayback
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


The VideoPlayback sample uses the TMediaPlayer and the TMediaPlayerControl components to demonstrate how to playback an existing video clip on your iOS or Android device, including:

  • Selecting different videos.
  • Playing and stopping the video.
  • Moving the video forward, backward, to the beginning, and to the end.
  • Using a TRectangle as parent for the TMediaPlayerControl to hide and show the video as well as to move up and down the position of the video.

How to Use the Sample

  1. Navigate to the location given above and open:
    • Delphi: VideoPlayerTest.dproj.
  2. Select your target platform (iOS or Android supported).
  3. Press F9 or choose Run > Run.
  4. Select one of the files to play from the file list.
  5. Use the Play, Stop, To The Start, 10 Sec Backward, 10 Sec Forward, and To The End buttons to interact with the video.
  6. Use the Moving Parent Up, Moving Parent Down, and Change Parents Visible buttons to interact with the TRectangle that contains the TMediaPlayerControl.


File in Delphi Contains


The project itself.


The main form where the components are located.


Used to define and implement the sample.

MP4\Kayaking.mp4, MP4\Ocean.mp4

The video files to play in the sample.


The Video

The Rectangle Used as Parent

  • TRectangle is the rectangle that serves as parent for the TMediaPlayerControl component.
  • TRectangle.Position with TPosition type is used to get and update the X and Y positions of the rectangle.
  • The TRectangle.Visible property is used to hide and show the rectangle when the Change Parent Visible button is clicked.
  • Since the rectangle is the parent of the media player control, changing the position as well as hiding and showing the rectangle also moves, hides or shows the video.

Selecting the Video

The Timer

  • The TTimer is used to repeat the following actions after a given interval, that specifies the time interval between the TTimer.OnTimer events:
  • Setting the maximum value of the tbProcess track bar according to the Duration of the video file.
  • Updating the Value of the tbProcess track bar to match the CurrentTime of the video file.

On From Creation

When the form is created the sample:

  • Gets the appropriate paths to access the video files:
    The Platform property of TOSVersion is used to know the platform the sample is running on. Depending on the platform, a different path to the video is used.
  • Fills the TListBox with the available video files.
  • Sets the volume:
    The Value of the tbVolume track bar is adjusted to the TMediaPlayer.Volume.
    Later, when the tbVolume track bar changes, the Value of the track bar is used to set the TMediaPlayer.Volume.


See Also