Programming C++Builder How to work with multimedia--add video or audio in your CBuilder or Delphi program?
Notice: Undefined variable: relatedArticlesCount in /home/wwwroot/codeback.net/plugins/content/tags.php on line 149

How to work with multimedia in C++Builder or Delphi?

C++Builder and Delphi allows you to add multimedia components to your Windows (not CLX or Linux) applications. To do this, you can use either the TAnimate component on the Win32 page or the TMediaPlayer component on the System page of the Component palette. Use the animate component when you want to add silent video clips to your application. Use the media player component when you want to add audio and/or video clips to an application.

The following topics are discussed in this section:

  1. Adding silent video clips to an application
  2. Adding audio and/or video clips to an application 

How to add silent video clips to an application?

The animation control in C++ Builder allows you to add silent video clips to your application.
To add a silent video clip to an application:

  1. Double-click the animate icon on the Win32 page of the Component palette. This automatically puts an animation control on the form window in which you want to display the video clip.
  2. Using the Object Inspector, select the Name property and enter a new name for your animation control. You will use this name when you call the animation control. (Follow the standard rules for naming C++ identifiers).
    Always work directly with the Object Inspector when setting design time properties and creating event handlers.
  3. Do one of the following:
    Select the Common AVI property and choose one of the AVIs available from the drop down list; or
    Select the FileName property and click the ellipsis (...) button, choose an AVI file from any available local or network directories and click Open in the Open AVI dialog; or
    Select the resource of an AVI using the ResName or ResID properties. Use ResHandle to indicate the module that contains the resource identified by ResName or ResID.
    This loads the AVI file into memory. If you want to display the first frame of the AVI clip on-screen until it is played using the Active property or the Play method, then set the Open property to true.
  4. Set the Repetitions property to the number of times you want to the AVI clip to play. If this value is 0, then the sequence is repeated until the Stop method is called. 
  5. Make any other changes to the animation control settings. For example, if you want to change the first frame displayed when animation control opens, then set the StartFrame property to the desired frame value.
  6. Set the Active property to true using the drop down list or write an event handler to run the AVI clip when a specific event takes place at runtime. For example, to activate the AVI clip when a button object is clicked, write the button's OnClick event specifying that. You may also call the Play method to specify when to play the AVI.

Note: If you make any changes to the form or any of the components on the form after setting Active to true, the Active property becomes false and you have to reset it to true. Do this either just before runtime or at runtime.

For more information on using the animation control, see the topic called Example of adding silent video clips.

How to add audio and/or video clips to an application? 

The media player component in C++ Builder allows you to add audio and/or video clips to your application. It opens a media device and plays, stops, pauses, records, etc., the audio and/or video clips used by the media device. The media device may be hardware or software.

NoteAudio and video clip support is not provided for cross-platform programming.

 To add an audio and/or video clip to an application:

  1. Double-click the media player icon on the System page of the Component palette. This automatically put a media player control on the form window in which you want the media feature.
  2. Using the Object Inspector, select the Name property and enter a new name for your media player control. You will use this when you call the media player control. (Follow the standard rules for naming C++ identifiers.)
    Always work directly with the Object Inspector when setting design time properties and creating event handlers.
  3. Select the DeviceType property and choose the appropriate device type to open using the AutoOpen property or the Open method. (If DeviceType is dtAutoSelect the device type is selected based on the file extension of the media file specified by the FileName property.) For more information on device types and their functions, see the table below.
  4. If the device stores its media in a file, specify the name of the media file using the FileName property. Select the FileName property, click the ellipsis (...) button, and choose a media file from any available local or network directories and click Open in the Open dialog. Otherwise, insert the hardware the media is stored in (disk, cassette, and so on) for the selected media device, at runtime.
  5. Set the AutoOpen property to true. This way the media player automatically opens the specified device when the form containing the media player control is created at runtime. If AutoOpen is false, the device must be opened with a call to the Open method.
  6. Set the AutoEnable property to true to automatically enable or disable the media player buttons as required at runtime; or, double-click the EnabledButtons property to set each button to true or false depending on which ones you want to enable or disable.
    The multimedia device is played, paused, stopped, and so on when the user clicks the corresponding button on the media player component. The device can also be controlled by the methods that correspond to the buttons (Play, Pause, Stop, Next, Previous, and so on).
  7. Position the media player control bar on the form by either clicking and dragging it to the appropriate place on the form or by selecting the Align property and choosing the appropriate align position from the drop down list.
    If you want the media player to be invisible at runtime, set the Visible property to false and control the device by calling the appropriate methods (Play, Pause, Stop, Next, Previous, Step, Back, Start Recording, Eject).
  8. Make any other changes to the media player control settings. For example, if the media requires a display window, set the Display property to the control that displays the media. If the device uses multiple tracks, set the Tracks property to the desired track.

Device Type Software/Hardware used Plays Uses Tracks Uses a Display Window
dtAVIVideo AVI Video Player for Windows  AVI Video files No Yes
dtCDAudio CD Audio Player for Windows or a CD Audio Player CD Audio Disks Yes No
dtDAT Digital Audio Tape Player  Digital Audio Tapes Yes No
dtDigitalVideo Digital Video Player for Windows AVI, MPG, MOV files No Yes
dtMMMovie MM Movie Player MM film No Yes
dtOverlay Overlay device Analog Video No Yes
dtScanner Image Scanner N/A for Play (scans images on Record)  No No
dtSequencer MIDI Sequencer for Windows MIDI files Yes No
dtVCR Video Cassette Recorder Video Cassettes No Yes
dtWaveAudio Wave Audio Player for Windows WAV files No No

For more information on using the media player control, see the topic called Example of adding audio and/or video clips.


Add comment


Security code
Refresh

Programming - C++Builder