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).

close

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.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Introduction to C++Language FeatureLearn C++

How To Use The Comprehensive Form Properties In C++ VCL Apps

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Add Characters to Wide Strings in Modern C++

C++ComponentsLanguage FeatureLearn C++

How To Create Gorgeous Transparent App Windows With C++

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Get A Substring of a Wide String in C++

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