C++C++11C++14C++17Language FeatureLearn C++

Learn To Develop Your Own Powerful Windows Media Player In C++ Builder

Media Players are good to play sounds or videos. You can easily create your own media player in C++ Builder. MediaPlayer (TMediaPlayer) component is very good to develop your media player application. You can use a TMediaPlayer component for easy access to media files.

MediaPlayer (TMediaPlayer) is used with TMediaPlayerControl. Set MediaPlayer to link a TMediaPlayer to this TMediaPlayerControl, so the video file attached to the media player is displayed on a form. The currently accessed media file is specified through the Media property. To specify the media file to be played by the current TMediaPlayer, set the FileName property. The file name must include the path of the file, so it can be localized on the memory, and the extension. Call the Play and Stop methods to start playing a media file, or to stop or pause a running media file.

Let’s create a new media player in C++ Builder.

  1. Create a new Multi-Device C++ Builder Project. Save all project files and unit in to a folder.
  2. Add a Layout, set it’s Align property to the Top. add four Buttons in to this Layout and change their Text properties to “Open“, “Play“, “Pause“, “Stop
  3. Drag MediaPlayer from Tools Palette on to Form. This will allow you to play videos on your MediaPlayerControl.
  4. Drag MediaPlayerControl from Tools Palette. This is a frame that will show your videos. Set it’s Allign property to Client.
  5. Drag OpenDialog from Tools Palette, this dialog will be used open media files.

6. Double Click to Open button, this will create OnClick() event for this button and add this line

this will delete previous filename if it has and it will execute OpenDialog, so user will able to browse his media file from its directory. If user choice a file, FileName property will have its path and file name together.

7. Now go back to Form design by clicking F12. Double click to Play button, this will create OnClick() event for this button, and add these lines as below.

8. Go back to Form design, double click to Pause button, this will create OnClick() event for this button, and add these lines to Pause as below

9. Again go back to Form design and double click to Stop button, this will create OnClick() event for this button, and add these lines to Stop as below

10. Go to Unit1.h and add this Media header under include lines as below if it is not added.

11. All is done. As you see in C++ Builder, it is very easy to create your own Media Player. Now you can run your application by pressing F9.

You can use styled icons on your buttons or you can add icons or images on your buttons. You can use some effects on display and hide your layout which has buttons inside when mouse is used or not. You can create your own music player or video player with glamorous images or textures.

In MediaPlayer (TMediaPlayer), the current position is specified through the CurrentTime property.  MediaPlayer also exposes media file properties such as Duration, VideoSize, Volume or State. You can also use more audio and video codecs by using  MediaCodecManager (TMediaCodecManager).


Oh hi there ๐Ÿ‘‹
Itโ€™s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We donโ€™t spam! Read our privacy policy for more info.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++17C++20Introduction to C++Learn C++

When Is The CMath Mathematical Special Functions Header Used in Modern C++?

C++C++17C++20Introduction to C++Learn C++

What Are The CMath Mathematical Special Functions in Modern C++?

C++C++17C++20Learn C++

What Are The New Rules For Auto Deduction In C++ 17?

C++C++14C++17Learn C++Syntax

What Are The New Overloads For Ranges In C++ 14?

Worth reading...
Introduction To C++ Windows Development With C++Builder